简体   繁体   English

3种不同的CSS背景

[英]3 different backgrounds with CSS

I'm wondering if the following is possible with CSS. 我想知道CSS是否可以实现以下功能。

I'd like there to be 3 horizontal bars running across the entire width of a background. 我希望在整个背景宽度上有3个水平条。 Here's a rough mockup of what I would like the background to be 这是我想要背景的粗略模型 在此处输入图片说明

I've been toying with the following but I can't seem to be able to position any of the backgrounds. 我一直在研究以下内容,但似乎无法定位任何背景。

#blog {
width: 1200px;
height: 100%;
background-image: url("bg1.png"),
          url("bg2.png"), 
          url("bg3.png");
background-position: 10px 10px,
          170px 10px, 
          750px 10px;
background-repeat:repeat-x;
}

Here's a fiddle: http://jsfiddle.net/5fo054L2/1/ 这是一个小提琴: http : //jsfiddle.net/5fo054L2/1/

Any idea what I'm doing wrong? 知道我在做什么错吗?

You almost have it. 您几乎拥有它。 The issue is that you have the x and y position confused. 问题是您对x和y位置感到困惑。 Also, x position doesn't have any meaning if it repeats. 另外,如果重复x位置,则没有任何意义。

 .blog { width: 100%; height: 100%; background-image: url("http://i.imgur.com/L3F9slr.png"), url("http://i.imgur.com/rmPDxMq.png"), url("http://i.imgur.com/9MMzDMs.png"); background-position: 0px 170px, 0px 100px, 0px 10px; background-repeat: repeat-x; } 

Here is an updated jsfiddle: http://jsfiddle.net/5fo054L2/3/ 这是更新的jsfiddle: http : //jsfiddle.net/5fo054L2/3/

Note that the vertical height (of text in your example) will limit the amount of the background images you see. 请注意,(示例中的文本的)垂直高度将限制您看到的背景图像的数量。

您还可以制作三个图像文件,将它们放置在其他所有文件之下,并使用绝对定位进行设置。

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

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