html - 如何对齐 4 个不同的表单元素

标签 html css

这是棘手的 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/

相关文章:

javascript - 有没有一种方法可以在没有 "styled"的情况下以情感为主题

javascript - 我想使用 Jquery 向我的 html 元素添加更多 css 属性,这意味着我不想删除前一个属性,只需添加更多属性即可

jquery - 响应式网站可以在桌面上运行,但在移动设备上无法加载正确的样式

javascript - 将 svg 形状彼此居中

html - 如何将 HTML <FORM> 显示为内联元素?

html - 子菜单滚动弹出不显示

html - 当 ul 只有一个 li 标签时隐藏 ul 和 li 标签

jquery - xsl css jquery - 隐藏的 div 仍然显示空间

css - 如何让我的文本包裹在我的 dijit.form.select 中

html - 为什么 max-width 上的媒体查询不起作用?