有没有可能让正确的浮动div总是“堆叠”在彼此下面?
例如,我正在尝试这样做:
> ---------------------------------+
> |Container div | div1|
> |Fixed width +--+----+
> | |div2|
> | +----+----+
> | | div3|
> | +---------+
> | |
> +--------------------------------+
Div1、2和3是可变的宽度和高度。如果我只是将它们完全浮动,它们不会总是像那样堆叠在一起,有时div2会放在div1的左边,等等,因为布局试图最小化容器的高度。我希望它们总是堆叠在一起。
发布于 2012-12-05 21:41:55
这些css规则应该将它们放在正确对齐和堆叠的位置
.div1, .div2, .div3{
float: right;
clear: right;
}
屏幕截图
来源
.div1, .div2, .div3{
float:right;
clear:right;
}
.div2{
background-color:green;
width: 300px;
height: 20px;
}
.div1{
background-color:blue;
width: 100px;
height: 30px;
}
.div3{
background-color:red;
width: 80px;
height: 40px;
}
.container{
background-color: gray;
width: 400px;
height: 400px;
}
发布于 2012-12-05 21:41:27
在div1
、div2
、div3
周围放置一个DIV
包装器,并让包装器浮动,同时将div1
、div2
、div3
设置为display: block
和float: none
https://stackoverflow.com/questions/13732964
复制