开发者

Best way to make a feature strip background with CSS?

开发者 https://www.devze.com 2023-04-13 05:46 出处:网络
开发者_StackOverflow中文版I was wondering what would be the best way to create a feature strip of background in a website layout?
开发者_StackOverflow中文版

I was wondering what would be the best way to create a feature strip of background in a website layout?

The approach that comes to mind, would be to create an absolute positioned div with a z-index of -1 and adjust top/height to match up behind a fixed layout.

Is this a good way to go about it? Or is there a better way?

Thank you for any help! :D


A div containing an image placed behind the content is probably the best way to make a scaling background.

I think CSS3 also supports background scaling, but it is not widely supported.


A more semantic approach would be to apply the background strip to an element on the page -- in the case of your example, the "slideshow" element. This element's outer constraint (whether that be a div, a ul, or something else) can then be stretched to 100% of the width of the page, and the content of the element centered (or positioned as desired).

This approach would be more maintainable than some other approaches -- content could be added before the element without breaking the layout, the strip could be changed without much effort, etc.

Background scaling could be taken care of in several ways:

  1. Make your background big enough that it isn't likely to ever be a problem.
  2. Use a tile-able background.
  3. Use CSS3 background-size property. A jsfiddle example is here. (Not supported in <=IE8, but with a little creativity could degrade gracefully.)
  4. Put the image inside your div (or similar) and then use CSS to position absolutely, set the z-index to force below the content, and stretch the image to the width and height of the element. Here's a jsfiddle example. (Note: UNSEMANTIC! Reduces maintainability, etc. But does have better support than CSS3 background-size...)


Number of websites "cheat" : the site's background image already have the strip on it

It's simple and painless but it's static.

0

精彩评论

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