假设我有以下内容:
<div class="entry">
<p>I want to display <br /><h2>heading level elements like this</h2>
<p> as inline elements on the same line with the text that preceded them as well as...</p>
<p>the text that<br />
<h3>(another heading element)</h3>
<p>, follows them...</p>
</p></p>
</div>
Run Code Online (Sandbox Code Playgroud)
我希望标题元素内联显示在文本中,就像它们只是粗体文本一样,大小与内容相同。
有什么想法 CSS 可以在上面的例子中完成这个而不改变内容吗?
使用display:inline属性:
.entry h2, /* Combining two selectors: h2/h3 as a child of class=entry */
.entry h3 {
display: inline;
}
Run Code Online (Sandbox Code Playgroud)
另请参阅:MDN、CSS 显示