Bạn có thể sử dụng absolute
và relative
vị.
ví dụ
html
<div id="container" class="box">
<div class="box top left"></div>
<div class="box top center"></div>
<div class="box top right"></div>
<div class="box middle left"></div>
<div class="box middle center"></div>
<div class="box middle right"></div>
<div class="box bottom left"></div>
<div class="box bottom center"></div>
<div class="box bottom right"></div>
</div>
css
#container{
width:200px;
height:200px;
position:relative;
border:1px solid black;
}
.box{
border:1px solid red;
position:absolute;
width:20px;
height:20px;
}
.top{top:0}
.middle{top:50%;margin-top:-10px;/*half of the .box height*/}
.bottom{bottom:0}
.left{left:0;}
.center{left:50%;margin-left:-10px;/*half of the .box width*/}
.right{right:0;}
Demo tạihttp://jsfiddle.net/gaby/MB4Fd/1/
(ofcourse bạn có thể điều chỉnh vị trí thực tế theo sở thích của mình, bằng cách thay đổi giá trị trên cùng/trái/phải/dưới)
Nguồn
2013-02-25 14:06:19
Ý của bạn là: bạn không biết gì về html và muốn người khác làm mẫu html cho bạn ? –
Bạn sai người bạn của tôi, đó là css :) Hãy thử thân thiện hơn lần sau, không có trở ngại nào ngăn cản bạn khỏi điều đó. – Stybos