Anchoring CSS Repeating Background Image

时间秒杀一切 提交于 2019-12-05 19:57:58

You can do this with a single styled element, yes:

#banner {
  height: 50px;
  width: 50%; margin: 0; padding-right: 50%;
  background-image:url('banner.png'), url('left-bg.png'), url('right-bg.png');
  background-clip: padding-box, content-box, content-box;  
  -webkit-background-clip: padding-box, content-box, padding-box; 
  background-origin: padding-box, content-box, padding-box;
  background-position: center, right, center;
  background-repeat: no-repeat, repeat-x, repeat-x;
}

The element has three backgrounds. The trick is in getting different ones to appear on the left and right, which I've done by adding 50% padding on the left. The left hand side is "padding box" and the right is "content box".

You might want to make the first background an <img> so you can give it a title tag -- if you do then it'll appear only in the right-hand 50% of the window so you'll have to left align it and use position:relative; left:-250px to get it back into the middle.

Lastly, the background images are locked to the middle of the window, not the edge of the banner, but you can fix that by changing the images themselves.

Can you provide a URL to check the site? It sounds like you'll need to experiment with the css property:

background-position {x, y}
banner
{
background-image:url('image.gif');
background-repeat:repeat-x;
vertical-align: middle;
text-align: center; /*optional*/
}

i don't know if this works, but it's worth a try.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!