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; 必须是背景图达到产生滚动条才会看到他的效果,否则不会起作用的

原文地址:https://www.cnblogs.com/hlrblog/p/7979066.html