Thẻ HTML <main>
Thí dụ
Nêu nội dung chính của tài liệu:
<main>
<h1>Most Popular Browsers</h1>
<p>Chrome, Firefox, and
Edge are the most used browsers today.</p>
<article>
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser
developed by Google, released in 2008. Chrome is the world's most popular web
browser today!</p>
</article>
<article>
<h2>Mozilla
Firefox</h2>
<p>Mozilla Firefox is an open-source web browser developed by
Mozilla. Firefox has been the second most popular web browser since January,
2018.</p>
</article>
<article>
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015.
Microsoft Edge replaced Internet Explorer.</p>
</article>
</main>
Thêm các ví dụ "Hãy tự mình thử" bên dưới.
Định nghĩa và Cách sử dụng
Thẻ <main>
chỉ định nội dung chính của tài liệu.
Nội dung bên trong <main>
phần tử phải là duy nhất cho tài liệu. Nó không được chứa bất kỳ nội dung nào được lặp lại trên các tài liệu như thanh bên, liên kết điều hướng, thông tin bản quyền, biểu trưng trang web và biểu mẫu tìm kiếm.
Lưu ý: Không được có nhiều hơn một <main>
phần tử trong một tài liệu. Phần <main>
tử KHÔNG được là con của phần tử <article>, <aside>, <footer>, <header> hoặc <nav>.
Hỗ trợ trình duyệt
Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ phần tử.
Element | |||||
---|---|---|---|---|---|
<main> | 26.0 | 12.0 | 21.0 | 7.0 | 16.0 |
Thuộc tính toàn cầu
Thẻ <main>
cũng hỗ trợ Thuộc tính chung trong HTML .
Thuộc tính sự kiện
Thẻ <main>
cũng hỗ trợ Thuộc tính sự kiện trong HTML .
Các ví dụ khác
Thí dụ
Sử dụng CSS để tạo kiểu cho phần tử <main>:
<html>
<head>
<style>
main {
margin: 0;
padding: 5px;
background-color: lightgray;
}
main
> h1, p, .browser {
margin: 10px;
padding: 5px;
}
.browser {
background: white;
}
.browser > h2,
p {
margin: 4px;
font-size: 90%;
}
</style>
</head>
<body>
<main>
<h1>Most
Popular Browsers</h1>
<p>Chrome, Firefox, and Edge are the
most used browsers today.</p>
<article class="browser">
<h2>Google Chrome</h2>
<p>Google Chrome is a web browser
developed by Google, released in 2008. Chrome is the world's most popular web
browser today!</p>
</article>
<article class="browser">
<h2>Mozilla Firefox</h2>
<p>Mozilla Firefox is an
open-source web browser developed by Mozilla. Firefox has been the second most
popular web browser since January, 2018.</p>
</article>
<article class="browser">
<h2>Microsoft Edge</h2>
<p>Microsoft Edge is a web browser developed by Microsoft, released in 2015.
Microsoft Edge replaced Internet Explorer.</p>
</article>
</main>
</body>
</html>