CSS 可以根据之前的标题类给我段落样式吗?
所以我想为采访记录设置一些 CSS 规则。我想到的格式看起来像这样:
<h2 class="interviewer">Alice: [00:00:00]</h2>
<p>Is it ok if I ask you a question now?</p>
<h2 class="interviewee">Bob: [00:00:03]</h2>
<p>Sure go ahead.</p>
我希望该段落是基于前面标题的类别的特定颜色。有没有办法做到这一点,因为它会使 html 标记变得更加简单。
So I want to rig up some css rules for interview transcripts. The format I have in mind looks something like this:
<h2 class="interviewer">Alice: [00:00:00]</h2>
<p>Is it ok if I ask you a question now?</p>
<h2 class="interviewee">Bob: [00:00:03]</h2>
<p>Sure go ahead.</p>
I'd like the paragraph to be a particular colour based on the class of the preceeding heading. Is there a way to do this, as it would make the html markup significantly simpler.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用以下兄弟组合器: +
h2.interviewer + p { /* 样式位于此处 */ }
You can use following-sibling combinator: +
h2.interviewer + p { /* style goes here */ }
当然:
我不完全确定如何处理多个段落。也许如果您将整个段落集包含在
div
中:您可以这样做:
Sure:
I'm not entirely sure how to do it with multiple paragraphs though. Perhaps if you encased the entire set of paragraphs in a
div
:You could then do this:
顺便说一句,有更好的 HTML 元素用于显示对话,例如新引入的
标签http://www.quackit.com/html_5/tags/html_dialog_tag.cfm
更新:
元素从未进入HTML5。它不存在。By the way, there are better HTML elements for displaying a conversation, like the newly introduced
<dialog>
taghttp://www.quackit.com/html_5/tags/html_dialog_tag.cfm
UPDATE:
The
<dialog>
element never made it into HTML5. It does not exist.