zoukankan      html  css  js  c++  java
  • CSS

    <style>

    img{

    border: 1px solid red;

    }

    #img2{

    position: relative;/*相对定位---相对自身位置而言*/

    bottom: 100px;/*left,right,top,bottom*/

    }

    </style>

    </head>

    <body>

    <img src="img/img01.png" /><img id="img2" src="img/img02.png" />

    </body>

    </html>

    代码2测试:

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    img{

    border: 1px solid red;

    }

    #img2{

    position: absolute;/*绝对定位---相对浏览器四周位置而言*/

    bottom: 100px;/*left,right,top,bottom*/

    }

    </style>

    </head>

    <body>

    <img src="img/img01.png" /><img id="img2" src="img/img02.png" />

    </body>

    </html>

    (2)z-index

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    #img1{

    position: absolute;

    left: 100px;

    top: 50px;

    }

    #img2{

    position: absolute;

    left: 100px;

    top: 50px;

    }

    </style>

    </head>

    <body>

    <img  id="img1" src="img/img01.png" /><img  id="img2"  src="img/img02.png" />

    </body>

    </html>                          

    从上面的代码演示效果来看,两张图片完全重贴在一起,只显示第二张照片(测试时让两张图片一样大小)

    然而我们想让第一张图片显示在上面呢?添加一个属性 z-index

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    #img1{

    position: absolute;

    left: 100px;

    top: 50px;

    z-index: 100;

    }

    #img2{

    position: absolute;

    left: 100px;

    top: 50px;

    z-index: 10;

    }

    </style>

    </head>

    <body>

    <img  id="img1" src="img/img01.png" /><img  id="img2"  src="img/img02.png" />

    </body>

    </html>

    z-index:其实改变的就是xyz轴的z轴的值,值越大,层级越高

    上面的100,10都是随便写的,想要第一张照片显示,让它的层级比图片2高就可以了。

    2.布局

    (1)display

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    </head>

    <body>

    <div>块级元素1</div>

    <div>

    <div class="cls">

    块级元素2-1

    </div>

    <div class="cls">

    块级元素2-2

    </div>

    <div class="cls">

    块级元素2-3

    </div>

    </div>

    </body>

    </html>

    效果:

    将块级元素变成行内元素:

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    .cls{

    display: inline;

    }

    </style>

    </head>

    <body>

    <div>块级元素1</div>

    <div>

    <div class="cls">

    块级元素2-1

    </div>

    <div class="cls">

    块级元素2-2

    </div>

    <div class="cls">

    块级元素2-3

    </div>

    </div>

    </body>

    </html>

    (2)display-none visibility-hidden的区别:

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    #img01{

    /*display: none; 隐藏元素---隐藏物理空间*/

    /*visibility: hidden;隐藏元素---不隐藏物理空间*/

    }

    </style>

    </head>

    <body>

    <img id="img01" src="img/img01.png" />

    <img src="img/img02.png" />

    </body>

    </html>

    上面的黄色重点部分,分别测试效果 ,即可看出区别。

    (3)float 悬浮

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    ul{

    /*使ul没有前面的点*/

    list-style-type: none;

    }

    li{

    float: right;

    /*

     * left:居左悬浮:从左向右的悬浮效果

     * right:居右悬浮:从右向左的悬浮效果

     * */

    }

    </style>

    </head>

    <body>

    <ul>

    <li>新闻</li>

    <li>视频</li>

    <li>图片</li>

    <li>更多</li>

    </ul>

    </body>

    </html>

    3.尺寸

    (1)width,height

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    div{

    /*背景色*/

    /**/

     500px;

    /**/

    height: 100px;

    }

    </style>

    </head>

    <body>

    <div></div>

    </body>

    </html>

    4.背景

    (1) background-color, background-image, background-repeat, background

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    div{

    /*背景色*/

    /*背景图片*/

    background-image: url(img/img01.png);

    /*背景颜色,背景图片只能展示一个*/

    /*background-repeat:显示方式 默认是平铺--重复     不平铺--不重复--no-repeat*/

    background-repeat: no-repeat;

    /*还可以直接全部写在background中:*/

    background: url(img/img01.png) no-repeat;

    /**/

     1000px;

    /**/

    height: 1000px;

    }

    </style>

    </head>

    <body>

    <div></div>

    </body>

    </html>

    5.颜色

    (1)color

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    div{

    color: red;

    /*

     颜色的值可以有三种设置方式:

     1.颜色的单词

     2.#+6位的16进制数 --利用RGB三基色

     3.#+3位  ----RGB简写*/

    }

    </style>

    </head>

    <body>

    <div>你好div</div>

    </body>

    </html>

    (2)opacity 透明度

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    img{

    opacity: 0.5;

    /*透明度1:最饱和的状态

     可以用0-1之间的数测试效果*/

    }

    </style>

    </head>

    <body>

    <img src="img/img01.png" />

    </body>

    </html>

    6.字体

    (1) font-family, font-size, font-weight, font-style

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style>

    div{

    color: blue;

    /*字体*/

    font-family: '萝莉体 第二版';

    /*大小*/

    font-size: 30px;

    /*加粗*/

    font-weight: bold;

    /*斜体*/

    font-style: italic;

    }

    </style>

    </head>

    <body>

    <div>你好div</div>

    </body>

    </html>

    (2) text-align, text-decoration

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style>

    div{

    /*文本位置:常用:left | right | center*/

    text-align: center;

    /*文本中线的装饰:

    underline :  下划线

    line-through :  贯穿线

    overline :  上划线

    */

    text-decoration: line-through ; }

    </style>

    </head>

    <body>

    <div>你好div</div>

    </body>

    </html>

                             

    <style>

    img{

    border: 1px solid red;

    }

    #img2{

    position: relative;/*相对定位---相对自身位置而言*/

    bottom: 100px;/*left,right,top,bottom*/

    }

    </style>

    </head>

    <body>

    <img src="img/img01.png" /><img id="img2" src="img/img02.png" />

    </body>

    </html>

     

    代码2测试:

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    img{

    border: 1px solid red;

    }

    #img2{

    position: absolute;/*绝对定位---相对浏览器四周位置而言*/

    bottom: 100px;/*left,right,top,bottom*/

    }

    </style>

    </head>

    <body>

    <img src="img/img01.png" /><img id="img2" src="img/img02.png" />

    </body>

    </html>

    (2)z-index

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    #img1{

    position: absolute;

    left: 100px;

    top: 50px;

    }

    #img2{

    position: absolute;

    left: 100px;

    top: 50px;

    }

    </style>

    </head>

    <body>

    <img  id="img1" src="img/img01.png" /><img  id="img2"  src="img/img02.png" />

    </body>

    </html>                          

    从上面的代码演示效果来看,两张图片完全重贴在一起,只显示第二张照片(测试时让两张图片一样大小)

    然而我们想让第一张图片显示在上面呢?添加一个属性 z-index

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    #img1{

    position: absolute;

    left: 100px;

    top: 50px;

    z-index: 100;

    }

    #img2{

    position: absolute;

    left: 100px;

    top: 50px;

    z-index: 10;

    }

    </style>

    </head>

    <body>

    <img  id="img1" src="img/img01.png" /><img  id="img2"  src="img/img02.png" />

    </body>

    </html>

    z-index:其实改变的就是xyz轴的z轴的值,值越大,层级越高

    上面的100,10都是随便写的,想要第一张照片显示,让它的层级比图片2高就可以了。

     

    2.布局

    (1)display

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    </head>

    <body>

    <div>块级元素1</div>

    <div>

    <div class="cls">

    块级元素2-1

    </div>

    <div class="cls">

    块级元素2-2

    </div>

    <div class="cls">

    块级元素2-3

    </div>

    </div>

    </body>

    </html>

    效果:

     

    将块级元素变成行内元素:

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    .cls{

    display: inline;

    }

    </style>

    </head>

    <body>

    <div>块级元素1</div>

    <div>

    <div class="cls">

    块级元素2-1

    </div>

    <div class="cls">

    块级元素2-2

    </div>

    <div class="cls">

    块级元素2-3

    </div>

    </div>

    </body>

    </html>

     

    (2)display-none visibility-hidden的区别:

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    #img01{

    /*display: none; 隐藏元素---隐藏物理空间*/

    /*visibility: hidden;隐藏元素---不隐藏物理空间*/

    }

    </style>

    </head>

    <body>

    <img id="img01" src="img/img01.png" />

    <img src="img/img02.png" />

    </body>

    </html>

    上面的黄色重点部分,分别测试效果 ,即可看出区别。

    (3)float 悬浮

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    ul{

    /*使ul没有前面的点*/

    list-style-type: none;

    }

    li{

    float: right;

    /*

     * left:居左悬浮:从左向右的悬浮效果

     * right:居右悬浮:从右向左的悬浮效果

     * */

    }

    </style>

    </head>

    <body>

    <ul>

    <li>新闻</li>

    <li>视频</li>

    <li>图片</li>

    <li>更多</li>

    </ul>

    </body>

    </html>

    3.尺寸

    (1)width,height

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    div{

    /*背景色*/

    background-color: #7FFF00;

    /**/

    width: 500px;

    /**/

    height: 100px;

    }

    </style>

    </head>

    <body>

    <div></div>

    </body>

    </html>

     

    4.背景

    (1) background-color, background-image, background-repeat, background

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    div{

    /*背景色*/

    background-color: #7FFF00;

    /*背景图片*/

    background-image: url(img/img01.png);

    /*背景颜色,背景图片只能展示一个*/

    /*background-repeat:显示方式 默认是平铺--重复     不平铺--不重复--no-repeat*/

    background-repeat: no-repeat;

    /*还可以直接全部写在background中:*/

    background: url(img/img01.png) no-repeat;

    /**/

    width: 1000px;

    /**/

    height: 1000px;

    }

    </style>

    </head>

    <body>

    <div></div>

    </body>

    </html>

     

    5.颜色

    (1)color

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    div{

    color: red;

    /*

     颜色的值可以有三种设置方式:

     1.颜色的单词

     2.#+6位的16进制数 --利用RGB三基色

     3.#+3位  ----RGB简写*/

    }

    </style>

    </head>

    <body>

    <div>你好div</div>

    </body>

    </html>

    (2)opacity 透明度

    <html>

    <head>

    <meta charset="UTF-8">

    <title>定位position</title>

    <style>

    img{

    opacity: 0.5;

    /*透明度1:最饱和的状态

     可以用0-1之间的数测试效果*/

    }

    </style>

    </head>

    <body>

    <img src="img/img01.png" />

    </body>

    </html>

     

    6.字体

    (1) font-family, font-size, font-weight, font-style

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style>

    div{

    color: blue;

    /*字体*/

    font-family: '萝莉体 第二版';

    /*大小*/

    font-size: 30px;

    /*加粗*/

    font-weight: bold;

    /*斜体*/

    font-style: italic;

    }

    </style>

    </head>

    <body>

    <div>你好div</div>

    </body>

    </html>

    (2) text-align, text-decoration

    <html>

    <head>

    <meta charset="UTF-8">

    <title></title>

    <style>

    div{

    /*文本位置:常用:left | right | center*/

    text-align: center;

    /*文本中线的装饰:

    underline :  下划线

    line-through :  贯穿线

    overline :  上划线

    */

    text-decoration: line-through ;}

    </style>

    </head>

    <body>

    <div>你好div</div>

    </body>

    </html>

     

     

     

     

     

     

     

     

     

     

     

     

     

                             

  • 相关阅读:
    批处理bat命令--获取当前盘符和当前目录和上级目录
    网页切图div+css命名规则
    Css 切换
    JavaScript的编码规范
    JavaScript原型继承添加方法属性
    使用cookie
    常见元素及其相关事件/创建弹出框
    在JavaScript中什么时候使用==是正确的?
    理解Null和Undefined
    Oracle一列的多行数据拼成一行显示字符
  • 原文地址:https://www.cnblogs.com/wxj-106/p/7729853.html
Copyright © 2011-2022 走看看