position: static;... Các thuộc tính top, bottom, left and right không có tác dụng.. position: absolute; Ví dụ 1:... position: relativePosition:relative cho phép nó với div chứa nó gắn kế
Trang 11. position: static;
<div style="width:300px; height: 100px; border: 1px solid yellow;">
</div>
<div style="width:300px; height: 300px; border: 1px solid black;">
</div>
<div style="width:300px; height: 100px; border: 1px solid yellow;">
</div>
<div style="width:300px; height: 300px; border: 1px solid black;">
<div style="width:200px; height: 200px; border: 1px solid red; top: 100;ty” >
</div>
Trang 2</div>
Các thuộc tính top, bottom, left and right không có tác dụng.
2 position: absolute;
Ví dụ 1:
<div style="width:300px; height: 100px; border: 1px solid yellow;">
</div>
Trang 35020
Trang 43 position: relative
Position:relative cho phép nó với div chứa nó gắn kết với nhau như sau:
Ví dụ 1:
<div style="width:300px; height: 100px; border: 1px solid yellow;">
</div>
<div style="width:300px; height: 300px; border: 1px solid black;">
<div style=" position: relative; top: 20px; left: 10px;width:200px; height: 200px;
border: 1px solid red;">
</div>
</div>
Top, left thì lấy từ góc trên, bên trái của div màu đen trở xuống dưới.
Trang 51020
Ví dụ 2:
<div style="width:300px; height: 100px; border: 1px solid yellow;">
</div>
<div style="width:300px; height: 300px; border: 1px solid black;">
<div style="position: relative; bottom: 20px; right: 10px; width:200px; height:
200px; border: 1px solid red;">
</div>
</div>
Trang 64 Kết hợp Position
<div style="width:300px; height: 100px; border: 1px solid yellow;">
</div>
<div style="position: relative; width:300px; height: 300px; border: 1px solid black;">
<div style=" position: absolute; top: 20px; left: 10px; width:200px; height: 200px;
border: 1px solid red;">
</div>
</div>
Khi thêm position:relative cho div màu đen và position:absolute cho div màu đỏ thì khung màu đỏ sẽ lấy div màu đen là góc, để định top,left,right,left tương ứng.
Trang 7*Nếu cha relative hoặc absolute mà con là relative, absolute: Lấy cha làm gốc tọa độ.