[英]Can not wrap my middle 100% width div with 2 divs with a fixed width
My pen: http://codepen.io/helloworld/pen/AHdLm 我的笔: http : //codepen.io/helloworld/pen/AHdLm
I have 3 divs: 我有3个div:
A left and right div with a fixed width of 40px; 左右div,固定宽度为40px; (red colored) Between is a middle div with a fluid width of 100%;
(红色)介于中间的是div,流体宽度为100%;
Of course 40px + 100% + 40px will always wrap the divs just like it is now. 当然40px + 100%+ 40px总是会像现在一样包装div。
I can not use position:fixed for a solution and I need it for IE8+. 我不能将position:fixed用于解决方案,而IE8 +则需要它。
How can I achieve that? 我该如何实现?
HTML HTML
<div id="wrapper">
<div style="float:left;width:40px;height:80px;background:red;">Left</div>
<div style="float:left;" class="table">
<div id="navBar" >
<div class="cellContainer">
<div class="template">11</div>
</div>
<div class="cellContainer">
<div class="template">22</div>
</div>
<div class="cellContainer">
<div class="template">33</div>
</div>
<div class="cellContainer">
<div class="template">44</div>
</div>
</div>
</div>
<div style="float:left;width:40px;height:80px;background:red;">Right</div>
<div style="clear:both" />
</div>
CSS CSS
.cellContainer {
width: 20%;
float: none;
display: inline-block;
}
.table {
display: table;
width: 100%;
margin: 0 auto;
background-color: orange;
}
.template{
height: 80px;
margin: 10px;
background: lightgray;
border: black solid 1px;
padding-left: 5px;
font-size: 14px;
text-align: left;
cursor: pointer;
}
#navBar {
border: black solid 1px;
text-align: center;
}
Use this css for .table 将此CSS用于.table
.table {
position: absolute;
left: 40px;
right: 40px;
margin: 0 auto;
background-color: orange;
}
and use float: right;
并使用
float: right;
for the right div. 正确的div
http://codepen.io/anon/pen/bspdn http://codepen.io/anon/pen/bspdn
try this: 尝试这个:
<div id="wrapper">
<div style="float:left;width:40px;height:80px;background:red;margin-left:-40px;">Left</div>
<div style="float:left; width:100%;background:blue;" class="table">
<div id="navBar" >
<div class="cellContainer">
<div class="template">11</div>
</div>
<div class="cellContainer">
<div class="template">22</div>
</div>
<div class="cellContainer">
<div class="template">33</div>
</div>
<div class="cellContainer">
<div class="template">44</div>
</div>
</div>
</div>
<div style="float:right;width:40px;height:80px;background:red; margin-right:-40px;">Right</div>
<div style="clear:both"></div>
</div>
css: CSS:
#wrapper {padding:0 40px;}
however the above will not keep your columns the same height. 但是以上内容不会使您的列保持相同的高度。 If you want to do this you can go the
display:table
route (but this isn't compatible with earlier versions of ie): 如果要执行此操作,则可以执行
display:table
路由(但这与ie的早期版本不兼容):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.