从文本中删除边距
我在图像上有一个文本,但文本上方和下方有一个奇怪的边距。我margin-bottom: 0;已经尝试过了,但这并没有奏效。
.text {
position: absolute;
margin: 0;
left: 30px;
right: 0;
text-align: left;
top: 40%; /* Adjust this value to move the positioned div up and down */
color: black;
text-shadow: 3px 3px 1px rgba(0, 0, 0, 0.16);
font-size: 75px;
}
<div>
<h1>Test</h1>
</div>
<div>
<h1>Test</h1>
</div>
回答
您需要从h1标签中删除边距而不是div,这是因为该h1元素具有默认边距。
.text {
position: absolute;
margin: 0;
left: 30px;
right: 0;
text-align: left;
top: 40%; /* Adjust this value to move the positioned div up and down */
color: black;
text-shadow: 3px 3px 1px rgba(0, 0, 0, 0.16);
font-size: 75px;
}
.text h1{
margin-top: 0;
margin-bottom: 0;
}