<header> <img src="/static/imghw/default1.png" data-src="logo.png" class="lazy" alt="停止過度使用 Div!語意 HTML 最佳實務實用指南"> <nav> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> </ul> </nav> </header> <main> <h2>About Us</h2> <p>Lorem ipsum...</p> <h2>How It Works</h2> <p>Lorem ipsum...</p> <aside>Sidebar content...</aside> </main> <footer> <p>Terms & Conditions</p> </footer>
<header>
:包含標誌和主導航。 <nav>
:包含主要導航連結。 <main>
:包含頁面的主要內容。 <h2>
和 <p>
:邏輯地建構主要內容。 <aside>
:代表次要內容,例如側邊欄。 <footer>
:包括不太重要的訊息,例如條款和條件。 <main> <h1>JavaScript Guide</h1> <p>Learn JavaScript...</p> <nav> <ul> <li><a href="#toc">Table of Contents</a></li> </ul> </nav> </main>
<main>
元素明確定義了核心內容。 它是獨立的且可重複使用。 <main>
部分中,因為它對於指南的可用性至關重要。 <div> <p>Why a div here? The info-bar groups unrelated elements (breadcrumbs and a button) purely for layout; they lack a shared semantic purpose.</p> <h2>Summary</h2> <p>Use semantic tags when:</p> <ul> <li>Content is related (<article>).</li> <li>It's self-contained (<article>).</li> <li>It's critical navigation (<nav>).</li> <li>It's secondary content (<aside>).</li> </ul> <p>Use divs when: You need a container solely for styling.</p> <p>If you found this helpful, please like and follow! Thanks for reading!</p> <p>Connect with me on:</p> <p><strong>LinkedIn</strong> | <strong>Medium</strong> | <strong>Bluesky</strong></p> </div>
以上是停止過度使用 Div!語意 HTML 最佳實務實用指南的詳細內容。更多資訊請關注PHP中文網其他相關文章!