background-image大小和位置的设置

 1、background-position: 当背景图很大时,可以让其固定显示在不同的位置。剩下的会隐藏。

  引入背景图片:background-image: url("img/banner.jpg");

background-position参数:

  •   水平起始位置(left center right %)可以用这四种形式的任意一种
  •   垂直起始位置(top center bottom %)可以用这四种形式的任意一种

实例:

1 background-position: right top;、、、、、、值的顺序没有关系
2 
3 background-position: 40% center;、、、、、、、、百分比表示从图的左边向右边的百分之多少开始显示。
4 
5 background-position: right;、、、、一个值表示从right边的图的中间开始显示

 

 2、background-attachment: fixed

    固定定位相当于position:fixed

作用:用于固定背景图

background-attachment: fixed; 必须是背景图达到产生滚动条才会看到他的效果,否则不会起作用的

posted @ 2017-12-04 21:25  蓝心高飛  阅读(16634)  评论(0编辑  收藏  举报