设置标题中h1元素的上边距不能按预期工作 [英] setting the top margin of the h1 element in the header does not work as expected

查看:161
本文介绍了设置标题中h1元素的上边距不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了html5标题标签和一个h1标签。在我的标题中将h1元素的top margin属性设置为0px后,我设法删除了标题的顶部边界,但是我想让标题中的h1元素具有大约15px的顶部边距。



现在,当我尝试设置h1元素的顶部边距时,它也为头部创建了一个我不想要的顶部边距。



有人可以帮我解决这个问题吗?

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =utf-8>
< link href =normalize.css =stylesheet>
< link href =style.css =stylesheet>

< title>代号:ENT< / title>
< / head>
< body>
< header>
< h1>网站标题/ LOGO< / h1>
< p>网站标语/标语/一个班轮。< / p>
< p>< / p>
< nav>< / nav>
< / header>
< div id =content_wrapper>< / div>
< footer>
< / footer>
< / body>
< / html>

和CSS

  header {
background-color:#ff0
}

header h1 {
margin-top:0;
保证金余额:15px
}

标题p {
保证金余额:15px
}

解决方案

使用 padding-top c> h1 或标题或使用 overflow:hidden


I have made use of the html5 header tag and an h1 tag within it. After setting up the top margin property of the h1 element in my header to 0px, i manage to remove the top margin of the header, but i want the h1 element inside my header to have a top margin of around 15px.

Now when i try setting the top margin of the h1 element, it also creates a top margin for the header which i don't want.

Can someone help me out with this...?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <link href="normalize.css" rel="stylesheet">
    <link href="style.css" rel="stylesheet">

    <title>Codename : ENT</title>
</head>
<body>
    <header>
        <h1>Site Title / LOGO</h1>
        <p>Site Tagline / Slogan / One liner.</p>
        <p></p>
        <nav></nav>
    </header>
    <div id="content_wrapper"></div>
    <footer>
    </footer>
</body>
</html>  

and CSS

header {
    background-color:#ff0
}

header h1 {
    margin-top:0;
    margin-left:15px
}

header p {
    margin-left:15px
}

解决方案

Use padding-top for h1 or header or use overflow:hidden for header

这篇关于设置标题中h1元素的上边距不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆