如何让每个.wp_list
中的.c
都在右边和顶部,比如right:0 top:0
?
我设置了绝对位置,但如果那样的话 top: 0
代表 .wp
而不是 .wp_list
http://jsfiddle.net/8dMrx/
.wp{
background-color: blue;
position: absolute;
margin-left: auto;
margin-right: auto;
left: 0;
right: 0;
width: 450px;
}
.wp_list{
background-color: red;
margin: 10px;
height: 130px;
}
.a, .b, .c{
background-color: gray;
}
.a{
width: 220px;
height: 30px;
}
.b{
width: 220px;
height: 100px;
}
.c{
width: 130px;
height: 130px;
}
html
<div class="wp">
<div class="wp_list">
<div class="a">a</div>
<div class="b">b</div>
<div class="c">c</div>
</div>
<div class="wp_list">
<div class="a">a</div>
<div class="b">b</div>
<div class="c">c</div>
</div>
// generate from php
</div>
最佳答案
这应该可以解决问题:-
.wp_list{
background-color: red;
margin: 10px;
height: 130px;
position:relative; /*mark parent as relative*/
}
.c{
width: 130px;
height: 130px;
top:0; /*set right and top of the relative parent*/
right:0;
position:absolute; /*mark child as absolute*/
}
Fiddle
关于css - 如何使每个包装中的 1 个 div 保持在右侧和顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16825017/