简体   繁体   English

如何去除段落之间的空格 (p)

[英]How to remove the space between paragraphs (p)

How can I remove spaces between paragraphs in HTML?如何删除 HTML 中段落之间的空格?

<p class="first">This is a small demo</p>
<p class="second">This is second demo</p>

You can use margin: 0;您可以使用margin: 0; to remove the spaces.删除空格。

p { margin: 0; }

If this still don't work, try making it !important如果这仍然不起作用,请尝试制作!important

p { margin: 0 !important; }

Check this http://jsfiddle.net/zg7fP/1/检查这个http://jsfiddle.net/zg7fP/1/

Try setting margin-bottom: 0 on the top paragraph and margin-top: 0 to the bottom paragraph尝试将margin-bottom: 0设置为顶部段落,将margin-top: 0设置为底部段落

or you can use a div instead of the paragraph或者您可以使用 div 代替段落

You can set the default margin to zero with CSS:您可以使用 CSS 将默认边距设置为零:

p {
  margin: 0px;
}

You should use p {margin: 0 auto;}你应该使用p {margin: 0 auto;}

In case you want to add indentation (recommended if you remove spaces between paragraphs) a good technique is:如果您想添加缩进(如果您删除段落之间的空格,建议您这样做)一个好方法是:

p + p {text-indent: 1.25em;}

如果您使用引导程序,这是解决方案:类 m-0

<p class="m-0">text</p>

将两者放在一组 p 中并用 br 分开

Try to use line-height: 100%;尝试使用line-height: 100%; or other percentage you think it feets well on your HTML.或其他您认为适合您的 HTML 的百分比。

There are a range of "mx" classes you can add to paragraph elements where x (0+) represent integers driving increasing space between paragraphs:您可以将一系列“mx”类添加到段落元素,其中 x (0+) 表示推动增加段落之间空间的整数:

For example, this will have no space between the paragraphs:例如,这将在段落之间没有空格:

<p class="m-0">hello world</p>
<p class="m-0">hello world</p>

For example, this will have a bit more:例如,这将有更多:

<p class="m-1">hello world</p>
<p class="m-1">hello world</p>

For example, this will have yet more:例如,这将有更多:

<p class="m-2">hello world</p>
<p class="m-2">hello world</p>

And so on...等等...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM