css - 我想让DIV里面的背景固定,只有内容随滚动移动,怎么办?

标签 css html background styling

正如我已经提到的,我希望我的背景固定在它的 DIV 中,并且只有要滚动的内容。 我的问题是,每当我将背景属性设置为固定时,背景似乎从页面的开头(0-top)开始,尽管我只将它设置为 div。在我开始向下滚动之前,它不会被修复。

#elections_top
{
    position: relative;
    width: 890px;
    height: auto;
    direction: rtl;
}

#elections_top .elections_news
{
    position: relative;
    width: 890px;
    height: auto;
    padding-bottom: 90px;
    background: url("../images/coca_cola_bg.jpg") #e01b22;
    background-repeat: no-repeat;   
    background-attachment:fixed;
    background-position:50% top; 
}

elections_news 是相对于 elections_top 的,它出现在站点中的标题之后,背景不知何故似乎是从标题开始放置的

最佳答案

尝试移除background-attachment:fixed;

关于css - 我想让DIV里面的背景固定,只有内容随滚动移动,怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16997888/

相关文章:

css - 与 Material-UI 1 Grid 相同宽度的列

Css 悬停更改子背景

Android:为什么我的按钮不填充父级?

JavaScript 背景图像被 $(document).ready 破坏

html - 如何使图片的背景文字居中

html - CSS-边距底部不起作用

css - Wordpress 子主题 CSS 排队

html - CSS :checked - change id's background color

html - 我可以从哪里访问我的 netlify.toml 文件?

html - 将显示值从 block 更改为内联 block 时继承的文本缩进值行为