Less效用

高效编辑css,相信很多小伙伴都使用过Less,Less的使用相对比较简单;它能在开发css的组件话起到非凡的作用。

Css预编译处理:Less

1.定义变量,使用的的是@作用前缀

@w:200px;//定义一个宽度为200px

@bgColr:red;//定义个背景颜色

在一个div元素中使用定义过的变量

div{

backgound-color:@bgColor;

}

2.后代选择器,伪类使用符号&

div{

background-color:@bgColor;

.select{

width:100;

}

&:after{

content:'';

}

}

3.文件引用

@import:'less文件';

4.Less函数

.fun(@px){

height:@px;

}

这是Less的基本定义,下面是使用Demo展示Less的使用

index.less

@import 'me.less';

.fs(@px) {

font-size: unit(@px , rem);

}

.w(@px) {

width: unit(@px , rem);

}

.h(@px) {

height: unit(@px , rem);

}

.lh(@px) {

line-height: unit(@px, rem);

}

.mt(@px) {

margin-top: unit(@px, rem);

}

.ml(@px) {

margin-top: unit(@px, rem);

}

.mr(@px) {

margin-top: unit(@px, rem);

}

.mb(@px) {

margin-top: unit(@px, rem);

}

.pt(@px) {

padding-top: unit(@px, rem);

}

.pl(@px) {

padding-left: unit(@px, rem);

}

.pr(@px) {

padding-right: unit(@px, rem);

}

.pb(@px) {

padding-bottom: unit(@px, rem);

}

html,body {

height: 100%;

width: 100%;

margin: 0;

}

body {

background-color: @bodyBgColor;

.fs(16);

}

button {

border-width: 0;

outline-width: 0;

}

@defaultColor: #fff;

@headBgColor: #12d5b5;

@dangerColor: red;

@bodyBgColor: #eee;

me.less

.me {

img {

.mt(60);

margin-left: auto;

margin-right: auto;

}

.name {

.mt(25);

}

.login-btn {

background-color: @headBgColor;

color: @defaultColor;

.fs(16);

.w(340);

.h(40);

.mt(300);

}

.btns {

.mt(40);

button {

background-color: @headBgColor;

color: @defaultColor;

.fs(16);

.w(150);

.h(95);

margin-left: 12px;

margin-right: 12px;

&.logout {

background-color: @dangerColor;

.w(340);

.h(40);

.mt(20);

}

}

}

}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. tab列表折叠效果 html: 能源系统事业部 岗位名称: 工作地点 岗位名...
    lilyping阅读 1,923评论 0 1
  • 问答题47 /72 常见浏览器兼容性问题与解决方案? 参考答案 (1)浏览器兼容问题一:不同浏览器的标签默认的外补...
    _Yfling阅读 13,844评论 1 92
  • •前端面试题汇总 一、HTML和CSS 21 你做的页面在哪些流览器测试过?这些浏览器的内核分别是什么? ...
    Simon_s阅读 2,239评论 0 8
  • 创建一个线程有两种方式,一种及用一个类继承Thread类 另一种是通过实现Runnable接口 他们都要重写Run...
    惨不忍睹阅读 158评论 0 0
  • 最近打开简书,天涯,小红书,太多文都着重点强调21天逆袭,21天改变自己,21天瘦10斤以上。 说真的,在我刚开始...
    神采飞扬的鱼阅读 335评论 0 4