css background-size与背景图片填满div
background-size与背景图片填满div
在开发中,常有需要将一张图片作为一个div的背景图片充满div的需求
background-size的取值及解释
background-size共有三种属性,分别为
background-size: cover
MDN文档解释说明:缩放背景图片以完全覆盖背景区,可能背景图片部分看不见。A keyword that is the inverse of contain. Scales the image as large as possible and
maintains image aspect ratio(image doesn't get squished). The image "covers" the entire width or height of the container. When the image and container have different dimensions,the image is clipped either left/right or top/bottom.
这里的关键说明在于标红的两个区域,分别是它会保持图片的宽高比和当图像和容器具有不同的尺寸时,图像被左/右或顶部/底部裁剪。之后会结合例子说明
background-size: contain
MDN文档解释说明:缩放背景图片以完全装入背景区,可能背景区部分空白。A keyword that scales the image as large as possible and
maintains image aspect ratio(image doesn't get squished). Image is letterboxed within the container. www.97yingyuan.org When the image and container have different dimensions,the empty areas (either top/bottom of left/right) are filled with the background-color.
这里的关键说明在于标红的两个区域,分别是它会保持图片的宽高比和当图像和容器具有不同的尺寸时,空区域(左/右/上/右)填充背景色。之后会结合例子说明
background-size: width-value,height-value;
分为固定大小和百分比和auto,固定大小就是写死;auto就是以背景图片的比例缩放背景图片。。
百分比的的MDN文档解释说明<percentage> 值,指定背景图片相对
背景区(background positioning area)的百分比。背景区由background-origin设置,默认为盒模型的内容区与内边距,也可设置为只有内容区,或者还包括边框。如果attachment 为fixed,背景区为浏览器可视区(即视口),不包括滚动条。不能为负值。
css background-size与背景图片填满div的更多相关文章
- 设置div背景图片填满div
可以设置div的样式为 background:url('+UPLOAD_PATH+data.url+') no-repeat; background-size: 100%;width:100%;hei ...
- IE9以下通过css让html页面背景图片铺满整个屏幕
第一种方法不设为背景图片,通过css来控制样式,可兼容到IE6,代码如下: <!DOCTYPE html> <html lang="en"> <hea ...
- css文件 如何使背景图片大小适应div的大小
对背景图片设置属性:background-size:cover;可以实现背景图片适应div的大小. background-size有3个属性: auto:当使用该属性的时候,背景图片将保持100% 的 ...
- css网页中设置背景图片的方法详解
在css代码中设置背景图片的方法,包括背景图片.背景重复.背景固定.背景定位等 用css设置网页中的背景图片,主要有如下几个属性: 1,背景颜色 {">说明:参数取值和颜色属性一样 ...
- ExtJS-Viewport背景图片铺满浏览器视图并自动伸缩
var viewport = Ext.create('Ext.container.Viewport', { style : 'background-image:url(login_bj.jpg);ba ...
- css圆,背景,img填满等样式
background 属性 属性值 描述 background-color 单词颜色表示法.rgb.十六进制 设置元素的背景颜色 background-image url('http://www.aa ...
- CSS hack前传——背景图片全屏
在之前的博客CSS hack中我有提到,一个问题的解决让我对CSS hack的态度从不屑一顾,到认真研究了实验一下,事情是这样的,最近产品发布,向来狂妄的我被一个bug纠缠住了,甚至丧气的表示我做不出 ...
- 【CSS学习笔记】背景图片
直接看代码: background: blue; /*页面背景为蓝色,很简单的代码*/background-image:url(small.jpg); /*页面背景是名字叫small.jpg的图片*/ ...
- CSS background-color 、image 背景图片
背景颜色 background-color 语法: background-color:<color> 默认值:transparent 透明 适用于:所有元素 继承性:无 动画性:是 计算 ...
随机推荐
- python导入其他文件夹下的.py文件
想在globalpararm中导入read_config中的类 import sys sys.path.append('..') from common.read_config import Read ...
- python_1_变量的使用
print("hello word") name="Qi Zhiguang" print("My name is",name) name2= ...
- 高亮代码 SyntaxHighlighter
SyntaxHighlighter: http://alexgorbatchev.com/SyntaxHighlighter/download/ demo <!DOCTYPE html PUBL ...
- c/c++基础
如果有你认为重要的知识点,而我这却没有记录下来的,那么期待你分享给我(^U^)ノ~YO. 1.在结构体中,符号->的前面是指针变量,符号.的前面是普通变量. 程序中a->b等价于(*a ...
- django中的auth模块以及分页器
1.auth模块 auth模块是Django提供的标准权限管理系统,可以提供用户身份认证,和权限管理 auth可以和admin模块配合使用, 快速建立网站的管理系统 在INSTALLED_APPS中添 ...
- iOS 蓝牙(GameKit CoreBluetooth)
利用GameKit框架实现ios设备的蓝牙通讯,导入框架:#import <GameKit/GameKit.h> , 注意: 此框架只能用于ios设置间蓝牙通讯 如今苹果开放了接口来实现 ...
- POJ1286 Necklace of Beads(Polya定理)
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9359 Accepted: 3862 Description Beads ...
- UVA_10139
The factorial function, n! is defined thus for n a non-negative integer:0! = 1 n! = n×(n−1)! (n > ...
- 懒下载软件,一行代码连接wifi^_^
按键盘的windows+R,输入cmd,回车键 设置语句netsh wlan set hostednetwork mode=allow ssid=user key=possword 按回车键 启动语句 ...
- 深入理解restfulAPI和 Oauth2.0(精简版)
一.restfulAPI 1.解释: restfulAPI协议,我们也可以说是一套API接口编写风格. 它被现在很多企业所认可和默认,是一套成俗的API接口编写方案. 2.restfulAPI之资源 ...