我无法在搜索表单中将输入宽度设置为 100%。 我不确定我做错了什么。尝试在所有可能的地方设置 100%,但只有当我设置大小 px 时才会发生变化。
.searchInput {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 5px;
display: table-cell;
height: 29px;
padding: 0 4px;
vertical-align: middle;
width: 100%;
}
.searchIn {
-moz-appearance: none;
-moz-box-sizing: border-box;
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
border: 0 none;
font-size: 15px;
margin: 0;
outline-width: 0;
padding-left: 4px;
width: 97%;
}
<form method="post">
<div class="searchEn">
<input type=hidden name="do" value=search>
<input type="hidden" name="subaction" value="search" />
<div class="searchInput">
<input class="searchIn" name="story" width="100%" type="text" />
</div>
</div>
</form>
最佳答案
我认为您可以通过将 .searchInput
的 display
规则更改为 block
(然后是 宽度
到 98%
) 像这样 ( demo )
.searchInput {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 5px;
display: block;
height: 29px;
padding: 0 4px;
vertical-align: middle;
width: 98%;
}
或者为了更完整的修复(解决一堆填充和宽度问题),您可以使用此 CSS ( demo )(更改已注释)
.searchEn {
background-image: linear-gradient(to bottom, #FFFFFF 0px, #DFDFDF 100%);
border-radius: 5px;
color: #000000;
/*Push the right side over slightly more*/
padding: 4px 6px 4px 4px;
}
.searchInput {
background: none repeat scroll 0 0 #FFFFFF;
border: 1px solid #CCCCCC;
border-radius: 5px;
display: block;
height: 29px;
/*Remove padding from this element (now in the parent element)*/
padding: 0;
vertical-align: middle;
/*These can be full width if you fix the padding on the parent element*/
width: 100%;
}
.searchIn {
-moz-appearance: none;
-moz-box-sizing: border-box;
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
border: 0 none;
font-size: 15px;
margin: 0;
outline-width: 0;
padding-left: 4px;
/*Center the input box better inside the container*/
padding-top: 6px;
/*And make the input full width*/
width: 100%;
}
关于html - 论坛输入 100% 宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20182813/