background-size设置背景图像的尺寸大小

珠峰HTML|CSS精讲视频 admin 485浏览

background-size设置对象的背景图像的尺寸大小

  1. <length>用长度值指定背景图像大小,不允许负值;=>background-size:X轴尺寸大小 Y轴尺寸大小
  2. <percentage>用百分比指定背景图像大小,不允许负值;
  3. auto背景图像的真实大小;
  4. cover将背景图像等比缩放到完全覆盖容器,背景图像有可能超出容器;
  5. contain将背景图像等比缩放到宽度或高度与容器的宽度或高度相等,背景图像始终被包含在容器内;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.pic{
width: 2400px;
height: 1600px;
background: url(https://mobike.com/cn/assets/themes/moby/img/landing/hero-bg-4.jpg) no-repeat;
/* background-size: 500px 500px; */
background-size: 50% 50%;
}
</style>
</head>
<body>
<div class="pic"></div>
</body>
</html>

转载请注明:大灰牛博客 » background-size设置背景图像的尺寸大小