html - 对齐选择和输入

标签 html css alignment label fieldset

是否可以不指定宽度大小、不使用表格并使用相同的 HTML 对齐 SELECT 和 INPUT 内联?见图片。 现场示例:http://jsfiddle.net/N4hpQ/ 谢谢。

<html>
<head>
<style>

fieldset {
display: inline-block;
}

fieldset input,
fieldset select{
float: right;
margin-left: 5px;   
}

fieldset p {
text-align: right;
}

</style>
</head>
<body>

<fieldset>          
<p><label>First Name: </label><input type="text" /></p>
<p><label>Second Name: </label><input type="text" /></p>
<p><label>Country: </label><select><option>Choose</option></select></p>
<p><label>Age: </label><select><option>Choose</option></select></p>
</fieldset> 

</body>
</html>

image

最佳答案

您可以使用 css display: table; 来实现这一点。

HTML

<fieldset>
    <p>
        <label>First Name: </label>
        <input type="text" />
    </p>
    <p>
        <label>Second Name: </label>
        <input type="text" />
    </p>
    <p>
        <label>Country: </label>
        <select>
            <option>Choose</option>
        </select>
    </p>
    <p>
        <label>Age: </label>
        <select>
            <option>Choose</option>
        </select>
    </p>
</fieldset>
​

CSS

fieldset {
    display: table;
}
fieldset p {
    display: table-row;
}
fieldset input, 
fieldset select, 
fieldset label {
    display: table-cell;
    margin: 3px;
}
fieldset label {
    text-align: right;
}

Demo

关于html - 对齐选择和输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13750890/

相关文章:

javascript - VelocityJS 中的过渡效果动画

html - 延迟 CSS 转换

c - __attribute__ ((__aligned__)) 不适用于静态变量

facebook - 右对齐 Facebook 点赞按钮

HTML 表单 : file input from a url

java - 只使用一个 servlet

css - 图片和 HTML5 视频不会有相同的高度

html - CSS:如何围绕居中元素对齐元素?

javascript - Vis-Network.js 抑制边框显示

Javascript:无法在 HTML 输入中移回