我爱编程

6.1 css 显示模式 -背景和精灵图

2017-06-01  本文已影响0人  Jackson_yee_

Div和Span标签

<style>
        .header{
            width: 980px;
            height: 100px;
            background: red;
            margin: auto;
            margin-bottom: 10px;
        }
        .content{
            width: 980px;
            height: 500px;
            background: green;
            margin: auto;
            margin-bottom: 10px;
        }
        .footer{
            width: 980px;
            height: 100px;
            background: blue;
            margin: auto;
        }
        .logo{
            width: 200px;
            height: 50px;
            background: pink;
            float: left;
            margin: 20px;
        }
        .nav{
            width: 600px;
            height: 50px;
            background: yellow;
            float: right;
            margin: 20px;
        }
        .aside{
            width: 250px;
            height: 460px;
            background: purple;
            float: left;
            margin: 20px;
        }
        .article{
            width: 650px;
            height: 460px;
            background: deepskyblue;
            float: right;
            margin: 20px;
        }
</style>
<div class="header">
    <div class="logo"></div>
    <div class="nav"></div>
</div>
<div class="content">
    <div class="aside"></div>
    <div class="article"></div>
</div>
<div class="footer"></div>
<style>
        span{
            color: red;
        }
</style>
<p>努力到<span>无能为力</span>, 拼搏到<span>感动自己</span></p>

CSS元素显示模式

CSS元素显示模式转换

背景相关属性

背景颜色

<style>
div{
          width: 100px;
          height: 50px;
      }
.box1{
          background-color: red;
      }
      .box2{
          background-color: rgb(0,255,0);
      }
      .box3{
          background-color: rgba(0,0,255,0.7);
      }
      .box4{
          background-color: #0ff;
      }
</style>

背景图片

<style>
      div{
          width: 500px;
          height: 500px;
      }
      .box1{
          background-image: url(images/girl.jpg);
          /*background-image: url(http://img4.imgtn.bdimg.com/it/u=2278032206,4196312526&fm=21&gp=0.jpg);*/
      }
</style>
<div class="box1"></div>

背景平铺

<style>
      /*
      div{
          width: 500px;
          height: 500px;
      }
      .box1{
       background-color: red;
          background-image: url(images/girl.jpg);
          background-repeat: repeat-y;
      }
</style>
<div class="box1"></div>

背景定位

<style>
        div{
            /*width: 500px;*/
            height: 500px;
        }
        .box1{
            background-color: red;
            background-image: url(images/girl.jpg);
            background-repeat: no-repeat;
            /*background-position: left top;*/
            /*background-position: right top;*/
            /*background-position: right bottom;*/
            /*background-position: left bottom;*/
            /*background-position: center center;*/
            /*background-position: left center;*/
            background-position: center top;
        }
</style>
<div class="box1"></div>
<style>
        div{
            /*width: 500px;*/
            height: 500px;
        }
        .box1{
            background-color: red;
            background-image: url(images/girl.jpg);
            background-repeat: no-repeat;
            /*background-position: 100px 0;*/
            /*background-position: 100px 200px;*/
            background-position: -100px -100px;
        }
</style>

背景属性连写

背景关联

插入图片和背景图片的区别

css精灵

<style>
      .box{
          width: 86px;
          height: 28px;
          background-image: url(images/weibo.png);
          background-position: -425px -200px;
      }
  </style>
  <div class="box"></div>
image.png image.png
上一篇 下一篇

猜你喜欢

热点阅读