简体   繁体   English

h2 不会与它上面的 h1 分开

[英]h2 will not separate from h1 above it

I have an h1 in a section with the nav.我在导航部分中有一个 h1。

Below it I have an h2 with a paragraph.在它下面我有一个带有段落的 h2。 I have the h2 and the paragraph in one div and the h1 and navbar in another, but the h1 and h2 are together and will not separate.我在一个 div 中有 h2 和段落,在另一个 div 中有 h1 和导航栏,但是 h1 和 h2 在一起并且不会分开。 If I put a border around the div with the h2 and paragraph tags, the border borders around the h1 and h2.如果我在带有 h2 和段落标签的 div 周围放置一个边框,那么 h1 和 h2 周围的边框边框。 As I have floated the h1 and nav, I have clear: both on the h2 and I've also tried clear:both on the div its in. Nothing is pulling these two elements apart.因为我已经浮动了 h1 和导航,所以我很清楚:在 h2 上,我也尝试过 clear:both 在 div 上。没有什么能把这两个元素分开。 I've also tried a margin on the h2 and it's div.我还尝试了 h2 的边距,它是 div。

HTML: HTML:

<div class="banner">

            <h1>JIMMY DAWSON</h1>


                <ul class="nav">
                    <li><a href="index.html">Home</a></li>
                    <li><a href="thought.html">Thoughts</a></li>
                    <li><a href="#">Visuals</a></li>
                    <li><a href="#">About</a></li>
                </ul>

             </div>

        <div class="journal-section">

        <h2> Headline for the Journal</h2>

            <p> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>

</div>

CSS: CSS:

h2 {
    clear: both; }

.journal-section {
    width: 600px;
    margin: 30px 30px 0 30px;
    border: 1px solid red; }

I have check this codes on my browsers , and i cant find any issues and let me say one thing.我已经在我的browsers上检查了这些代码,但我找不到任何问题,让我说一件事。 when you have work with HTML every section have to be like blocks , that will be avoiding so many issues当您使用HTML每个部分都必须像blocks一样,这将避免很多问题

eg:例如:

you can add float:left;你可以添加float:left; property or display:block;属性或display:block;

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

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