less 学习笔记入门

CSS预处理器中Less的语法最接近原生CSS,学习成本比较低,语法比较简单,并且能够在浏览器客户端中预览,我这里只是简单的作为搭建less开发环境,可以在工作中熟练less相关的API和属性方法。

@border_color:#eee;
@item_height:45px;
@item_padding_width:60px;

.hb_list_container{
  display: block;

  .hb_item_container{
    border-bottom: 1px solid @border_color;
    height: @item_height;
    line-height: @item_height;
    position: relative;

    &.hb_icon_right{
      padding-right: @item_padding_width;
      .iconfont:first-child{
        position: absolute;
        top: 0px;
        right: 0px;
        line-height: @item_height;
      }
    }

    &.hb_icon_left{
      padding-left: @item_padding_width;
      .iconfont:last-child{
        position: absolute;
        top: 0px;
        left: 0px;
        line-height: @item_height;
      }
    }

  }
}

 备注:

语法参考 http://www.lesscss.net/features/

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet/less" type="text/css" href="less/list_icon.less">
    <link rel="stylesheet" href="public/css/hb_wap.css">
    <script src="public/js/less.js" type="text/javascript"></script>
    <title>list icon 组件</title>
</head>
<body>

<div class="hb_list_container">
    <div class="hb_item_container">
        dsaf
    </div>

    <div class="hb_item_container">
        dsaf
    </div>

    <div class="hb_item_container hb_icon_right">
        dsaf
        <span class="iconfont icon">&#xE60D;</span>
    </div>

    <div class="hb_item_container hb_icon_left hb_icon_right">
        <span class="iconfont icon">&#xE60D;</span>
        dsaf
        <span class="iconfont icon">&#xE60D;</span>
    </div>

    <div class="hb_item_container hb_icon_left">
        dsaf
        <span class="iconfont icon">&#xE60D;</span>
    </div>
</div>

</body>
</html>

1、引用less文件的方式

<link rel="stylesheet/less" type="text/css" href="less/list_icon.less">

2、引用对less解析的js函数

<script src="public/js/less.js" type="text/javascript"></script>

 less 学习笔记入门

相关推荐