【问题标题】:How do I make my title stick to the top, while the other contents go under the title and doesn't interfere with it如何让我的标题保持在顶部,而其他内容位于标题下方并且不干扰它
【发布时间】:2022-11-30 17:18:46
【问题描述】:
this is my code right now

#h1{
    font-family: 'open-sans';
    position: absolute;
    color: white;
    font-size: 16px;
    left: 850px;
    margin-top: 5px;
    position: fixed;
}

没有任何效果我在痛苦中也尝试使用位置粘性但它没有用

【问题讨论】:

  • 目前还不清楚想要在那里实现什么。请添加结果截图和所需的功能

标签: html css title


【解决方案1】:

您应该删除position: absolute;,只保留position: fixed;

h1{
position: fixed;
font-family: 'open-sans';
color: white;
font-size: 16px;
background-color: black;
top: 0;}

希望有所帮助。 您也可以使用background-color 使其看起来正确。

【讨论】:

    【解决方案2】:

    兄弟只使用一个位置属性,你在样式中使用两个。只需应用三个属性,例如:

    .element {
        position: fixed; 
        top: 0; 
        left: 0;
        width 100%
    }
    

    【讨论】:

      【解决方案3】:

      您可以使用position:stickyposition: fixed 而不是position: absolute https://www.w3schools.com/howto/howto_css_sticky_element.asp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-04
        • 2017-07-05
        • 1970-01-01
        • 2021-04-24
        • 1970-01-01
        • 1970-01-01
        • 2020-03-12
        • 2020-01-20
        相关资源
        最近更新 更多