小编use*_*996的帖子

根据标题缩进内容

我正在尝试获得一种缩进样式,如下所示

H1
Content here
    H2
    Any content after the H2, paragraphs, images, etc
        H3
        Any content after the H2, paragraphs, images, etc
    H2
    content
H1 another top level heading
etc
Run Code Online (Sandbox Code Playgroud)

示例 html:

<h1>heading 1</h1>
<p>content</p>
<h2>heading 2</h2>
<p>content</p>
<p>content</p>
<h3>heading 2</h3>
<p>content</p>
<img src="something.png" />
<p>content</p>
<h1>heading 1</h1>
<p>content</p>
Run Code Online (Sandbox Code Playgroud)

我试过以下

h2, h2 + * {
    margin-left: 30px;
}

h3, h3 + * {
    margin-left: 60px;
}
Run Code Online (Sandbox Code Playgroud)

但这只会在标题后的第一个元素上设置边距,我需要所有后续标签,直到下一个。

有任何问题请追问。

我想指出的是,我无法重写 hml,因为我将它应用到已经创建了许多页面的网站。

一些示例代码https://codepen.io/User1972/pen/WZyKNR

css

6
推荐指数
1
解决办法
1610
查看次数

标签 统计

css ×1