zoukankan      html  css  js  c++  java
  • CSS背景属性

    CSS背景属性

    1、background-attachment 属性

      scroll:默认值。背景图像会随着页面其余部分的滚动而移动。

      fixed:当页面的其余部分滚动时,背景图像不会移动。

      inherit:规定应该从父元素继承 background-attachment 属性的设置。

    body 
      { 
      background-image: url(bgimage.gif); 
      background-attachment: fixed;
      }

    2、background-clip 属性

      border-box:背景被裁剪到边框盒。

      padding-box:背景被裁剪到内边距框。

      content-box:背景被裁剪到内容框。

    div
    {
    background-color:yellow;
    background-clip:content-box;
    }

    3、background-origin 属性

      border-box:背景图像相对于边框盒来定位。

      padding-box:背景图像相对于内边距框来定位。

      content-box:背景图像相对于内容框来定位。

    div
    {
    background-image:url('smiley.gif');
    background-repeat:no-repeat;
    background-position:left;
    background-origin:content-box;
    }

    4、background-size 属性

      length
      设置背景图像的高度和宽度。
      第一个值设置宽度,第二个值设置高度。
      如果只设置一个值,则第二个值会被设置为 "auto"。
      percentage
      以父元素的百分比来设置背景图像的宽度和高度。
      第一个值设置宽度,第二个值设置高度。
      如果只设置一个值,则第二个值会被设置为 "auto"。
      cover
      把背景图像扩展至足够大,以使背景图像完全覆盖背景区域。
      背景图像的某些部分也许无法显示在背景定位区域中。
      contain

      把图像图像扩展至最大尺寸,以使其宽度和高度完全适应内容区域。 

    div
    {
    background:url(img_flwr.gif);
    background-size:80px 60px;
    background-repeat:no-repeat;
    }

     例子1:

     500px;
    height: 500px;
    border: 15px double #0000ff;
    padding: 20px;
    background: #f0f url("img/panda.jpg") no-repeat;
    background-clip: border-box;
    background-origin: border-box;
    background-size: 100%;

    如图:

    例子2:

     500px;
    height: 500px;
    border: 15px double #0000ff;
    padding: 20px;
    background: #f0f url("img/panda.jpg") no-repeat;
    background-clip: padding-box;
    background-origin: content-box;
    background-size: 100%;

    如图:

    如果 background-attachment 设置了 fixed 属性,则设置 background-origin 无效果。

  • 相关阅读:
    Hello iOS
    钝化程序、逻辑冻结、冻结程序的延续、瞬间转移
    对字符串操作的各种笔试题
    .NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)
    多线程计算----pthread
    Xcode的Hello World(简单易懂)
    two sets of Qt binaries into the same process的解决办法
    微软新一代输入法框架 TSF
    Starting the application on Mac does not work(拷贝platforms到不同的位置,才能解决问题),还可设置DYLD_PRINT_LIBRARIES=1 观察动态库
    dddd
  • 原文地址:https://www.cnblogs.com/hu555snow/p/5710948.html
Copyright © 2011-2022 走看看