Html 删除 <p> 之间的间距
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18392584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove spacing between <p>
提问by Pacha
I want to remove the spaces between paragraphs so all my text doesn't have any kind of space between each other, but I don't know which proprety I should use.
我想删除段落之间的空格,这样我的所有文本之间都没有任何空格,但我不知道应该使用哪种属性。
I am aware of line-height
, but tried messing around with different values and couldn't find the correct one.
我知道line-height
,但尝试使用不同的值并找不到正确的值。
Example code:
示例代码:
<style>
p
{
margin:0;
padding:0;
font-size:60px;
}
div
{
margin:0;
padding:0;
background-color:red;
}
</style>
<div>
<p>test</p>
<p>test</p>
</div>
Image of code (I want to remove the space between "test" and "test"):
代码图像(我想删除“test”和“test”之间的空格):
采纳答案by DA.
That space isn't between the paragraphs. that's the space given to the characters themselves. Type has white space around it (partially to accommodate ascenders and descenders).
该空间不在段落之间。那是给角色本身的空间。文字周围有空白区域(部分是为了容纳上升和下降)。
If you want to remove the space between the lines of text themselves, then you need to put the text into the same paragraph, and adjust the line height.
如果你想去除文本本身的行之间的空间,那么你需要将文本放入同一个段落中,并调整行高。
But even then, note that you'll never get this exact, as every typeface and font is going to have different metrics, and you won't always know what exact font will be shown on the end-user's screen. Using a web font will make things a bit more predictable for you.
但即便如此,请注意,您永远不会得到准确的结果,因为每种字体和字体都有不同的度量标准,并且您不会总是知道最终用户的屏幕上会显示什么确切的字体。使用网络字体会让事情变得更容易预测。
回答by Mohammed Hamz?
回答by Sasidhar Vanga
Check this out : http://jsfiddle.net/a45Mm/
看看这个:http: //jsfiddle.net/a45Mm/
HTML
HTML
<p>The quick brown fox jumps over the lazy dog.</p>
<p id='p2'>The quick brown fox jumps over the lazy dog.</p>
CSS
CSS
p {
font-size : 30px;
background-color : #cfc;
padding : 0;
margin : 0;
line-height : 20px;
}
#p2 {
background-color : #fcc;
}
You need to use all the following three properties
您需要使用以下所有三个属性
margin : 0
: This will remove space between two paragraphs.padding : 0
: This will remove space between the border and text of each paragraphline-height : 20px
: This will decrease spacing between different lines in each paragraph. A0
value for this property will bring all lines in a single line overlapping everything.
margin : 0
:这将删除两个段落之间的空格。padding : 0
:这将删除每个段落的边框和文本之间的空间line-height : 20px
:这将减少每个段落中不同行之间的间距。0
此属性的值会将所有行合并为一条与所有内容重叠的行。
回答by chucknelson
You can tweak the line height to get the sort of minimal spacing you're looking for.
您可以调整行高以获得所需的最小间距。
Fiddle: http://jsfiddle.net/chucknelson/UtwXk/
小提琴:http: //jsfiddle.net/chucknelson/UtwXk/
p
{
margin: 0;
padding:0;
font-size:60px;
line-height: .75em;
}
回答by Kaaveh Mohamedi
For first <p>
set: margin-bottom:0;
and for second <p>
set: margin : 0; padding-top:0;
simultaneously. It shoud be like:
第一<p>
组:margin-bottom:0;
和第二<p>
组:margin : 0; padding-top:0;
同时。它应该是这样的:
<p style="margin-bottom:0;">
test
</p>
<p style="margin : 0; padding-top:0;">
test
</p>
回答by poop
<'BR'> helps in some cases, so you might want to try that.
<'BR'> 在某些情况下会有所帮助,因此您可能想尝试一下。
this is a paragraph i want this piece to be separate
这是一段我希望这件作品是分开的
回答by Sachman Bhatti
I think what you are looking for is line-height:1em. em is relative to the font-size, so 2em means two times the size of the font.
我认为您正在寻找的是 line-height:1em 。em 是相对于字体大小的,所以 2em 表示字体大小的两倍。
回答by mrilikecoding
Try:
尝试:
margin-bottom: 0;
margin-bottom: 0;
By default the margin bottom is 1em
默认下边距为 1em
回答by THE AMAZING
The spacing is due to the font type. If you want the spacing to be smaller you will either have to change the font or do a position absolute on a relative div or section.
间距是由于字体类型。如果您希望间距更小,则必须更改字体或在相对 div 或部分上执行绝对位置。