css如何设置banner图自适应


本文摘自PHP中文网,作者醉折花枝作酒筹,侵删。

在css中,可以使用“background-size”设置banner图自适应,语法“background-size:cover”;其中cover是指把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

1

2

3

4

5

6

7

8

9

10

11

12

13

//test.css

.index-banner-top {

    width: 100%;

    background: url(../imgs/guanyu.png) no-repeat center center;

    height: 210px;

    background-size:cover

}

@media only screen and (max-width: 640px){

 

    .index-banner-top {

        height: 100px;

    }

}

1

2

//test.html

<p class="index-banner-top"></p>

电脑端显示:

阅读剩余部分

相关阅读 >>

如何使用css解决浮动元素父元素的高度塌陷问题?(代码示例)

css怎么设置fontfamily

css border-color属性怎么用?

css怎么用id进行定位

css如何实现水平居中

响应式css前端框架有哪些

css样式的注释怎么写

css中大于符号是什么意思

css中relative的用法是什么

css如何隐藏标签

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...