flex box容器div.中的行间距



为什么flex box容器中有这么多行距?我该如何调整?我在w3schools尝试了一个例子,得到了这个。

.flex-container {
display: flex;
flex-direction: column;
background-color: DodgerBlue;
}
.flex-container>div {
background-color: #f1f1f1;
width: 200px;
margin: 10px;
text-align: center;
line-height: 75px;
font-size: 30px;
}
p {
margin: 0
}
<h1>The flex-direction Property</h1>
<p>The "flex-direction: column;" stacks the flex items vertically (from top to bottom):</p>
<div class="flex-container">
<div>
<p>The quick brown fox jumps over the lazy dog</p>
</div>
</div>

链接::https://www.w3schools.com/css/tryit.asp?filename=trycss3_flexbox_flex-方向_列我试过p {margin: 0},但仍然没有用。请帮忙。非常感谢。

如果是,是否要减小p标记之间的行间距?请尝试更改flex-container>div中的line-height:0

<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
flex-direction: column;
background-color: DodgerBlue;
}
.flex-container > div {
background-color: #f1f1f1;
width: 200px;
margin: 10px;
text-align: center;
font-size: 30px;
}
</style>
</head>
<body>
<h1>The flex-direction Property</h1>
<p>The "flex-direction: column;" stacks the flex items vertically (from top to bottom):</p>
<div class="flex-container">
<div><p>The quick brown fox jumps over the lazy dog</p></div>

</div>
</body>
</html>

75像素是一个非常高的线高度。只需将其更改为较小的数字,例如"0";35px";或";1.2〃;你会看到区别的。

.flex-container > div {
line-height: 1.2;
}

要清除空间,只需移除或调整line-height: 75px;

.flex-container>div

您可以完全删除它,线条高度将自动调整为浏览器默认值,该值接近1.2,具体取决于您的浏览器设置和PC的字体大小。

因此,线路高度将计算如下:

line-height: 1.8975(大致为浏览器默认值)*(元素示例30px的字体大小)建议你在做数学时使用1.2,但是的,我只是想尽可能准确。

该元素的高度将是35.692px,乘以行高和字体大小,这就是浏览器为您所做的。但如果你想要更多,你可以使用更多。

您也可以使用percentage ( % )

这是一个伟大的页面,你可以阅读关于线高度

最新更新