如何使用css background-position属性
本篇文章给大家分享的是有关如何使用css background-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 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>
以上就是如何使用css background-position属性,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。