开发者

CSS background image and box width (%)

开发者 https://www.devze.com 2023-02-08 02:49 出处:网络
My layout uses percent values in the boxes. For example: h2#news { background: url(\'../images/news-background.jpg\');

My layout uses percent values in the boxes. For example:

h2#news {
    background: url('../images/news-background.jpg');
    color: #fff;
    padding: 8px 20px;
    width: 90%;
    -moz-border-radius: 20px;
}

It's ok, but when layout increases, background images repeat... look at this image: http://img821.imageshack.开发者_如何学Pythonus/img821/3503/cssbgandpercent.jpg

Is there a way to background image follow the size of the box? Thank you.


You can add no-repeat to the background to make it stop early.

You can add the CSS3 property background-size: auto 100%; to stretch the background to fit.
You should also add -moz-background-size and -webkit-background-size, with the same value.

0

精彩评论

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