这是我的模型:
我想像图片中那样设置div。DIV 1 和 DIV 2 包含动态生成的内容,并且宽度每次都不同。
Div 1 浮动到左侧, Div 2 浮动到右侧。
我的问题是:如何定位 div 3 以使其适合 div 1 和 3 之间?
我的代码是:HTML
<div class="dia">
<div class="left">sassssss</div>
<div class="center">dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd</div>
<div class="right">asdasdfgdsgdf</div>
</div>
CSS
.dia {
background: #282828;
padding: 10px;
height: 106px;
border-radius: 5px;
}
.dia .center {
margin-left: 20px;
}
.dia .left, .dia .right {
overflow: hidden;
}
.dia .left {
float: left;
margin-right: 10px;
}
.dia .right {
float: right;
margin-left: 10px;
background: rgb(214,214,214);
}
我想适应现在太宽的中心 div 并且向右移动 div 比我想要的低。
解决方案:
HTML
<div class="dia">
<div class="left">sassssss</div>
<div class="center">ddddddddddddddddddddd dddddddddddddddddddddddddd ddddddddddddddddddddddddddddddddd dddddddddddd</div>
<div class="right">asdasdfgdsgdf</div>
</div>
CSS
.dia {
background: #282828;
padding: 10px;
height: 106px;
border-radius: 5px;
width: inherit;
}
.dia .left, .dia .right {
overflow: hidden;
height: 106px;
}
.dia .left {
float: left;
margin-right: 10px;
}
.dia .right {
float: right;
margin-left: 10px;
}
.dia .center {
height: inherit;
float: left;
}
jQuery
$('.dia .left a:not(:first-child)').css('width',$('.dia a').outerWidth(true)+'px');
$('.dia .center').css('width',$('.dia').width()-$('.dia .left').outerWidth(true)-$('.dia .right').outerWidth(true)+'px');
和小提琴