我的搜索框的布局如下:
<div id="emulating_variable_width">
<form id="srxForm" method="post">
<div id="qsrxSearchbar">
<div id="scope"> Person Name </div>
<input type="text" id="theq" title="Search">
<button id="btnSearch" type="button">Search</button>
</div>
</form>
</div>
(为了显示目的,它非常简化)
我想要的是让输入文本元素填充所有可用空间(即黄色空间),同时保持搜索按钮在右侧。
Full example with the CSS is in a fiddle
在IE7 +,FF,Safari等中完成解决方案的最简单方法是什么??
谢谢!
答案 0 :(得分:32)
喜欢这个吗?
DEMO:http://jsfiddle.net/v7YTT/19/
HTML:
<div id="emulating_variable_width">
<form id="srxForm" method="post">
<div id="qsrxSearchbar">
<button id="btnSearch">Search</button>
<label id="scope"> Person Name </label>
<span><input type="text" id="theq" title="Search" /></span>
</div>
</form>
</div>
CSS:
#qsrxSearchbar
{
width: 500px;
height: 100px;
overflow: hidden;
background-color: yellow;
}
#qsrxSearchbar input
{
width: 100%
}
#qsrxSearchbar label
{
float: left
}
#qsrxSearchbar span
{
display: block;
overflow: hidden;
padding: 0 5px
}
#qsrxSearchbar button
{
float: right
}
#qsrxSearchbar input, .formLine button
{
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box
}
答案 1 :(得分:1)
嘿,您可以在输入字段中使用焦点属性,就像这样
<强>的CSS 强>
#emulating_variable_width{
width:500px;
height:100px;
background-color:yellow;
}
input {
width:auto;
/*width:100%;*/
float:left;
width:100px;
font-size: 17px;
}
#scope{float:left;}
button{float:left;}
input:focus{
width:200px;
}
<强> HTML 强>
<div id="emulating_variable_width">
<form id="srxForm" method="post">
<div id="qsrxSearchbar">
<div id="scope"> Person Name </div>
<input type="text" id="theq" title="Search">
<button id="btnSearch" type="button">Search</button>
</div>
</form>
</div>
答案 2 :(得分:1)
你需要这样的东西:
#emulating_variable_width{
width:500px;
height:100px;
background-color:yellow;
}
input {
width:320px;
/*width:100%;*/
float:left;
font-size: 17px;
}
#scope{float:left;}
button{float:left;}