我正在使用<code>额外的CSS.我想增加左/右边距
code {
margin-left: 10px;
margin-right: 10px;
}Run Code Online (Sandbox Code Playgroud)
This word is a <code>reserved</code> word.Run Code Online (Sandbox Code Playgroud)
这通常很好,但是如果这个单词在一行的开头,那么左边有一个我不想要的尴尬的额外边距.例:
code {
margin-left: 10px;
margin-right: 10px;
}Run Code Online (Sandbox Code Playgroud)
This word is a <br><code>reserved</code> word.Run Code Online (Sandbox Code Playgroud)
要清楚的<br>是,仅仅是针对上面的例子...我不知道什么时候<code>它在行的开头,它取决于它是如何折叠的(对于给定的窗口宽度).
CSS word-spacing似乎可能是这里的修复,但它似乎只是字间距,所以它不起作用.
有没有办法用CSS完成这个?
有没有办法选择一个CSS元素作为其父元素的第一个子元素,计算文本节点?如果标题位于其父级的顶部,我想删除标题的上边距,但如果我使用:
#content h1 {
margin-top: 1em;
}
#content h1:first-child {
margin-top: 0;
}
Run Code Online (Sandbox Code Playgroud)
并有一些HTML喜欢
<div id="content">
This is some text.
<h1>A heading</h1>
Some more text.
</div>
Run Code Online (Sandbox Code Playgroud)
保证金仍然被删除.CSS有什么方法可以防止这种情况发生吗?