在段落 (X)HTML 和 CSS 之间留出一个空格
我希望我的
content
标签之间有空格。不在
标签之前或之后。例如,我的代码是:
<div>
<h1>A headline</h1>
<p>Some text</p>
<p>Some text</p>
</div>
Something
我不希望 h1 和 p 之间有空格,这是在 h1 上以零边距完成的。但我不希望最后一个 标记后有空格。如果没有 :last-child 或一些 JavaScript/jQuery,这可能吗?
我无法在最后一个标签上设置class="last",因为它是 CMS 系统。
I want space between my <p>content</p>
tags. Not before and not after <p>
tags. For example, my code is:
<div>
<h1>A headline</h1>
<p>Some text</p>
<p>Some text</p>
</div>
Something
I don't want space between h1 and p which is done with zero margin on h1. But I don't want space after the last <p>
tag. Is this possible without :last-child or some JavaScript/jQuery?
I can't set class="last" on the last tag because it is a CMS system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
(尽管这需要比 IE6 更好地支持 CSS 的浏览器。)
(Although this requires a browser with better support for CSS than IE6.)
如果您不需要支持 Internet Explorer 6 (IE6),您可以使用:
如果您需要支持 IE6,这是一个肮脏的 hack,但无需 JavaScript 即可工作:
此方法的缺点是您不能简单地使用 1em 等来平衡边距,因为它们具有不同的字体大小。您可以根据需要手动调整或使用像素宽度。
If you're not required to support Internet Explorer 6 (IE6) you can use:
If you need to support IE6, this is a dirty hack but it works without JavaScript:
The disadvantage of this method is that you can't simply use, say, 1em for the balancing margins as they have different font sizes. You can either manually adjust as required or use pixel widths.
将默认下边距设置为 p,然后为最后一个标签指定一个没有下边距的类。
Set a default bottom-margin to p, then give the last tag a class with no bottom-margin.
?
?
如果您想让它与浏览器更加兼容,您还可以使用:
负边距会将元素拉向它们。它比我喜欢的更混乱,但是当您受制于 CMS 生成的代码而无法添加类时,您必须发挥创造力。
If you want to make it more browser compatible, you could also use:
Negative margins will pull elements toward them. It's messier than I like, but when you are at the mercy of CMS generated code with no way to add classes, you have to be creative.