元素的层级和背景

z-index
   .box1{
        width: 200px;
        height: 200px;
        background-color: #0bcd96;
        position:relative;
        z-index:3;
    }
    .box2{
        width: 200px;
        height: 200px;
        background-color: #1e389a;
        position: absolute;
        left: 100px;
        top: 100px;
    }
    .box3{
        width: 200px;
        height: 200px;
        background-color: #6a1752;
        position: relative;
        z-index:2;
    }
  • 如果没有开启定位的元素或者是定位为默认值,会忽略z-index的声明
  • 父元素的层级再怎么高也不会盖住子元素,可以理解为(水涨船高)

opacity(透明)
 .box1{
        width: 200px;
        height: 200px;
        background-color: #0bcd96;
        position:relative;
        opacity: 50%;
        filter: alpha(opacity=50);
    }
    .box2{
        width: 200px;
        height: 200px;
        background-color: #1e389a;
        position: absolute;
        left: 100px;
        top: 100px;
        opacity:0.5px;
        filter: alpha(opacity=50);
    }
    .box3{
        width: 200px;
        height: 200px;
        background-color: #6a1752;
        position: relative;
        opacity: 50%;
        filter: alpha(opacity=50);
    }
  • opacity只能设置0-1之间的数值
  • filter: alpha(opacity=50)兼容IE浏览器

背景(background-image)

.box1{
        width: 500px;
        height: 500px;
        margin:0 auto;
        background-color: #0bcd96;
        background-image: url(../css/logo_new@2x.png);
        background-repeat:no-repeat;
    }
  • background-repeat:no-repeat 图片只显示一次
  • background-repeat:repeat-x 背景将在水平方向重复
  • background-repeat:repeat-y 背景将在垂直方向重复
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML标准。 注意:讲述HT...
    kismetajun阅读 27,958评论 1 45
  • 学会使用CSS选择器熟记CSS样式和外观属性熟练掌握CSS各种选择器熟练掌握CSS各种选择器熟练掌握CSS三种显示...
    七彩小鹿阅读 11,422评论 2 66
  • 元素的层级z-index: z-index(正整数) 数值越大,层级越高(元素的层级必须开启...
    常伟波阅读 5,071评论 0 0
  • 转载请声明 原文链接地址 关注公众号获取更多资讯 第一部分 HTML 第一章 职业规划和前景 职业方向规划定位...
    前端进阶之旅阅读 16,677评论 32 459
  • 感恩外出回来下了一阵猝不及防的雨,不大不小,抱着睡的美,娘四个正打算下了车冲进雨里跑回家,这时一个雨伞递了过来,为...
    寸心洁白阅读 1,943评论 0 0