简体   繁体   English

h1之前的空行

[英]An empty line before h1

I think it's a really simple CSS problem, but I just don't know how to solve it. 我认为这是一个非常简单的CSS问题,但我只是不知道如何解决。

Why is there an empty line before <h1>, and how to remove it (without setting margin and line-height if possible)? 为什么<h1>前面有一个空行,以及如何将其删除(如果可能,不设置边距和行高)? Thank you! 谢谢!

<style>
.box-green { background-color: #CCC; }
.box-empty { height: 50px; }
</style>

<div class="box-empty box-green"></div>
<div class="box-green">
    <h1>There is an empty line before h1, why?</h1>
</div>


Edit: 编辑:

Result: http://tinkerbin.com/u6eB0PFQ 结果: http : //tinkerbin.com/u6eB0PFQ

The break is there because you are using block elements. 休息在那里是因为您正在使用块元素。 An empty <div> element will otherwise cause a line break. 空的<div>元素将导致换行。 You can avoid this by putting display:inline-block; 您可以通过使用display:inline-block;来避免这种情况display:inline-block; in the CSS for the divs. 在div的CSS中。

You can add display: inline to your div to solve this. 您可以将display: inline添加到div中以解决此问题。

See: http://tinkerbin.com/HDmlrG6u 请参阅: http//tinkerbin.com/HDmlrG6u

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM