h2不会与它上面的h1分开

时间:2016-09-17 13:34:00

标签: html css

我在带导航的部分中有一个h1。

在它下面我有一个带有段落的h2。我在一个div中有h2和段落,在另一个div中有h1和navbar,但是h1和h2在一起并且不会分开。如果我使用h2和段落标记在div周围放置边框,则边框与h1和h2相邻。当我已经漂浮了h1和导航时,我已经清楚了:在h2和我都尝试过清楚:两者都在div上。没有什么能将这两个元素分开。我也尝试了h2的余量,这是div。

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:

h2 {
    clear: both; }

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

1 个答案:

答案 0 :(得分:1)

我已在browsers检查此代码,我无法找到任何问题,让我说一件事。当您使用HTML工作时,每个部分都必须像blocks一样,这将避免这么多问题

例如:

您可以添加float:left;属性或display:block;