简体   繁体   English

增加位置:固定 破坏标题

[英]Adding Position: fixed; ruins the header

When I add: 当我添加:

* {
    margin: 0;
    padding: 0;
    position: fixed;
}

the whole banner messes up and ends with a piece of the code. 整个横幅乱七八糟,并以一段代码结尾。 I've been experimenting on popular websites, and when this one came along I've been having a lot of trouble. 我一直在流行的网站上进行实验,当这个网站出现时,我遇到了很多麻烦。

How do I make it so the position: fixed; 我如何做到这一点position: fixed; doesn't ruin it? 不毁了吗?

Wooahh you've added position fixed onto every single element of the page with this line: 哇,您已经在此行中添加了固定在页面每个元素上的位置:

* {
    margin: 0;
    padding: 0;
    position: fixed;
}

You should only add position fixed to the element you want to be fixed. 您只应在要固定的元素上添加固定的位置。 If its the top nav then something like this. 如果它是顶级导航,则类似这样。

nav#top {
  position: fixed;
}

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

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