javascript - 水平对齐选择标签

标签 javascript jquery html css

<div style="width:100%;" id="comboDiv">   
    <div style="width: 100px;">
        <select style="width: 100%;"/>
    </div>
    <div style="width: 200px;">
        <select style="width: 100%;" />
    </div>
    <input type="text" style="width: 10%; float:right;" />
</div>

我需要将这 3 个元素排成一行,但我只得到一个选择标签和输入框。我已经尝试将 float 样式应用于 div 和其他各种 css 样式,但我无法连续获得 2 个选择标签以及右对齐的文本框。

最佳答案

您还没有关闭您的 <select></select>并使用 float:left水平对齐两个 div。

<div style="width:100%;" id="comboDiv">   
   <div style="width: 100px; float:left;">
       <select style="width: 100%;" >
         <option value="1">1</option>
         <option value="2">2</option>
       </select>
   </div>
   <div style="width: 200px; float:left;">
       <select style="width: 100%;" >
         <option value="1">1</option>
         <option value="2">2</option>
       </select>
   </div>

   <input type="text" style="width: 10%; float:right;" />
</div>

更新

或者您可以使用 display:inline并删除不必要的 div像这样:

<div style="width:100%;" id="comboDiv"> 
   <select style="width: 100px; display:inline;" >
      <option value="1">1</option>
      <option value="2">2</option>
   </select>
  
   <select style="width: 200px; display:inline;" >
      <option value="1">1</option>
      <option value="2">2</option>
   </select>

   <input type="text" style="width: 10%; float:right;" />
</div>

关于javascript - 水平对齐选择标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39369531/

相关文章:

javascript - 如何在 ASP .NET MVC 中使用 javascript 或 jquery 移动 html 元素中的类属性?

javascript - 从 php 创建的下拉列表列表中单独填充 textarea

html - 调整页面大小时停止元素移动 CSS

javascript - CSS 无法识别 ID 或名称

html - x-handlebars 模板中的 Twitter Bootstrap 工具提示

javascript - 如何访问 Web 组件上的 observedAttributes

javascript - 滚动上的动画技能栏

Jquery Flot - 为单个数据系列设置可悬停

javascript - getScript 函数工作但没有得到一些 css

jquery - 重用 jQuery 选择器而不是构造它两次?