国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > WEB開發 > 正文

less的使用

2024-04-27 15:07:56
字體:
來源:轉載
供稿:網友

less的用法

1.注釋:less的注釋有兩種

     一種是: /* 會被編譯的 */   

    另一種是: //不會被編譯的

    會不會被編譯是指這個注釋的文字會不會顯示在該less文件所對應的CSS文件上

2.變量

   @test_width:300px;

   .box{

    width:@test_width;

    height:@test_width;

    }

  聲明變量:一定要用@開頭   @變量名:值;

3.混合

   .box{

    width:300px;

    hight:300px;

    .border; //混合下面的border

     }

   .border{

    border:solid  5px  pink;

    }

   .box2{

    .box;

    margin-left:100px;

    }

4.混合--帶參數

   .border_02(@border_width){

    border:solid  yellow  @border_width;

    }

   .test_hunhe{

    .border_02(30px);

    }

5.混合--默認帶值

   .border_03(@border_width:10px){

    border:solid  yellow  @border_width;

   }

   .test_hunhe_03{

   .border_03();

   }

主意:如果混合有默認值,使用時可以不用傳參。如果沒有默認值,則必須傳參。

有默認值時,如需要改變值,則傳遞需要傳入的數值,其余未傳入的值則使用默認值。

6.匹配模式

    .sanjiao{  //向上三角形的畫法

    width:0;

    height:0;

    overflow:hidden;   

    border-width:10px;

    border-color: transparent transparent red transparent

    border-style: dashed dashed solid  dashed ;

    }

   .triangle(top,@w:5px,@c:#ccc){ //向上的三角

    border-width:@w;

    border-color: transparent transparent @c transparent;

    border-style: dashed dashed solid  dashed ;

   }

   .triangle(bottom,@w:5px,@c:#ccc){//向下的三角

    border-width:@w;

    border-color: @c transparent transparent transparent;

    border-style: solid dashed dashed dashed ;

   }

   .triangle(left,@w:5px,@c:#ccc){//向左的三角

    border-width:@w;

    border-color: transparent @c transparent transparent;

    border-style: dashed solid dashed dashed ;

   }

   .triangle(right,@w:5px,@c:#ccc){//向右的三角

    border-width:@w;

    border-color: transparent transparent transparent @c ;

    border-style: dashed dashed dashed solid ;

   }

   triangle(@_,@w:5px,@c:#ccc){  //如下代碼不管能否匹配到數值,都會顯示出來

    width:0;

    height:0;

    overflow:hidden; 

   }

   sanjiaoxing{ //畫三角形,傳值進入進行匹配

   .triangle(top,100px);

   }

7.匹配模式--定位例子

   .pos(r){

   position:relative;

   }

   .pos(a){

   position:absolute;

   }

  .pos(f){

   position:fixed;

   }

  .pipei{   width:200px;   height:200px;   background-color:green;   .pos(f);  }

8.運算

  @test_01:300px;

  .box_02{

  width: (@test_01 - 20) * 2;  //運算過后得到的值為:width:560px;

  color: #ccc-10;  //變成了c2c2c2,顏色也是可以進行運算的,只是比較少運動到

  }

9.嵌套規則

   --最有意思的小東西了

   --兩種用法

   *& 對尾類使用

    - hover 或 focus

   *對連接的使用

    - &-item

   list{

   li{

   height:30px;

   wight:30px;

   }

   a{

   float:left;

   //& 代表他的上一層選擇器

   &:hover{

    color:red;

    }

    }

   span{

   float:right;

   }

  }

把 a 和 span嵌套到list里面。

10. @arguments變量

  *@arguments包含了所有傳遞進來的參數。

   .border_arg(@w:30px,@c:red,@xx:solid){

       border:@arguments;

   }

   .test_arguments{

       .border_arg(40px);

   }

  所對應的CSS文件顯示的是:

   .test_arguments{

       border:40px,red,solid;

    }

11.避免編譯

  *有時候我們需要輸出一些不正確的CSS語法或者使用一些less不認識的專有語法。

  *要輸出這樣的值我們可以在字符串前加上一個 ~

   列如:width:~‘calc(100%-35)’

  less文件中:

  .test_03{

  width:~'calc(300px-30px)'

  }

  css中:

  .test_03{

  width:calc(300px-30px);

  } 

12.!important以及總結

   ! important關鍵字

   -會為所以混合所帶來的樣式,添加上!important

   


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新宁县| 固镇县| 彝良县| 平阴县| 营山县| 沙河市| 小金县| 新营市| 滁州市| 柳林县| 巨野县| 巴东县| 寻乌县| 商河县| 洪洞县| 陈巴尔虎旗| 青河县| 葵青区| 凌源市| 汉源县| 乐平市| 台南县| 应城市| 丰宁| 潞城市| 和平县| 齐齐哈尔市| 历史| 全南县| 长宁区| 通道| 开阳县| 洪雅县| 东安县| 永修县| 腾冲县| 铁力市| 海淀区| 淮安市| 乐山市| 上思县|