【发布时间】:2016-10-23 23:27:12
【问题描述】:
我这里有小提琴:https://jsfiddle.net/ufLpqdtj/
我的问题是试图让我的搜索框和按钮始终全宽显示在页面上,而不管它在什么设备上运行。
在 Javascript 中,我总是可以将文本框的宽度设为 100% 减去按钮的像素宽度(按钮的大小始终相同),但我觉得我好像遗漏了一些东西,而且它可以在 CSS 中本地完成。
有什么想法或建议吗?
#commonSearchContainer {
display: block;
clear: both;
width: 100%;
position: relative;
}
#commonSearchTerm {
width: 100%;
margin: 25px 0px 0px 0px;
padding: 5px;
border: 1px solid #999999;
height: 35px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.common-search-term-wrapper {
width: 90%;
display: inline-block;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.common-search-button {
background-color: #E9700D;
border: 1px solid #ccc;
display: inline-block;
margin: 25px 0px 0px 10px;
width: 80px;
color: #fff;
padding: 7px;
font-style: italic;
cursor: pointer;
}
<div id="searchSection" class="common-search-section">
<div class="common-search-term-wrapper">
<input id="commonSearchTerm" type="text" autocomplete="off" class="common-search-term">
</div>
<div id="commonSearchSubmit" class="common-search-button">
Search
<div style="clear: both;"></div>
</div>
</div>
【问题讨论】: