html - 我的文本在 div 中的每个新行之间有很大的垂直空间?

标签 html css text spacing

如果运行以下代码,您会注意到单词 hello 在白色 div 中垂直输出,每行之间的距离很大。我尝试了很多不同的事情,例如摆脱边距样式(不确定它是否重要)但没有找到解决方案。

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252">  
<title>div_experiment</title>
</head>
<body>
<style type = "text/css">
body
{
    background-color: black;
}
#div_id
{
    position: absolute;
    top: 0%;
    left: 50%;
    margin: 0 auto; 
    overfill: auto auto;    
    max-height: 696px;  
    background-color: white;
    font-size: 25px;
}
</style>
<script language="JavaScript"> 
</script>   
<div id = "div_id">
    <p>hello</p><br>
    <p>hello</p><br>
    <p>hello</p><br>    
</div>
</body>
</html>

最佳答案

您的段落元素具有该边距,而不是容器。所以这个规则应该修复它:

#div_id p {margin: 0;}

关于html - 我的文本在 div 中的每个新行之间有很大的垂直空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807089/

相关文章:

java - css 样式在 javax 邮件 api 中不起作用

javascript - 在 html5 canvas 中将文本绘制为图像

php 表单选择应该触发 url 更改和值更改

javascript - 用户选择另一个选项卡,页面标题每 8 秒更改为不同的标题

javascript - 在 Javascript 中获取本地文件的内容

javascript - 删除 <th> 的内容

css - 切换溢出属性时,谷歌浏览器不会调整内容大小

text - 如何在 JavaFX 中让文本内容在一段时间后消失?

python - 这个文本处理代码是 Pythonic 的吗?

javascript - 将外部标记正确加载到多个页面中