简体   繁体   English

一起使用背景重复和背景位置

[英]Using background-repeat and background-position together

I'm trying to implement a faux column layout on a website. 我正在尝试在网站上实现人造列布局。 Briefly, it involves tiling a background image on the div that holds both the vertical columns to make it look like both columns extend all the way to the bottom. 简要地说,它涉及在div上平铺一个背景图像,该背景图像包含两个垂直列,以使其看起来像两个列都一直延伸到底部。

My columns look like this: 我的专栏看起来像这样:

XXXX   MMMM
XXXX   MMMM
XXXX
XXXX   YYYY
XXXX   YYYY
XXXX   YYYY
XXXX   YYYY
XXXX   YYYY

With a column on the left that goes all the way down the page, but with menus and transparency and stuff ("M") at the top of the right column. 左侧有一列,一直向下延伸到页面的最下端,但菜单和透明度以及东西(“ M”)位于右列的顶部。 I only want the faux column background to start once the real right column starts ("Y"), and to ignore everything above that due to the transparency between the menu and Y-column. 我只希望人造列的背景在最右边的列开始时才开始(“ Y”),并且由于菜单和Y列之间的透明性而忽略了高于该列的所有内容。

To do that, I was planning on offsetting the background image via (background-position: 0px 200px) to drop the image down 200 pixels. 为此,我计划通过(background-position:0px 200px)将背景图像偏移到200像素以下。 This doesn't work. 这行不通。

I quickly realized that the image is repeating in BOTH directions vertically. 我很快意识到图像在两个方向上都是垂直重复的 Up and down from that original offset point. 从原始偏移点上下移动。 This obviously undoes the effects of the offset. 显然,这抵消了偏移的影响。 But the background-repeat-Y is needed for faux columns to work. 但是要使伪列正常工作,需要使用background-repeat-Y。

How can I use both background-repeat and background-position together to get the layout I want? 如何同时使用背景重复和背景位置来获得所需的布局?

Thanks! 谢谢!

UPDATE TO CLARIFY: 更新说明:

Here's my layout: 这是我的布局:

alt text http://img38.imageshack.us/img38/3032/colorlayout.jpg 替代文字http://img38.imageshack.us/img38/3032/colorlayout.jpg

Ideally, the green wouldn't be there and I could use an "orange - transparent - pink" image to do the faux columns for the entire columns. 理想情况下,绿色将不存在,我可以使用“橙色-透明-粉色”图像为整个列创建人造列。 But if I did that now, the green menu would have a pink background due to that (really stupid, by the way) CSS repeat glitch. 但是,如果我现在这样做的话,由于CSS重复故障(顺便说来,这真是愚蠢),绿色菜单的背景将变成粉红色。 And I could do the green menu's transparent background as a transparent png, but I don't want that being repeated throughout the pink column. 我可以将绿色菜单的透明背景设置为透明png,但是我不希望在整个粉红色列中重复这种操作。 The site's background is an image so I can't just make the green menu's div have a certain color background. 该网站的背景是图片,因此我不能仅使绿色菜单的div具有特定的颜色背景。

Seems to be a lose-lose situation. 似乎是一种双输的情况。

It's not possible to make a background start repeating from a specific position. 不可能使背景从特定位置开始重复。

In your case one of the solutions would be to use a faux-columns in your whole page (starting from the top) and then use PNG transparency for your MMMM menu. 在您的情况下,一种解决方案是在整个页面中使用人造列(从顶部开始),然后对MMMM菜单使用PNG透明度。 Then you can degrade gracefully for IE and older browsers. 然后,您可以优雅地降级IE和旧版浏览器。

But I'm not sure I understand your question very well. 但是我不确定我是否很好地理解了你的问题。

If the problem is that the YYYY column shouldn't be displayed above (where the MMMM is for example), then you can still use that faux-column thing and then wrap your MMMM menu and everything above YYYY in a div with a different beackground. 如果问题是YYYY列不应该显示在上方(例如MMMM),那么您仍然可以使用该伪列内容,然后将MMMM菜单和YYYY上方的所有内容包装在具有不同beackground的div中。 This way it would hide your faux-column above YYYY. 这样,它将把您的人造列隐藏在YYYY上方。

Again, it's hard to help without seeing the actual design. 同样,在没有看到实际设计的情况下很难提供帮助。

UPDATE: 更新:

This seems pretty hard to achieve with CSS only (I'm not sure it's even possible). 仅使用CSS似乎很难做到这一点(我不确定这是否可能)。 There are a lot of solutions out there to equalize heights using javascript. 有很多解决方案可以使用javascript来使高度相等。 See: http://spindrop.us/2007/05/22/equal-height-columns-with-jquery/ 参见: http : //spindrop.us/2007/05/22/equal-height-columns-with-jquery/

UPDATE 2: 更新2:

Actually, if the XXXX part of your site stays at the same place all the time, you can fake the transparency and display a background-image corresponding exactly to the part of the actual background it is hiding. 实际上,如果您网站的XXXX部分始终保持在同一位置,则您可以伪造透明度并显示与隐藏的实际背景部分完全对应的背景图像。 I've done that many times. 我已经做了很多次了。

As far as I can see, you have two possibilities here: 据我所知,这里有两种可能性:

  1. Give the MMMM part of the right column a solid background color. 为右列的MMMM部分提供纯色背景色。 Then it overlays the fake columns 然后覆盖假列

  2. Set the background image not to the container but to the YYYY and XXXX columns: 将背景图像设置为不设置为容器,而是设置为YYYY和XXXX列:


#XXXXcol {
  background: url(fake.png) repeat-y left top;
}

#YYYYcol {
  background: url(fake.png) repeat-y right top;
}

Note the "right" and "left" parts. 请注意“右”和“左”部分。

You could split the XXXX section into two parts (fixed size): 您可以将XXXX部分分为两部分(固定大小):

XXXX   MMMM
XXXX   MMMM
XXXX

And (vertical repeat of XXXX YYYY): 并且(XXXX YYYY的垂直重复):

XXXX   YYYY
XXXX   YYYY
XXXX   YYYY
XXXX   YYYY
XXXX   YYYY
...

To position the background correctly you can manipulate the container (probably a div) that has the background-image applied to it. 要正确定位背景,您可以操作应用了背景图片的容器(可能是div)。

I don´t know how your columns are positioned, but perhaps it would be possible to use your main background image (the site's background) as the background for the menu that is now green. 我不知道您的栏的位置,但是也许可以将您的主要背景图像(网站的背景)用作现在绿色的菜单的背景。

Or use an absolutely positioned div in z-index between your menu and your right column to "overwrite" your purple background. 或在菜单和右列之间的z-index中使用绝对定位的div,以“覆盖”紫色背景。 You could center that and put it behind your left column as well in case your lay-out is centered and the first solution is impossible. 您可以将其居中,然后将其放在左列后面,以防布局居中且无法采用第一个解决方案。

Another solution would be to use javascript to set the height of your two main columns to have them go all the way down, but I would try css first... 另一个解决方案是使用javascript设置两个主列的高度,以使它们一直向下移动,但是我会首先尝试使用CSS ...

I found an alternative to faux columns that works in this case: 我发现在这种情况下可以使用的人造列替代方法:

http://www.positioniseverything.net/articles/onetruelayout/equalheight http://www.positioniseverything.net/articles/onetruelayout/equalheight

Basically: 基本上:

#page {
    overflow: hidden

#orange, #pink {
    padding-bottom: 32767px;
    margin-bottom: -32767px;
}

Thanks everyone! 感谢大家!

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

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