简体   繁体   中英

An empty line before h1

I think it's a really simple CSS problem, but I just don't know how to solve it.

Why is there an empty line before <h1>, and how to remove it (without setting margin and line-height if possible)? 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

The break is there because you are using block elements. An empty <div> element will otherwise cause a line break. You can avoid this by putting display:inline-block; in the CSS for the divs.

You can add display: inline to your div to solve this.

See: http://tinkerbin.com/HDmlrG6u

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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