css背景位置(position)详解

css背景位置(position)详解

前端知识qingyu2020-11-13 7:05:251509A+A-

  css背景位置(position)详解

  语法:

  background-position : length || length

  background-postiton: position || position

  length:百分数|由浮点数字和单位标识符 组成的长度值

  positon  :top | center| bottom | left | center |right 方位名词

  注意:

  必须指定backgroud-image属性

  postion后面是X坐标和y坐标,可以使用方位名词或者精确单位

  如果只指定了一个方位名词,另一个值默认居中对齐,为50%

  如果只指定了一个数值,那该数值用于X坐标,另一个默认是y坐标,默认居中

  如果是精确坐标,第一个是x坐标第二个是y坐标。

  如果指定了两个值,两个值都是方位名词,则两个词顺序无关,比如left top  和top left效果一样。

  如果指定了两个值,精确单位和方位名字混合使用,则第一个值是x坐标,第二个值是y坐标。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			div {
				width: 600px;
				height: 300px;
				background-color: pink;
				background-image: url(images/ldh.jpg);
				background-repeat: no-repeat;
				/*左上角*/
				background-position: left top;
				/*水平垂直居中*/
				background-position: center center;
				/*距离左10px 距离上50px*/
				background-position: 10px 50px;
				/*x坐标10px 垂直居中*/
				background-position: 10px;

			}
		</style>
	</head>
	<body>
	</body>
	<div>
	</div>
</html>


点击这里复制本文地址 欢迎来到大黄鸡源码分享网
qrcode

大黄鸡源码编程网 © All Rights Reserved.  
网站备案号:闽ICP备18012015号-4
Powered by Z-BlogPHP
联系我们| 关于我们| 广告联系| 网站管理