展示我想要的东西的最好方法是展示它:

我希望左边和右边的div自动展开到容器div的左和右边缘。
这可以用Javascript和flex来完成,但我想知道是否还有另外一种方法支持IE9+ (flex is IE11+)
我创建了这个现场演示 (单击"Run“),它有一个动态变化的中心div (因为”真实生活“问题没有静态大小)
发布于 2014-05-26 13:48:31
使用display: table-cell将使您更容易。
演示: http://jsfiddle.net/abhitalks/VytTX/1/
HTML
<div class="outer">
<div id="left" class="inner"></div>
<div id="center" class="inner">...</div>
<div id="right" class="inner"></div>
</div>CSS
body { width: 100%; }
div.outer {
width: 90%;
border: 1px solid gray;
background-color: rgb(12, 34, 43);
text-align: center;
display: table;
border-spacing: 10px;
}
div.inner {
border: 1px solid gray;
height: 200px;
display: table-cell;
min-width: 20px; width: 20px;
padding: 4px;
background-color: rgb(212, 234, 143);
}发布于 2014-05-26 13:33:03
你可以这样做:
一个例子:http://codepen.io/srekoble/pen/rugxh (更改中心宽度$width的变量)
它是一个用于变量使用的sass文件:
* {
box-sizing: border-box;
-webkit-box-sizing: border-box;
}
div.outer {
width: 100%;
border: 1px solid gray;
background-color: rgb(12,34,43);
text-align: center;
margin: 0 auto;
font-size: 0;
}
div.inner {
border: 1px solid gray;
height: 200px;
display:inline-block;
min-width: 20px;
}
$width: 50%;
#center {
width: $width;
background: red;
}
#left,
#right {
width: ( 100% - $width ) / 2;
background: yellow;
}发布于 2014-05-26 13:43:11
<style>
body
{
background: #0B222A;
}
.outer
{
width: 400px;
height: 300px;
background: #D3EA8F;
margin: auto;
}
.inner
{
width: 60%;
height: 300px;
background: #D3EA8F;
border-left: solid 10px #0B222A;
border-right: solid 10px #0B222A;
margin: auto;
}
</style>
<div class="outer">
<div class="inner"></div>
</div>https://stackoverflow.com/questions/23871073
复制相似问题