我有下一个html结构:
<div class="offerButtons">
<button type="reset" class="btnReset"><span> No </span></button>
<input type="text" class="offerInput" />
<button type="submit" class="btnSubmit"><span> Yes </span></button>
</div>
Run Code Online (Sandbox Code Playgroud)
而我的CSS如下:
.offerButtons {
display: table;
width: 100%;
background-color: yellow;
}
.btnReset, .btnSubmit {
border: 1px solid red;
border-radius: 50%;
width: 30px;
height: 30px;
display: table-cell;
text-align: center;
vertical-align: middle;
}
.btnReset span, .btnSubmit span{
color: red;
}
.offerInput {
height: 31px;
margin: 0 5px;
display: table-cell;
}
Run Code Online (Sandbox Code Playgroud)
btnReset和btnSubmit具有固定的宽度。我想要的是那两个按钮的宽度固定,而inout字段占据其余宽度。
我想得到类似的东西:
但是现在,有了这段代码,我得到了:
任何的想法?
这是jsfiddle
您也可以使用css3 flexbox。跟随css将使其如您所愿:
.offerButtons {
align-items: center;
display: flex;
width: 500px;
}
.offerInput {
flex-grow: 1;
}
Run Code Online (Sandbox Code Playgroud)
.offerButtons {
align-items: center;
display: flex;
width: 500px;
}
.offerInput {
flex-grow: 1;
}
Run Code Online (Sandbox Code Playgroud)
.offerButtons {
align-items: center;
display: flex;
width: 500px;
background-color: yellow;
}
.btnReset, .btnSubmit {
border: 1px solid red;
border-radius: 50%;
width: 30px;
height: 30px;
text-align: center;
}
.btnReset span, .btnSubmit span{
color: red;
}
.offerInput {
height: 31px;
text-indent: 15;
margin: 0 5px;
flex-grow: 1;
}Run Code Online (Sandbox Code Playgroud)
但是,如果您对此不满意flexbox,则可以在几乎大多数浏览器中使用另一种方法。
<div class="offerButtons">
<button type="reset" class="btnReset"><span> No </span></button>
<input type="text" class="offerInput" />
<button type="submit" class="btnSubmit"><span> Yes </span></button>
</div>Run Code Online (Sandbox Code Playgroud)
.offerButtons {
background-color: yellow;
position: relative;
padding: 0 40px;
}
.btnReset, .btnSubmit {
transform: translateY(-50%);
position: absolute;
border: 1px solid red;
border-radius: 50%;
width: 30px;
height: 30px;
left: 3px;
top: 50%;
}
.btnSubmit {
left: auto;
right: 3px;
}
.btnReset span, .btnSubmit span{
color: red;
}
.offerInput {
height: 31px;
display: block;
width: 100%;
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
333 次 |
| 最近记录: |