我有一个有两件物品的容器.其中一个项是select
元素,所以我需要size
通过HTML 设置属性.我希望容器中的其他项目伸展其高度以适合容器.我无法弄清楚.我不想明确设置容器的高度,因为我不知道该选择框的大小.
.container {
padding: 5px;
border: 1px solid black;
}
.container .column {
display: inline-block;
width: 40%;
background-color: #AAA;
padding: 5px;
margin: 5px;
vertical-align: top;
height: 100%;
}
select {
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="column">Stretch to fill?</div>
<div class="column">
<select size="15">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div>
Run Code Online (Sandbox Code Playgroud)
Ant*_*ony 61
如果table-cell
是一个选项,这是一种方法:
.container {
display: table;
width: 100%;
padding: 5px;
border: 1px solid black;
}
.container .column {
display: table-cell;
width: 40%;
background-color: #AAA;
padding: 5px;
border: 5px solid white;
vertical-align: top;
height: 100%;
}
select {
width: 100%;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="column">Stretch to fill?</div>
<div class="column">
<select size="15">
<option>Option 1</option>
<option>Option 2</option>
</select>
</div>
<div>
Run Code Online (Sandbox Code Playgroud)
小智 5
这里没有答案给我安慰,所以我去寻找真相。我添加了更多的CSS以使两个框之间的间距更清晰。
CSS:
.wrapper {
background-color:gray;
}
.container {
margin: 25px auto;
display: inline-flex;
}
.leftbox {
height: inherit;
display: inline-block;
border: 1px solid #D7D2CB;
background-color: #FFFFFF;
border-radius: 5px;
max-width: 550px;
margin-right: 18px;
align-items: stretch;
padding: 15px;
width: 100%;
}
.rightbox {
height: 100%;
display: inline-block;
border: 1px solid #D7D2CB;
background-color: #FFFFFF;
border-radius: 5px;
align-items: stretch;
max-width: 300px;
width: 100%;
padding: 20px 15px;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="wrapper">
<div class="container">
<div class="leftbox">
There is something here, I am not avoiding it.
</div>
<div class="rightbox">
Probably something else here but much much much much much much much much much much much much much much much much much much much much much much much much much much much much much bigger.
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
检查代码笔:https ://codepen.io/anon/pen/XRNMMp