Body top gap; should I use margin or padding?

亡梦爱人 提交于 2020-01-07 03:57:12

问题


So, I'm working on a website with a fixed header (which is used to navigate).
I use padding-top on body to lower the content to fit with the header.

This is how it looks like right now:

body
{
    background-color: red; 
    padding-top: 50px;
}
.header {
    background-color: yellow;
    position: fixed;
    width: 100%;
    height: 50px;
    top: 0;
    left: 0;
}
<div class="header">
    Header
</div>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr.<br>
Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

My question is: What would be better to use in this situation? margin-top or padding-top?


回答1:


There's no actual better way to do it. It's just to you. Maybe one will be slightly faster to render then another but nothing that someone could notice.

As a tip anyway is to make the header positioned as fixed so it scrolls down with the user.



来源:https://stackoverflow.com/questions/30984776/body-top-gap-should-i-use-margin-or-padding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!