HTML <aside> 标签

HTML <aside> 标签用于表示文档中与主内容间接相关的部分。它最常用于文档的侧边栏。它在浏览器中不会渲染任何特殊效果。例如,

<div>
    <h1>This is a heading</h1>
    <aside>
        <p>This is a paragraph</p>
    </aside>
</div>

浏览器输出

HTML aside element

在此,<aside> 元素包含一个与 <h1> 元素间接相关的段落。


CSS 与 HTML <aside>

我们使用 CSS 来设置 HTML <aside> 的样式。例如,

<aside>
    <h2>Sidebar</h2>
    <p>This is some content in the sidebar.</p>
</aside>
<main>
    <h1>Main Content</h1>
    <p>This is the main content of the page.</p>
</main>
<style>
    main {
        padding: 10px;
        margin: 10px;
    }

    aside {
        width: 200px;
        border: 1px solid black;
        padding: 10px;
        margin: 10px;
        float: left;
    }
</style>

浏览器输出

HTML aside element with main content

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战