您好,欢迎来到百万美食网。
搜索
您的当前位置:首页cssbackground-position属性怎么用

cssbackground-position属性怎么用

来源:百万美食网
 background-position属性用于设置背景图像的起始位置的。语法为background-position: x y,其中x表示水平位置,y表示垂直位置;x和y有多种赋值方式,例:top left,3% 2%,xpos ypos。

css background-position属性怎么用?

background-position属性可以设置背景图像的起始位置。

语法:

background-position: x y

可以设置的值:


描述
left top
left center
left bottom
right top
right center
right bottom
center top
center center
center bottom
如果仅指定一个关键字,其他值将会是"center"
x% y%第一个值是水平位置,第二个值是垂直。左上角是0%0%。右下角是100%100%。如果仅指定了一个值,其他值将是50%。 。默认值为:0%0%
xpos ypos第一个值是水平位置,第二个值是垂直。左上角是0。单位可以是像素(0px0px)或任何其他 CSS单位。如果仅指定了一个值,其他值将是50%。你可以混合使用%和positions

说明:这个属性设置背景原图像(由 background-image 定义)的位置,背景图像如果要重复,将从这一点开始。

注释:您需要把 background-attachment 属性设置为 "fixed",才能保证该属性在 Firefox 和 Opera 中正常工作。

css background-position属性 示例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<style type="text/css">
body
{ 
 background-image:url('https://img.php.cn/upload/article/000/005/656/5af270fd37755429.jpg');
 background-repeat:no-repeat;
 background-attachment:fixed;
 background-position:center;
}
</style>
</head>
<body>
<body>
<p><b>提示:</b>您需要把 background-attachment 属性设置为 "fixed",才能保证该属性在 Firefox 和 Opera 中正常工作。</p>
</body>
</body>
</html>

Copyright © 2019- bwgh.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务