css - 使用 CSS 创建固定背景图像

标签 css

我无法创建固定位置的背景图像(灰色矩形)。 .当我向下滚动页面时,图像继续随页面滚动,而不是像图像那样保持静止。

此灰色背景图像仅用于创建左侧导航的轮廓。

body.ms-backgroundImage {
    background: url(../LandingPage/LAIPic1.png);
    background-size: 250px 455px;
    background-position: 8px 280px;
    background-attachment: fixed;
    background-repeat: no-repeat;
}

How the background image is before the page is scrolled down

While the page is scrolled down, the gray background image also scrolls.

最佳答案

要让菜单像那样位于页面的一侧,您需要使用 css 属性 position: absolute;。然后将其放置在您想要使用的位置 top: 100px; left:10px; 使用您想要的任何值。

使用它,您可以将它放在页面上您想要的位置,并且无论您何时滚动,它都应该留在原处。您可以将它放入页面上的脚本编辑器中(如果您只需要它)或放在样式库中的文件中并在母版页中引用它。

关于css - 使用 CSS 创建固定背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27840256/

相关文章:

javascript - 为什么不能创建box元素?

html - 表格在 Div 中的响应式设计

jquery - Div 在 JQuery 中被下推

css - 溢出-y 滚动 div 裁剪嵌套 div

css - 100% div(DIV 顶部有 10px 边距)

css - child 在整个文档中选择

html - Flexbox 需要在 IE 11 中溢出

html - 在 IE11 中将响应页面宽度从 640px 调整为 1117px 会导致对齐不正确

javascript - 如何将 JavaScript 函数应用于同一类下的多个不同元素(结果不同)?

css - 如何从 GitHub 以不同的权重显示 Noto Sans?