选择和输入彼此相邻

时间:2020-10-28 22:05:40

标签: css

我正在尝试将选择标签和输入标签彼此相邻放置,类似于亚马逊如何配置其搜索栏。

我的问题是我希望按浏览器的宽度缩放搜索栏,即使窗口很小也不会折叠到下一行。

如何实现?以下是我的尝试...

**HTML**

<div class="container">
  <select>
    <option>One</option>
    <option>Two</option>
  </select>
  <input type="text" placeholder="Enter something...">
</div>

**CSS**

.container {
  width: 100%;
}

select {
  width: 4%;
}

input {
  padding-left: 0;
  width: 95%;
}

1 个答案:

答案 0 :(得分:1)

如果我说对了,那应该可以。

.container {
  width: 100%;
  display:flex;
}


input {
  width:100%;
  box-sizing:border-box;
}

enter image description here