zoukankan      html  css  js  c++  java
  • 大家一起学习less 3:命名空间

    这其实是“嵌套规则”的升级版。

    我们先看官网例子吧:

    //LESS
    //这里是命名空间的定义,里面包含一个button方法
    #bundle {
      .button () {
        display: block;
        border: 1px solid black;
        background-color: grey;
        &:hover { background-color: white }
      }
    }
    //这里是具体调用,通过XXX > YYY方式进行调用,本人觉得用 -〉更可靠,起码长得不像亲子选择器
    #header a {
      color: orange;
      #bundle > .button;
    }
    
    /* 生成的 CSS */
    #header a {
    color: orange;
    display: block;
    border: 1px solid black;
    background-color: grey;
    }
    #header a:hover {
    background-color: #ffffff;
    } 
    
    

    上面的命名空间定义,不要以为只有ID选择器才可以,任何合法选择器也行,如

    //LESS
    //模块名改为类了
    .bundle {
      .button () {
        display: block;
        border: 1px solid black;
        background-color: grey;
        &:hover { background-color: white }
      }
    }
    #header a {
      color: orange;
      .bundle > .button;
    }
    
    /* 生成的 CSS */
    #header a {
    color: orange;
    display: block;
    border: 1px solid black;
    background-color: grey;
    }
    #header a:hover {
    background-color: #ffffff;
    } 
    
    

    我是强烈建议,对于这些命名空间(其他叫模块更恰切些),只应该包含方法

    
    //LESS
    //这里应该只包含方法,否则里面的合法语句会生成出来
    #bundle {
      .button () {
        display: block;
        border: 1px solid black;
        background-color: grey;
        &:hover { background-color: white }
      }
      .red{ color: red; }
    }
    //这里是具体调用,通过XXX > YYY方式进行调用,本人觉得用 -〉更可靠,起码长得不像亲子选择器
    #header a {
      color: orange;
      #bundle > .button;
    }
    /* 生成的 CSS */
    
    #bundle .red {
      color: red;
    }
    #header a {
      color: orange;
      display: block;
      border: 1px solid black;
      background-color: grey;
    }
    #header a:hover {
      background-color: #ffffff;
    }
    

    具体自己可以到这个网站玩玩!

  • 相关阅读:
    Dp~Hrbust1426( 集训队的晚餐 )
    DP~数塔(hrbustoj1004)
    MyEclipse启动性能优化(----加快启动速度)
    很实用的php的缓存类文件示例
    PHP中9大缓存技术总结
    微信公众平台开发(76) 获取用户基本信息
    js中 onreadystatechange 和 onload的区别
    一个js文件导入js的函数
    PHP cURL实现模拟登录与采集使用方法详解教程
    Mysql清空表(truncate)与删除表中数据(delete)的区别
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/2684177.html
Copyright © 2011-2022 走看看