开发者

CSS problem with background-attachment:fixed;

开发者 https://www.devze.com 2023-03-31 03:05 出处:网络
I have a Joomla site that i have created a custom theme. The site is http://esn.teipir.gr/. I have two images right and left that i want them to have background image fixed.

I have a Joomla site that i have created a custom theme. The site is http://esn.teipir.gr/.

I have two images right and left that i want them to have background image fixed.

I use the following CSS rules

开发者_开发技巧div.backgroundboxleft {
    background-attachment: fixed;
    background-image: url("/images/back_1.png");
    float: left;
    height: 822px;
    top: 40px;
    width: 457px;
}

and

div.backgroundboxright {
    background-attachment: fixed;
    background-image: url("/images/back_2.png");
    float: right;
    height: 822px;
    top: 40px;
    width: 457px;
}

If i remove the background-attachment all is OK with the images but when i add with firebug the following code everything messes up.Can you help me making the pages stay fixed without the background color being on top of the image?

Thanks


When you set background-attachment:fixed it fixes the background in relation to the window. So you would then need to adjust the background-position of your images so they appear in the right place. If you replace your backgroundproperties with the css below it will line up properly.

div.backgroundboxleft {
    background-image: url("/images/back_1.png");
    background-attachment: fixed;
    background-position: 0 44px;
    background-repeat: no-repeat;
}

div.backgroundboxright {
    background-image: url("/images/back_2.png");
    background-attachment: fixed;
    background-position: 1323px 44px;
    background-repeat: no-repeat;
}

Live example: http://jsfiddle.net/tw16/6fZ96/embedded/result/

To clarify background-attachment:fixed stops the background from scrolling with the window. So if your viewport is too small and you have to scroll horizontally or vertically the background will not move (i.e. it will be overlapped). More information can be found here.

0

精彩评论

暂无评论...
验证码 换一张
取 消