HTML基礎第四課(2D形變,定位)

一、2D形變

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2d形變</title>
    <style type="text/css">

        body{

        }
        div{
            width: 200px;
            height: 200px;
            background-color: gray;

            text-align: center;
            line-height: 200px;
            font-size: 30px;
            margin-left: 100px;
            float: left;
            color: black;
            transition: 2s linear;
        }
        .rotate{
            /*旋轉*/
            transform: rotate(0deg);
        }
          .rotate:hover{
            transform: rotate(360deg);
          }

       .translate{
        /*平移*/
           transform: translate(0px,0px);
       }

       .translate:hover{
       transform: translate(10px,10px);
       }

       .scale{
        /*縮放*/
         /*transform: scale(2);*/
         transform: scale(0.5,2);
       }
       .skew{
        /*傾斜*/
        /*skewX skewY skew*/
    transform: skewX(10deg);

       }
    </style>
</head>
<body>
    <div class="rotate">旋轉</div>
    <div class="translate">平移</div>
    <div class="scale">縮放</div>
    <div class="skew">傾斜

    </div>

</body>
</html>

二、定位


body{
 height: 1200px;
}
//a.定位種類:
1.relative相對定位
2.absolute絕對定位 
3.fixed固定定位
4.abstract默認定位*/

.redDiv,.blueDiv{
    width: 200px;
   height: 200px;
}
.redDiv{
    /*默認值:不定位*/
    /*position: static;*/
    /*相對定位  相對於自身的位置,去移動
      不脫離文檔流的,還佔用原來的位置
    */
    position: relative;
    /*只有定位的元素才能使用:left top bottom right*/
    left: 10px;
    bottom: 20px;

    background-color: red;
}
.blueDiv{
    background-color: blue;
    /*position: relative;*/
  /*絕對定位 相對於 定位 父級去定位
   如果父級只是作爲父級使用,只需要
   視同relatives
  */

}
.greenDiv{
    /*絕對定位  相對於帶有postion屬性(不包括static)的父級定位,如果
   父級沒有postion屬性,就去找父父級別,直到html。如果html也沒有position
   就相當於document窗口定位
    */
    position: absolute;
    right: 0px;
    bottom: 0px;
    width: 50px;
    height: 50px;
    background-color: green;

    /*! 對於定位的元素纔可以使用,z-index
    z-index值越大,位置越靠前
    z-index可以是賦值,賦值情況下比正常元素靠後
    z-index >浮動 >正常的塊級元素 

    */
    z-index:2;
}
.ad{
    width: 100px;
    height: 380px;
    background-color: gray;
    color: white;
    font-size: 20px;
    /*固定定位 相對於窗口的位置始終不變
    left 0;設置元素在距離窗口左邊爲0的地方
    bottom 0;設置元素在距離窗口下邊爲0的地方
    right 0;設置元素在距離窗口右邊爲0的地方
    top 0;設置元素在距離窗口上邊爲0的地方
    會脫離文檔流的
    */

    position: fixed;
    right: 20px;
    top: 50%;
    margin-top: -190px;

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章