缩进h2后的所有标签,直到下一个h2使用CSS命中 [英] Indent all tags following h2 until next h2 is hit using CSS

查看:327
本文介绍了缩进h2后的所有标签,直到下一个h2使用CSS命中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我想对doxygen输出进行不同的设计。
目前生成的html如下所示:

In our project I'd like to style our doxygen output differently. Currently the generated html looks like the following:

<html>
<body>
    <h1> Heading 1 </h1>

    <h2> Heading 2.1 </h2>
    <p> Paragraph 2.1.1 </p>
    <p> Paragraph 2.1.2 </p>
    <p> Paragraph 2.1.3 </p>

    <h2> Heading 2.2 </h2>
    <p> Paragraph 2.2.1 </p>
    <p> Paragraph 2.2.2 </p>
    <p> Paragraph 2.2.3 </p>
</body>
</html>

< h2> 具有 font-size 属性以及所有< h2> < p> / code>标签在文档左侧对齐。

The <h2> is only styled with a font-size attribute and all <h2> and <p> tags are aligned on the left side of the document.

要让下面的内容< h2> code>标签在视觉上突出显示我想缩进标签,直到下一个< h2> 标签。

到目前为止,我尝试的是以下CSS规则:

What I tried so far is the following CSS rule:

h2 + * {
    margin-left: 10px;
}

* 因为除了< p> 标签之外还存在其他标签。
但是,此规则仅缩进< h2> 标记后面的第一个段落,而不是所有标签直到下一个< h2> ; 标签。

The * is used since there are also other tags present besides <p> tags. However, this rule only indents the first paragraph following the <h2> tag and not all tags up to the next <h2> tag.

还应该提到的是,html的结构不能改变, $ c>< div> 例如。

It should also be mentioned that the structure of the html can not be changed to wrap each section inside of a <div> for example.

推荐答案

在第一个h2之后的兄弟姐妹除了其他的h2s,在这种情况下,这应该做的工作:

It sounds like you want to indent all siblings after the first h2 except other h2s, in which case this should do the job:

h2 ~ *:not(h2) {
    margin-left: 10px;
}

请参阅一般兄弟组合器否定伪类以及 jsbin上的现场演示

这篇关于缩进h2后的所有标签,直到下一个h2使用CSS命中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆