
网页布局中,精准控制文本行高至关重要。line-height属性通常能轻松解决此问题。然而,当<p></p>标签嵌套在<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></pre>标签内,并尝试使用line-height: 0;消除段落间距时,可能会出现意想不到的结果。
问题:作者尝试使用p { line-height: 0; }来消除<p></p>标签间的间距。在非<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></pre>环境下,此方法有效。但当代码片段包含在<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></pre>标签内时,p { line-height: 0; }失效,段落间距依然存在。即使添加pre { line-height: 0; }和pre p { line-height: 0; }也无法解决问题。
解决方案:将line-height: 0;直接应用于<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></pre>元素本身。修改样式为pre { line-height: 0; }即可。<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></pre>标签会继承并应用其子元素的样式,设置<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false;"></pre>标签行高为0,能有效影响其内部所有元素(包括<p></p>
标签)的行高,从而消除段落间距。
以上就是如何在``标签内有效消除``标签间的间距?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号