Thứ Sáu, 26 tháng 7, 2013

thẻ div trong html

Mô tả thẻ DIV:

Thẻ <div> trong XHTML xác định các vùng logic - logical divisions bên trong nội dung của một trang. Nó giúp định dạng, quản lý, sao chép các sections trong trang web. Nó là công cụ mạnh hỗ trợ cho các Web developers trong việc thiết kế web theo chuẩn của W3C.

VÍ DỤ VỀ THẺ <DIV>

Ví dụ khối sau có nền màu xanh:
<div style="color:#00FF00">
<h3>This is a header</h3>
<p>This is a paragraph.</p>
</div> 

KHÁC BIỆT GIỮA HTML VÀ XHTML

Thuộc tính "align" của thẻ div được hỗ trợ trong HTML 4.01, nhưng không được hỗ trợ trong XHTML 1.0 Strict DTD.

Sử dụng thẻ DIV:

  • Thẻ <div> là một phần tử khối
  • Thẻ <div> có thể chứa bất kỳ thẻ nào khác
  • Thẻ <div> không thể nằm trong thẻ <p>

Tips:

  • Thẻ <div> không thay thế thẻ <p>. Thẻ <p> chỉ dùng cho đoạn văn bản, hỗ trợ định dạng đoạn văn bản với các khoảng trắng, trong khi thẻ <div> xác định nhiều vùng trong một tài liệu HTML. Đừng thay thế thẻ <p> bằng <div>.
  • Bạn nên đặt id cho các thẻ <div> riêng biệt. Và áp dụng một lớp CSS cho các div có cùng một style. 
  • Ví dụ, để xác định nội dung chính của site, bạn nên đặt id cho thẻ DIV là: "maincontent". <div id="maincontent">
Sử dụng Thẻ div kết hợp với CSS để tạo bố cục cho trang web.
Chú ý: Đừng quên đóng thẻ div </div> khi bạn đã tạo một thẻ mở. Nếu không bố cục website của bạn có thể bị sai lệch ngoài ý muốn.
Trình duyệt sẽ đặt một đường thẳng phân cách trước và sau các thẻ div.

THUỘC TÍNH TÙY CHỌN

DTD chỉ rõ thuộc tính được cho phép. S=Strict, T=Transitional, and F=Frameset.
AttributeValueDescriptionDTD
alignleft
right
center
justify
Deprecated. Use styles instead.
Specifies the alignment of the content inside a div element
TF


THUỘC TÍNH CHUẨN

AttributeValueDescriptionDTD
classclassnameSpecifies a classname for an elementSTF
dirrtl
ltr
Specifies the text direction for the content in an elementSTF
ididSpecifies a unique id for an elementSTF
langlanguage_codeSpecifies a language code for the content in an elementSTF
stylestyle_definitionSpecifies an inline style for an elementSTF
titletextSpecifies extra information about an elementSTF
xml:langlanguage_codeSpecifies a language code for the content in an element, in XHTML documentsSTF

THUỘC TÍNH SỰ KIỆN

Thẻ <div> hỗ trợ các thuộc tính sự kiện sau:
AttributeValueDescriptionDTD
onclickscriptScript to be run on a mouse clickSTF
ondblclickscriptScript to be run on a mouse double-clickSTF
onmousedownscriptScript to be run when mouse button is pressedSTF
onmousemovescriptScript to be run when mouse pointer movesSTF
onmouseoutscriptScript to be run when mouse pointer moves out of an elementSTF
onmouseoverscriptScript to be run when mouse pointer moves over an elementSTF
onmouseupscriptScript to be run when mouse button is releasedSTF
onkeydownscriptScript to be run when a key is pressedSTF
onkeypressscriptScript to be run when a key is pressed and releasedSTF
onkeyupscriptScript to be run when a key is releasedSTF

Không có nhận xét nào:

Đăng nhận xét