我在CSS printed media岁左右.我有遵循此 struct 的HTML文档:

具有以下子元素的main元素:

  • 强制性:div.list-of-titles个元素(文档具有内容表、图表、图像.在这div)
  • 可选:section.dedication elements(文件可能有奉献)
  • 可选且无界:section.preface(文档可能有一个或多个序言部分)
  • 强制且无界:section.chapter(文档有一个或多个章节)

对于好的老式书籍,我想用ToC和注释(如果有的话)用罗马数字对页面进行编号,并用小数/阿拉伯数字对real content进行编号.为此,我必须在real content开始时做counter-reset: page.

real content可以从前一个section.preface元素开始,或者,如果没有这样的元素,可以从前一个section.chapter元素开始.所以我的问题是:

如何 Select main元素中的first child element(section)并且具有preface类或chapter类?

谢谢, 弗兰克·施泰姆克

推荐答案

最明确的方法可能是简单地说明每种可能性 使用CSS + combinator.

main>div.list-of-titles:first-child+section.dedication+section.preface,
main>div.list-of-titles:first-child+section.dedication+section.chapter,
main>div.list-of-titles:first-child+section.preface,
main>div.list-of-titles:first-child+section.chapter {
  border: solid 1px red;
}
<main>
  <div class="list-of-titles">list of titles</div>
  <section class="dedication">dedication</section>
  <section class="preface">preface1</section>
  <section class="preface">preface2</section>
  <section class="chapter">chapter1</section>
  <section class="chapter">chapter2</section>
</main>
<main>
  <div class="list-of-titles">list of titles</div>
  <section class="dedication">dedication</section>
  <section class="chapter">chapter1</section>
  <section class="chapter">chapter2</section>
</main>
<main>
  <div class="list-of-titles">list of titles</div>
  <section class="preface">preface1</section>
  <section class="preface">preface2</section>
  <section class="chapter">chapter1</section>
  <section class="chapter">chapter2</section>
</main>
<main>
  <div class="list-of-titles">list of titles</div>
  <section class="chapter">chapter1</section>
  <section class="chapter">chapter2</section>
</main>

这里的具体性可能比您在实践中需要的要多,并且您可以使用CSS嵌套工具来缩短内容.

Html相关问答推荐

微软Edge中HTML页面上的奇怪文本指针

如何使文本从按钮中心生长?

你能让Cypress测试为p—fileUpload做文件上传吗?

我需要主页按钮出现在中间

如何使用css为动态用户输入矩阵添加背景色?

页脚与主要内容重叠

我怎样才能在我的网站上制作花哨的角落

在css中,如何在英雄版块的标题后面做一个粘性的导航栏?

从网页中提取URL

在css中是否可以在遮罩图像中结合线性渐变和径向渐变?

(HTML框架标签)点击后目标框架将不再工作

为什么我的 html 对话框在 React 中没有渲染在我的内容之上?

按钮位于主 div 的底部而不是内部 Div

将箭头图标添加到工具提示包装器时遇到问题

将三个div转换为显示flex

带有数据 URI 的音频在 Chrome 中失败

::可点击图标之前

网页设计不适合移动设备

无法使用 flexbox 裁剪图像

font awesome 的 CDN/CSS 如何工作?