LESS CSS非常实用实例应用
@charset "UTF-8";
@base-color:#333;
// 圆角
.border-radius (@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
//四角半径定制
.border-radius-custom (@topleft: 5px, @topright: 5px, @bottomleft: 5px, @bottomright: 5px) {
-webkit-border-radius: @topleft @topright @bottomright @bottomleft;
-moz-border-radius: @topleft @topright @bottomright @bottomleft;
border-radius: @topleft @topright @bottomright @bottomleft;
}
//阴影
.box-shadow (@x: 0px, @y: 0px, @blur: 5px, @color:#999) {
-webkit-box-shadow: @x @y @blur @color;
-moz-box-shadow: @x @y @blur @color;
box-shadow: @x @y @blur @color;
}
//内阴影
.box-shadow-inset (@x: 0px, @y: 0px, @blur: 5px, @color:#999) {
-webkit-box-shadow: @x @y @blur @color inset;
-moz-box-shadow: @x @y @blur @color inset;
box-shadow: @x @y @blur @color inset;
}
//过渡效果
.transition (@prop: all, @time: .3s, @ease: linear) {
-webkit-transition: @prop @time @ease;
-moz-transition: @prop @time @ease;
-o-transition: @prop @time @ease;
-ms-transition: @prop @time @ease;
transition: @prop @time @ease;
}
//转换
.transform (@rotate: 90deg, @scale: 1, @skew: 0deg, @translate: 10px) {
-webkit-transform: rotate(@rotate) scale(@scale) skew(@skew) translate(@translate);
-moz-transform: rotate(@rotate) scale(@scale) skew(@skew) translate(@translate);
-o-transform: rotate(@rotate) scale(@scale) skew(@skew) translate(@translate);
-ms-transform: rotate(@rotate) scale(@scale) skew(@skew) translate(@translate);
transform: rotate(@rotate) scale(@scale) skew(@skew) translate(@translate);
}
//颜色渐变
.gradient (@origin: left, @start: #ffffff, @stop: #000000) {
background-color: @start;
background-image: -webkit-linear-gradient(@origin, @start, @stop);
background-image: -moz-linear-gradient(@origin, @start, @stop);
background-image: -o-linear-gradient(@origin, @start, @stop);
background-image: -ms-linear-gradient(@origin, @start, @stop);
background-image: linear-gradient(@origin, @start, @stop);
}
//rgba
.rgba(@r,@g,@b,@a){
@c: rgba(@r,@g,@b,@a);
@c2 :argb(@c);
/* for IE9 IE8 IE7 not sure about IE6*/
filter:~"progid:DXImageTransform.Microsoft.gradient(enabled='true',startColorstr='@{c2}', endColorstr='@{c2}')";
background-color:@c;
:root &{
/*
* IE9 由于rgba和filter都支持,会导致两个颜色叠加,使用hack去除
* \9 代表 IE9 以下浏览器支持
* :root 只有 IE9+ 以及其他现代浏览器支持
* IE10 以上不再支持 filter
*/
filter:none;
}
}
//设置透明度
.opacity(@number){
/* older safari/Chrome browsers */
-webkit-opacity: @number/100;
/* Netscape and Older than Firefox 0.9 */
-moz-opacity: @number/100;
/* Safari 1.x (pre WebKit!) 老式khtml内核的Safari浏览器*/
-khtml-opacity: @number/100;
/* IE9 + etc...modern browsers */
opacity: @number/100;
/* IE 4-9 */
filter:alpha(opacity=@number);
/*This works in IE 8 & 9 too*/
-ms-filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=@number);
/*IE4-IE9*/
filter:progid:DXImageTransform.Microsoft.Alpha(Opacity=@number); }
//less文件中定义的函数
//Animation 动画
//@animation-name规定需要绑定到选择器的 keyframe 名称
//@animation-duration规定完成动画所花费的时间,以秒或毫秒计,默认是 0。
//@animation-timing-function规定动画的速度曲线。默认是 "ease"。
//@animation-delay规定在动画开始之前的延迟。默认是 0。
//@animation-iteration-count规定动画应该播放的次数。默认是 1。
//@animation-direction规定是否应该轮流反向播放动画。默认是 "normal"。 .animation(@animation-name:myanimate,@animation-duration:2s,@animation-timing-function:linear,
@animation-delay:0s,@animation-iteration-count:infinite,@animation-direction:normal){
animation: @arguments;
/* Firefox: */
-moz-animation: @arguments;
/* Safari 和 Chrome: */
-webkit-animation: @arguments;
/* Opera: */
-o-animation: @arguments;
}
.keyframes(@name:myanimate){
@keyframes @name{
0% {}
25% {}
50% {}
75% {}
100% {}
}
@-webkit-keyframes @name{
0% {}
25% {}
50% {}
75% {}
100% {}
}
@-moz-keyframes @name{
0% {}
25% {}
50% {}
75% {}
100% {}
}
@-o-keyframes @name{
0% {}
25% {}
50% {}
75% {}
100% {}
}
}
//设置中心点
.origin(@x:50%,@y:50%){
transform-origin:@x @y;
-ms-transform-origin:@x @y; /* IE 9 */
-webkit-transform-origin:@x @y; /* Safari 和 Chrome */
-moz-transform-origin:@x @y; /* Firefox */
-o-transform-origin:@x @y; /* Opera */
}
//设置盒模型
.box-sizing(@box:border-box){
box-sizing:@box;
-moz-box-sizing:@box; /* Firefox */
-webkit-box-sizing:@box; /* Safari */
}
//设置缩放比例
.scale (@scale: 1) {
-webkit-transform: scale(@scale);
-moz-transform: scale(@scale);
-o-transform: scale(@scale);
-ms-transform: scale(@scale);
transform: scale(@scale); }
//绕Y轴旋转角度
.rotateY (@rotate: 90deg) {
-webkit-transform: rotateY(@rotate);
-moz-transform: rotateY(@rotate);
-o-transform: rotateY(@rotate);
-ms-transform: rotateY(@rotate);
transform: rotateY(@rotate); }
//文本垂直居中
.ver-m(@height:0px){
height: @height;
line-height: @height;
} //三角绘制
.sanjiao(@top:@base-color,@left:transparent,@bottom:transparent,@right:transparent,@width:10px){
width:0;
height:0;
overflow:hidden;
font-size: 0; /*是因为, 虽然宽高度为0, 但在IE6下会具有默认的 */
line-height: 0; /* 字体大小和行高, 导致盒子呈现被撑开的长矩形 */
border-width:@width;
border-style:solid; /*ie6下会出现不透明的兼容问题*/
border-color:@top @left @bottom @right;
}
//超出显示省略号
.ellipsis(){
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
}
//inline-block
.inline-block(){
display:inline-block;
zoom:1; /*IE 下触发 hasLayout*/
*display:inline; /*一旦IE 下触发了 hasLayout,设置 block 元素为 inline 会使 display:inline 效果与 display:inline-block 相似*/
}
如何使用Less并监听
<link rel="stylesheet/less" type="text/css" href="{%$rootpath%}css/index.less" />
<script src="{%$rootpath%}js/less.js" type="text/javascript" ></script>
<script>less.watch();</script>
在node.js环境下:
npm install -g less
用git 将less文件编译成css文件
lessc index.less>index.css
用git 将less文件编译成css压缩文件
lessc index.less>index.css -x
LESS CSS非常实用实例应用的更多相关文章
- jQuery UI 入门之实用实例分享
jQuery UI 入门 jQuery UI 简介 jQuery UI 是一个建立在 jQuery JavaScript 库上的小部件和交互库,您可以使用它创建高度交互的 Web 应用程序.无论您是创 ...
- jQuery UI 入门之实用实例
jQuery UI 入门 jQuery UI 简介 jQuery UI 是一个建立在 jQuery JavaScript 库上的小部件和交互库,您可以使用它创建高度交互的 Web 应用程序.无论您是创 ...
- 网页设计与开发:HTML、CSS、JavaScript实例教程 (郑娅峰) pdf扫描版
网页设计与开发:HTML.CSS.JavaScript实例教程从实用角度出发,详细讲解了HTML.CSS和JavaScript的基本语法和设计技巧,通过一个实用的班级网站的规划.设计.实现到发布过程, ...
- 【转】精选30个优秀的CSS技术和实例
今天,我为大家收集精选了30个使用纯CSS完成的强大实践的优秀CSS技术和实例,您将在这里发现很多与众不同的技术,比如:图片集.阴影效果.可扩展按钮.菜单等-这些实例都是使用纯CSS和HTML实现的. ...
- 精选30个优秀的CSS技术和实例
精选30个优秀的CSS技术和实例 投递人 墙头草 发布于 2008-12-06 20:57 评论(97) 有17487人阅读 原文链接 [收藏] « » 今天,我为大家收集精选了30个使用纯CSS ...
- css技术和实例
今天,我为大家收集精选了30个使用纯CSS完成的强大实践的优秀CSS技术和实例,您将在这里发现很多与众不同的技术,比如:图片集.阴影效果.可扩展按钮.菜单等-这些实例都是使用纯CSS和HTML实现的. ...
- 《CSS动画实用技巧》课程笔记
概述 这是我学习[CSS动画实用技巧][1]的课程笔记 常用动画属性--transition [常用动画属性--transition][2] .change img{ display:block; w ...
- CSS 分类 (Classification) 实例
CSS 分类 (Classification) 实例CSS 分类属性 (Classification)CSS 分类属性允许你控制如何显示元素,设置图像显示于另一元素中的何处,相对于其正常位置来定位元素 ...
- CSS 尺寸 (Dimension) 实例
CSS 尺寸 (Dimension) 实例CSS 尺寸属性CSS 尺寸属性允许你控制元素的高度和宽度.同样,还允许你增加行间距. 属性 描述height 设置元素的高度.line-height 设置行 ...
随机推荐
- Learning Python 003 缩进
Python 缩进 Python的代码中不使用{}大括号来来表示一个代码块,而是使用缩进方式.像下面这段代码: # print absolute value of an integer: a = 10 ...
- js判断IP字符串是否正确
//判断ip地址的合法性 function checkIP(value){ var exp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0 ...
- myeclipse 不能重新编译 web .classpath文件修改
这个问题困扰我好久了,就是当你从另一个workspace中拷到另一个workspace中,然后在import进myeclipse中就会出现无论你怎么改代码,编译完成后webroot目录下的classe ...
- haml
创建: 2019/05/23 文档: http://haml.info/docs/yardoc/file.REFERENCE.html 安装 安装 gem "haml" ...
- explain SQL语句()
坊间有传言:MySQL性能优化有个神器,叫做explain,它可以对select语句进行分析并且输出详细的select执行过程的详细信息,让开发者从这些信息中获得优化的思路. 下面来讲讲这个MySQL ...
- ps怎样简单快速去除图片上的文字
具体步骤如下: 1.选择"修补工具": 2.在公共栏中选择"源": 3."图像"->"模式"中选择"RG ...
- HDU1863-畅通工程
题目链接:点击打开链接 Problem Description 省政府"畅通工程"的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即 ...
- STP-19-Port-Channel发现和配置
工程师在给一台交换机上的特定Port-Channel增加多个端口时,有一些配置参数必须相同,如下所示: 使用相同的速率和双工设置: 使用相同的操作模式(Trunk.Access.动态): 若不为T ...
- POJ1845 Sumdiv 数学?逆元?
当初写过一篇分治的 题意:求A^B的所有因子之和,并对其取模 9901再输出 对于数A=p1^c1+p2^c2+...+pn*cn,它的所有约数之和为(1+p1+p1^2+p1^3+...+p1^(c ...
- Luogu P1768 天路 0/1分数规划+dfs spfa
“那是一条神奇的天路诶~~把第一个神犇送上天堂” 怕不是某大佬早就A了这题,然鹅我又调了很久很久... 好吧就是0/1分数规划,但是跑的dfs的spfa(好像题解说bfs过不了????不知) 发现把s ...