这是棘手的 css 事情之一
我在导航栏中有 4 个元素,我想将其中的 3 个元素合并到一个漂亮的搜索框中。这个想法是让所有的搜索框具有相同的高度、对齐方式并且并排排列。另一方面,链接必须适当定位。
我已经尝试了所有方法,我可以让它适用于一个导航器,但不能适用于其中的两个,这不行。
这是 html 示例:
<a href="#" id="btn-category">Comprar por Categoría ▼</a>
<select>
<option>a</option>
<option>b</option>
</select>
<input type="text">
<input type="submit">
和基础 CSS:
#btn-category{
font-size: 8pt;
display: inline-block;
width: 80px;
}
input, select{
border: 1px solid #ccc;
padding: 5px;
font-size: 10pt;
height: 30px;
}
select{
font-size: 8pt;
}
这是 fiddle http://jsfiddle.net/Q7Ge4/1/
只是说清楚,它是关于搜索框元素的高度...有点像 ebay 搜索框
最佳答案
这是一个 Fiddle
#btn-category {
float: left;
clear: left;
font-size: 11px;
width: 70px;
height: 30px;
}
input:focus,
select:focus {
outline: none;
border: 1px solid #12b6f3;
box-shadow: 0 0 2px 0 #12b6f3;
}
select,
input {
float: left;
clear: none;
padding: 5px;
margin-right: 8px;
font-size: 12px;
border: 1px solid #ccc;
border-radius: 3px;
}
select {
height: 30px;
font-size: 8pt;
}
input[type="text"] {
height: 18px;
width: 150px;
transition: width 0.4s linear;
}
input[type="text"]:focus {
width: 200px;
}
input[type="submit"] {
width: 70px;
height: 30px;
}
关于html - 如何对齐 4 个不同的表单元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18746368/