Html 如何从标题元素中删除空白?

Html 如何从标题元素中删除空白?,html,css,Html,Css,我想将这个div中的单词与它旁边div中的图片对齐,但是在h1和h3元素的顶部和底部都有空白。我使用flexbox将它们垂直对齐,并使用对齐内容和均匀的空间。我已经在CSS中指定删除标题元素上的任何边距或填充。我被这个问题困住了。我附上了Firefox的截图来解释我遇到的问题 grid-area: card-description; display: flex; flex-direction: column; justify-content: space-between;

我想将这个div中的单词与它旁边div中的图片对齐,但是在h1和h3元素的顶部和底部都有空白。我使用flexbox将它们垂直对齐,并使用对齐内容和均匀的空间。我已经在CSS中指定删除标题元素上的任何边距或填充。我被这个问题困住了。我附上了Firefox的截图来解释我遇到的问题

grid-area: card-description; display: flex; flex-direction: column; justify-content: space-between; line-height: normal; } #card-description h1, h3 { line-height: normal; margin: 0; padding: 0; }``` [1]: https://i.stack.imgur.com/RFwJw.png 网格区域:卡片描述; 显示器:flex; 弯曲方向:立柱; 证明内容:之间的空间; 线高:正常; } #卡说明h1、h3{ 线高:正常; 保证金:0; 填充:0; }``` [1]: https://i.stack.imgur.com/RFwJw.png 文本在框(内容区域)中呈现,并带有导致间隙的前导。这个间隙是自然的,给了文本喘息的空间

为了与您的箱子一样的边缘对齐,您可以通过负垂直边距或填充来消除间隙,以“挤压”容器:

顶部填充:-10px;/*调整该值以适合您的布局*/
垫底:-10px;
和/或对包含的文本应用负边距(
h1的
margin top
h3的
margin bottom

您可以尝试的另一种方法是减少文本的
行高
(有效地删除前导)

h1{
线条高度:1;/*或甚至0.8,用于更紧密的距离*/
}

但这只适用于单行文本(如您的
h1
),因为文本行将全部压缩在一起,可能不是您想要的。您能分享一些代码吗?您迄今为止所做的工作吗?谢谢您的帮助。然而,这对我来说并不奏效。我编辑了这篇文章并提供了更多的代码。line height属性定义了内联元素上方和下方的空间量。即,设置为“显示:内联”或“显示:内联”块的元素。此属性最常用于设置文本行的前导。line height属性可以接受关键字值normal或none以及数字、长度或百分比。可以使用任何有效的CSS单元(px、em、rem等)定义长度值。百分比值是元素的字体大小乘以百分比值,可以尝试类似于:1rem、20%或1px的方式,只需玩转数字即可。
@leonking93 there is no need for you to give all the four properties 0px you can simply do.
margin: 0;
padding:0; <<<<< this is equivalent to what you have done.
As far as you question goes you can give line height to the the text element this will solve you issue.
 line-height: normal

// You can give the value for this in many 
// forms. You can go through the 
// below given link.


Visit https://www.w3schools.com/cssref/pr_dim_line-height.asp