html - 我想设计我的表格,如图所示

标签 html css html-table

Link to Image

我希望我的表格看起来像图像中使用 CSS 的表格。有没有办法做到这一点,因为我尽我所能尝试但没有奏效。非常感谢您的帮助。

这是我的 HTML 代码

<div id="login_fields"> 
    <form id="login_form">
        <table>
          <tr>
            <td>User</td>
            <td><input type="text" name="user" id="user" /></td>
          </tr>
          <tr>
            <td>Password</td>
            <td><input type="password" name="password" id="password" /></td>
          </tr>
        </table>
    </form>
</div>

最佳答案

我可以建议修改您的 HTML(表格 完全没有必要),如下所示:

<form action="#" method="post">
    <!-- using a label means that clicking the text automatically focuses
         the relevant input, the value of the 'for' attribute must match the 'id'
         of the relevant input though -->
    <label for="uName">User</label>
    <input id="uName" />
    <label for="pass">Password</label>
    <input type="password" id="pass" />
</form>

使用以下 CSS(根据喜好修改颜色和尺寸):

form {
    /* aesthetics, just to move the label/input pairs from the edge of the screen */
    padding: 1em;
}

label,
input {
    float: left; /* to allow for width to be given, and for clearing */
    border: 1px solid #999; /* amend the following as required */
    line-height: 1.2em;
    padding: 0.2em 0;
    font-size: 1em;
    height: 1.4em;
    margin-bottom: 0.8em;
}

input + label {
    clear: left; /* this styles a label element that immediately
                    follows an input, and forces a new-line */
}

label {
    text-indent: 0.5em; /* moves the text away from the curved corners */
    width: 30%;
    border-radius: 0.5em 0 0 0.5em; /* handles the curved corners */
}

input {
    width: 60%;
    border-radius: 0 0.5em 0.5em 0;
    outline: none;
}

input:focus,
input:active {
    box-shadow: inset 0 0 5px #55f; /* compensates for the fact I removed the
                                       default outline, and gives visual
                                       feedback to show the input is focused/active */
}

JS Fiddle demo .

关于html - 我想设计我的表格,如图所示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14484198/

相关文章:

javascript - jQuery:如何将 css() 与 delay() 链接起来

html/css 框模型结构,居中和东西

html - 如何使用 ui-sref-active ="active"设置悬停状态等于 li clearfix 元素的事件状态

javascript - Bootstrap 日历不显示

javascript - 如何将 CSS 类的索引与 JavaScript 匹配?

css - 表格单元格高度显示不同 IE8 vs IE7 vs Firefox

html - IE 绝对定位 <div> inside <td> relative to <tr> with position : relative

html - 我想使用 html 在表格的每一行旁边添加一个复选框

java - 如何使用 apache pdfbox 在 pdf 中打印 html 文本

html - CSS:绘制倾斜的边框