简体   繁体   English

div 的 CSS 背景图像底部

[英]CSS background-image bottom of div

Here's what I have:这是我所拥有的:

<div id="page_container">
    A short text
</div>

#page_container
{
    position: absolute;
    top: 120px;
    left: 280px;
    right: 30px;
    background-color: #D0D0CD;
    border-radius: 5px;
    box-shadow: 1px 1px 12px #555;
    height: 1060px;
    overflow: auto;
    background-image: url(./library/grappe.png);
    background-repeat: no-repeat;
    background-position: bottom right;
}

So, my div is 1060px, on the right of my screen, and has an image on the right bottom corner.所以,我的 div 是 1060px,在我的屏幕右侧,并且在右下角有一个图像。 So far so right.到目前为止是正确的。 Nice looking with a short text.短文好看。

Due to the overflow: auto, a long text won't make my div higher, but add a scrollbar to it, that's what I want.由于溢出:自动,长文本不会使我的 div 更高,而是为其添加滚动条,这就是我想要的。

However, the background-image stays glued to the div right bottom corner, instead of basically not showing and first show when I scroll down the div that has a scrollbar.但是,背景图像仍然粘在 div 的右下角,而不是在我向下滚动具有滚动条的 div 时基本上不显示并首先显示。 Basically the image stays on the same position, like a position: fixed .基本上图像保持在相同的位置,就像一个position: fixed Can't get to change that behavior.无法改变这种行为。

You need to add an inner div, and that inner div will have the background while the first one will handle the scrolling.您需要添加一个内部 div,该内部 div 将具有背景,而第一个将处理滚动。

<div id="page_container">
    <div class="block_container">
        A short text
    </div>
</div>

CSS part CSS 部分

#page_container
{
    position: absolute;
    top: 120px;
    left: 280px;
    right: 30px;
    border-radius: 5px;
    box-shadow: 1px 1px 12px #555;
    height: 1060px;
    overflow: auto;
}

#page_container .block_container
{
    background: #D0D0CD url('./library/grappe.png') bottom right no-repeat;
}

I manage to make it work without having to have another div there.我设法让它工作,而不必在那里有另一个 div。

#page_container {
  background: url('IMAGE_URL') no-repeat bottom right, linear-gradient(315deg, #0F3052 0%, #11A0B0 100%);
  background-size: contain;
}

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

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