less 经典范例 bootstrap 的 less 版本 常用 less 代码
2.less 文件分布
/*!
* Bootstrap v3.3.7 (http://getbootstrap.com)
* Copyright 2011-2016 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/ // Core variables and mixins
// 引入变量和mixin函数
@import "variables.less"; //Bootstrap变量
@import "mixins.less"; //引入Bootstrap mixin工具函数 // Reset and dependencies
// 重置元素样式和依赖关系
@import "normalize.less"; //重置元素样式,统一浏览器显示
@import "print.less"; //设置打印样式
@import "glyphicons.less"; //icon图标 // Core CSS
// CSS全局样式
@import "scaffolding.less"; //重置元素样式,统一/增添Bootstrap样式。(盒模型宽度、字体大小、a鼠标样式、图片、sr-only和button)
@import "type.less"; //排版
@import "code.less"; //代码
@import "grid.less"; //定义栅格系统样式 (.container,.row和各.col-*-*)
@import "tables.less"; //表格
@import "forms.less"; //表单
@import "buttons.less"; //定义按钮基本样式 // Components
// 组件
@import "component-animations.less";
@import "dropdowns.less"; //下拉按钮
@import "button-groups.less"; //按钮组
@import "input-groups.less"; //表单元素样式
@import "navs.less"; //导航样式
@import "navbar.less"; //导航条样式
@import "breadcrumbs.less"; //眉毛链接
@import "pagination.less"; //分页导航
@import "pager.less"; //翻页 (上一页、下一页 .pager,.next,.previous,.disabled)
@import "labels.less"; //标签
@import "badges.less"; //徽章
@import "jumbotron.less"; //巨幕
@import "thumbnails.less"; //缩略图
@import "alerts.less"; //警告框
@import "progress-bars.less"; //进度条
@import "media.less"; //媒体对象
@import "list-group.less"; //列表组
@import "panels.less"; //面板
@import "responsive-embed.less"; //具有响应式特性的嵌入内容
@import "wells.less"; //把 Well 用在元素上,就能有嵌入(inset)的简单效果。
@import "close.less"; // Components w/ JavaScript
// JS插件
@import "modals.less"; //对话框样式
@import "tooltip.less"; //工具提示
@import "popovers.less"; //弹出框
@import "carousel.less"; //轮播 // Utility classes
// 实用工具类
@import "utilities.less"; //设置浮动,显示/隐藏,固定定位
@import "responsive-utilities.less"; //设置栅格系统中各列显示/隐藏,打印样式(col-*-*)
3.相关链接
4. 扩展:常用 less 代码
4.1 文件导入前缀
@import (reference) "main.less"; //引用LESS文件,但是不输出,不会编译出来
@import (inline) "main.less"; //引用LESS文件,但是不进行操作
@import (once) "main.less"; //引用LESS文件,但是不进行操作
@import (less) "index.css"; //无论是什么格式的文件,都把他作为LESS文件操作
@import (css) "main.less"; //无论是什么格式的文件,都把他作为CSS文件操作
4.2 动画
.transition(@property:all,@duration:1s,@timing-function:linear,@delay:0s){
//transition:@property @duration @timing-function @delay;
transition:@arguments;
-webkit-transition:@arguments;
-moz-transition:@arguments;
-ms-transition:@arguments;
-o-transition:@arguments;
} .wrap{
.transition(@duration:2s);
&:hover{
width:200px;
}
}
4.3 普通盒子 宽 高 背景色
/*------不加括号即是普通样式类,也是封装的一个函数,编译的时候,也会跟着编译加;括号仅仅是封装的函数,编译的时候不是编译函数-------*/
.pub(){ //-->不加括号会被编译出来,加了不会被编译出来
width: 100px;
height: 100px;
background: green;
}
.box2{
.pub(); //--->也可以 .pub;
background: red; }
4.4 1px 边框
.border-1px(@color:#e5e5e5){
position: relative;
&:after{
display: block;
position: absolute;
left:;
bottom:;
width: 100%;
border-top:1px solid @color;
content: '';
}
}
.box2{
width:100px;
height:100px;
.border-1px;
}
4.5 作为URL的变量
//作为URL的变量
@imgurl:"https://www.baidu.com/img/";
//引用
.box2{
width:100px;
height:100px;
background: url("@{imgurl}bdlogo.png");
}
4.6 //字体设置
@font_size: 14px; //默认字体大小
.font_s(@fs:@font_size){
font-size: @fs;
} @font_family: "microsoft yahei"; //默认字体颜色 .font_style(@fc: #333, @fs: @font_size, @ff: @font_family) { color: @fc; font-size: @fs; font-family: @ff; }
4.7 三角形
//三角样式---①
.triangle-less(top, @w:50px, @c:#ccc) {
border-color: transparent transparent @c transparent;
}
.triangle-less(bottom, @w:50px, @c:#ccc) {
border-color: @c transparent transparent transparent;
}
.triangle-less(left, @w:50px, @c:#ccc) {
border-color: transparent @c transparent transparent;
}
.triangle-less(right, @w:50px, @c:#ccc) {
border-color: transparent transparent transparent @c;
}
//@_ 匹配所有
.triangle-less(@_, @w:50px, @c:#ccc) {//传参保存一致,所以@w:50px和@c:#ccc也必须写上
width: 0;
height:;
border-width: @w;
border-style: solid;
} //引用
.box{
.triangle-less(top, 100px, green);
}
4.8 渐变
//渐变
.jh2(@color1,@color2,@dd:180deg){
background: -webkit-linear-gradient(@dd,@color1,@color2);
background: -moz-linear-gradient(@dd,@color1,@color2);
background: -ms-linear-gradient(@dd,@color1,@color2);
background: -o-linear-gradient(@dd,@color1,@color2);
background: linear-gradient(@dd,@color1,@color2);
}
.box2{
width:100px;
height:100px;
.jh2(red,pink);
}
4.9 圆角
//圆角
.border_radius(@radius:5px){
-wekit-border-radius: @radius;
-max-border-radius: @radius;
border-radius: @radius;
} .box2{
.border;
.border_radius;
width:200px;
height:200px;
}
4.10 溢出截断-
.subText() {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
4.11 flex 垂直居中
.flex(){
display: -webkit-box;
display: -moz-box;
display:-webkit-flex;
display: -ms-flexbox;
display:flex;
}
.flex-auto{
.flex();
-webkit-justify-content: center;
-moz-justify-content: center;
-ms-justify-content: center;
justify-content: center;
-webkit-align-items: center;
-moz-align-items: center;
-ms-align-items: center;
align-items: center;
}
4.12 1px
/*1像素*/
.borderLine(@color:#dcdcdc,@top:auto,@right:auto,@bottom:0,@left:0){
position: relative;
&::after{
content: '';
position: absolute;
left: @left;
bottom: @bottom;
right: @right;
top: @top;
height: 1px;
width: 100%;
background-color: @color;
display: block;
z-index:;
-webkit-transform-origin: 50% 100%;
transform-origin: 50% 100%;
}
}
.border-b{
.borderLine(@color:#dcdcdd,@top:auto,@right:auto,@bottom:0,@left:0)
} @media only screen and (-webkit-min-device-pixel-ratio: 2) {
.border-b:after {
-webkit-transform: scaleY(0.5);
transform: scaleY(0.5);
}
}
@media only screen and (-webkit-min-device-pixel-ratio: 3) {
.border-b::after {
-webkit-transform: scaleY(0.33);
transform: scaleY(0.33);
}
}
5.其他扩展
5.1 其他常用组件 less
/**
* 作品:mixin.less
* 更新:2017年12月14日
* 简介:1. 一个基于 Less 的样式工具库,封装了常用 mixin,帮助您更轻松地书写 Less 代码。
* 2. 只在调用时才输出代码,减少代码冗余,避免样式污染
* 3. 不自带兼容前缀,减少代码量,而建议采用工具生成,如 postcss、Autoprefixer、less-plugin-autoprefix 等
* 4. 附带 IE 各类 Hack
*/ /*-------------------------------------
├ 布局 ┆
└------------------------------------*/ // 盒子宽高
.size(@w, @h) { width: @w; height: @h; } // 最小尺寸, 兼容IE6
.min-width(@min-w) { min-width: @min-w; _width: @min-w; }
.min-height(@min-h) { min-height: @min-h; _height: @min-h; } // 内联块级元素, 兼容IE6
.dib() { display: inline-block; *display: inline; *zoom:; } // 固定定位, 兼容IE6
.fixed() { position: fixed; _position: absolute; *zoom:; } // 统一盒模型
.border-box() {
*, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
} // 文字图片居中
.center(text-x) { text-align: center; }
.center(text-y) { display: table-cell; vertical-align: middle; } // 块级元素水平居中
.center(auto-x) { display: block; margin-left: auto; margin-right: auto; } // 居中, 不确定尺寸, 不兼容 IE6
.center(unknown) { position: absolute; top:; left:; right:; bottom:; margin: auto; }
.center(unknown-x) { position: absolute; left:; right:; margin-left: auto; margin-right: auto; }
.center(unknown-y) { position: absolute; top:; bottom:; margin-top: auto; margin-bottom: auto; } // 居中, 确定尺寸, 兼容 IE6
.center(known, @w, @h) {
.size(@w, @h);
position: absolute; top: 50%; left: 50%; margin-top: -(@w / 2); margin-left: -(@h / 2);
}
.center(known-x, @w) {
width: @w;
position: absolute; left: 50%; margin-left: -(@h / 2);
}
.center(known-y, @h) {
height: @h;
position: absolute; top: 50%; margin-top: -(@w / 2);
} // 居中, CSS3 平移方式, 兼容性不行
.center(translate) { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); } // 居中, Flex 方式, 兼容性不行
.center(flex) { display: flex; align-items: center; justify-content: center; } // 多个子项布局
.list(float, @w: 25%) { float: left; width: @w; }
.list(inline, @w: 25%) { .dib(); width: @w; }
.list(flex) { flex:; } // 遮罩层, 全屏遮罩、区域遮罩
.over-screen(fixed) { .fixed(); top:; left:; right:; bottom:; }
.over-screen(absolute) { position: absolute; top:; left:; right:; bottom:; } // 容器宽高比固定
// 100* 1/1 = 100%
// 100* 3/4 = 75%
.fixed-ratio(@padding-top: 100%) {
position: relative; width: 100%; height:; padding-top: @padding-top;
img { position: absolute; top:; left:; width: 100%; height: 100%; }
} // 扩展点击区域
.extend-click() {
position: relative;
&:before { content: ''; position: absolute; top: -10px; left: -10px; right: -10px; bottom: -10px; }
} // 定宽居中页面布局
.layout-page(@width: 1200px) { width: @width; margin-left: auto; margin-right: auto; } // 侧边栏
// 主要区域:overflow: hidden; margin-left: xx; margin-right: xx;
.sidebar(left, @width) { position: absolute; top:; left:; width: @width; }
.sidebar(right, @width) { position: absolute; top:; right:; width: @width; } /*-------------------------------------
├ 字体 ┆
└------------------------------------*/ // 字体大小
.fz(@fz) { font-size: @fz; } // 字体大小与行高
.fz(@fz, @lh) { font-size: @fz; line-height: @lh; } // 字体大小、行高、高度
.fz(@fz, @h, @lh: @h) { font-size: @fz; height: @h; line-height: @lh; } // 行高与高度
.lh(@h, @lh: @h) { height: @h; line-height: @lh; } // 字体颜色, 包括链接与非链接
.color(@color) { color: @color;} // 字体颜色 + 自身 Hover
.color(@color, @hovercolor) {
color: @color;
&:hover { color: @hovercolor; }
} // 字体颜色 + 链接 Hover
.color(@color, @acolor, @hovercolor) {
color: @color;
a {
color: @acolor;
&:hover { color: @hovercolor; }
}
} // 正常字体样式
.normal-font() { font-weight: normal; font-style: normal; } // 辅助性文字(灰色)
.assist-font(@color: #b0b0b0, @fz: 14px) { color: @color; font-size: @fz; } // 禁止换行, 文本溢出省略号显示 (一行)
.ellipsis() {
white-space: normal; word-wrap: break-word; word-break: break-all;
-o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; text-overflow:ellipsis; overflow:hidden;
} // 文本溢出省略号显示 (多行)
// 只支持 webkit 浏览器, 解决方案:高度 = 行高*行数
// height: 90px; line-height: 30px; -webkit-line-clamp: 3;
.ellipsis-mult(@n: 3) {
display: -webkit-box; -webkit-box-orient: vertical;-webkit-line-clamp: @n; word-break: break-all;
-o-text-overflow: ellipsis; -ms-text-overflow: ellipsis; text-overflow:ellipsis; overflow: hidden;
} // 书写模式:牌匾从右至左水平单行排版效果、文笺从右至左、从上至下排版效果
.retext(x) { direction: rtl; unicode-bidi: bidi-override; }
.retext(y) { writing-mode: tb-rl; writing-mode: vertical-rl; } // 文字透明
.transparent-text() { font: 0/0 serif; text-shadow: none; color: transparent; } // 文字隐藏(常用于SEO优化)
// <a href="" title="Logo SEO 优化 "><h1 class="logo">xx</h1></a>
.hidden-text() { text-indent : -9999px; overflow: hidden; text-align: left; } // 文字外发光效果
.glow-text(@r: 10px, @color: gold) { text-shadow: 0 0 @r @color; } /*-------------------------------------
├ 图像 ┆
└------------------------------------*/ // 用 max-width 来防止图片撑破容器
.max-img() { display: block; max-width: 100%; height: auto; } // 2x 3x 背景图片
.bg-image(@url) {
background-image: url("@url + '@2x.png'");
@media (-webkit-min-device-pixel-ratio: 3), (min-device-pixel-ratio: 3) {
background-image: url("@url + '@3x.png'");
}
} // 全屏大图背景
.fullscreen-bg(@url) {
width: 100vw;
height: 100vh;
background: url(@url) no-repeat 50% 50%;
background-size: cover;
} // 滤镜: 将彩色照片显示为黑白照片
.grayscale() {
filter: grayscale(100%);
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
} /*-------------------------------------
├ 动效 ┆
└------------------------------------*/ // 链接默认无下划线,hover后有下划线的样式
.hover-link() {
text-decoration: none;
&:hover { text-decoration: underline; }
} // 将链接变成默认的文字样式
.unstyled-link() {
color: inherit;
cursor: inherit;
text-decoration: inherit;
&:active, &:focus { outline: none; }
} // 盒子阴影
// box-shadow: 水平阴影的位置, 垂直阴影的位置, 模糊距离, 阴影的大小, 阴影的颜色, 阴影开始方向(默认是从里往外,设置inset就是从外往里);
// box-shadow: h-shadow v-shadow blur spread color inset;
.box-shadow() {
box-shadow: 0px 14px 26px 0px rgba(0, 0, 0, 0.1);
} // 盒子 Hover
.box-hover() {
// box-shadow: 0px 1px 2px 0px rgba(84, 107, 107, .4);
transition: all .2s linear;
&:hover {
box-shadow: 0 15px 30px rgba(0, 0, 0, .1);
transform: translate3d(0, -2px, 0);
}
} .box-hover2() {
transition: transform .5s ease;
&:hover {
transform: translateX(10px);
}
} // 三维闪动 bug 处理
.transform-fix() { -webkit-backface-visibility: hidden; -webkit-transform-style: preserve-3d; } // Animation
.ani(@name, @time: 1s, @ease: ease-in-out, @fillmode: forwards) {
animation-name: @name;
animation-duration: @time;
animation-timing-function: @ease;
animation-fill-mode: @fillmode;
} /*-------------------------------------
├ 功能 ┆
└------------------------------------*/ // 浮动, 兼容 IE6
.fl() { float: left; *display: inline; _display:inline; }
.fr() { float: right; *display: inline; _display:inline; } // 清除浮动
.clearfix() {
*zoom:;
&:after { display: block; clear: both; content: ''; visibility: hidden; height:; }
}
.clearfix(table) {
*zoom:;
&:before, &:after { content: " "; display: table; clear: both; }
} // 禁止文本被选择
.user-select() { -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } // 隐藏鼠标手势
.hide-cursor() { cursor: none !important; } // 鼠标禁用样式,但仍然可以触发事件
// <input type="text" disabled="disabled">
.disabled() { cursor: not-allowed; } // 禁用元素事件
// 1. 阻止任何点击动作的执行
// 2. 使链接显示为默认光标(cursor:default)
// 3. 阻止触发hover和active状态
// 4. 阻止JavaScript点击事件的触发
.pointer-events() { pointer-events: none; } // 模糊
.blur(@blur: 10px) {
filter: blur(@blur);
-webkit-filter: blur(@blur);
-moz-filter: blur(@blur);
-o-filter: blur(@blur);
-ms-filter: blur(@blur);
filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius='@{blur}');
*zoom: 1;
} // 透明度, 兼容 IE8
.opacity(@opacity: 20) { opacity: @opacity / 100; filter: alpha(opacity=@opacity); } // 用伪类来显示打印时 a 标签的链接
.print-link() {
@media print {
a[href]:after { content: " (" attr(href) ") "; }
}
} // 隔行换色
.zebra-lists(odd, @color) {
&.odd {
>li:nth-child(odd) { background-color: @color; }
}
}
.zebra-lists(even, @color) {
&.even {
>li:nth-child(even) { background: green; }
}
} // 首字下沉
.first-letter(@font-size: 6em) {
&::first-letter{
float: left;
line-height:;
font-size: @font-size;
}
} // 特殊标记段落第一行
.first-line() {
&::first-line{
color: red
}
} // 美化选中文本
.beauty-select() {
&::selection{
color: #fff;
background-color: #6bc30d;
text-shadow: none;
}
} // 美化占位符 placeholder 样式
.beauty-placeholder(@fz, @color: #999, @align: left) {
&:-moz-placeholder { font-size: @fz; color: @color; text-align: @align; }
&:-ms-input-placeholder { font-size: @fz; color: @color; text-align: @align; }
&::-webkit-input-placeholder { font-size: @fz; color: @color; text-align: @align; }
} // 美化占位符 placeholder 样式(自定义属性和值)
.beauty-placeholder(custom, @property, @value) {
&:-moz-placeholder { @{property}: @value; }
&:-ms-input-placeholder { @{property}: @value; }
&::-webkit-input-placeholder { @{property}: @value; }
} /*-------------------------------------
├ 图形 ┆
└------------------------------------*/ // 三角形
.triangle(@width: 4px,@color: #000) {
display: inline-block;
width:;
height:;
vertical-align: middle;
border-top: @width solid @color;
border-left: @width solid transparent;
border-right: @width solid transparent;
} // 三角形箭头气泡效果, IE6-7 无表现
.arrow(top, @w: 10px, @color, @x: 50%) {
position: relative;
&:before { position: absolute; bottom: 100%; left: @x; content: " "; height:; width:; pointer-events: none; border-style: solid; border-color: transparent; border-bottom-color: @color; border-width: unit(@w, px); @margin: -@w; margin-left: unit(@margin, px); }
}
.arrow(right, @w: 10px, @color, @y: 50%) {
position: relative;
&:before { position: absolute; left: 100%; top: @y; content: " "; height:; width:; pointer-events: none; border-style: solid; border-color: transparent; border-left-color: @color; border-width: unit(@w, px); @margin: -@w; margin-top: unit(@margin, px); }
}
.arrow(bottom, @w: 10px, @color, @x: 50%) {
position: relative;
&:before { position: absolute; top: 100%; left: @x; content: " "; height:; width:; pointer-events: none; border-style: solid; border-color: transparent; border-top-color: @color; border-width: unit(@w, px); @margin: -@w; margin-left: unit(@margin, px); }
}
.arrow(left, @w: 10px, @color, @y: 50%) {
position: relative;
&:before { position: absolute; right: 100%; top: @y; content: " "; height:; width:; pointer-events: none; border-style: solid; border-color: transparent; border-right-color: @color; border-width: unit(@w, px); @margin: -@w; margin-top: unit(@margin, px); }
} // 三角形箭头气泡效果, 带边框
.arrow-with-border(top, @w: 10px, @color, @border-w: 1px, @border-color, @x: 50%) {
position: relative;
&:before, &:after { bottom: 100%; left: @x; content: " "; height:; width:; position: absolute; pointer-events: none; border-style: solid; border-color: transparent; }
&:after { border-bottom-color: @color; border-width: unit(@w, px); @margin: -@w; margin-left: unit(@margin, px); }
&:before { border-bottom-color: @border-color; @arrbo: @w+@border-w; border-width: unit(@arrbo, px); @margin-bo: -@arrbo; margin-left: unit(@margin-bo, px); }
}
.arrow-with-border(bottom, @w: 10px, @color, @border-w: 1px, @border-color, @x: 50%) {
position: relative;
&:before, &:after { top: 100%; left: @x; content: " "; height:; width:; position: absolute; pointer-events: none; border-style: solid; border-color: transparent; }
&:after { border-top-color: @color; border-width: unit(@w, px); @margin: -@w; margin-left: unit(@margin, px); }
&:before { border-top-color: @border-color; @arrbo: @w+@border-w; border-width: unit(@arrbo, px); @margin-bo: -@arrbo; margin-left: unit(@margin-bo, px); }
}
.arrow-with-border(left, @w: 10px, @color, @border-w: 1px, @border-color, @y: 50%) {
position: relative;
&:before, &:after { top: @y; right: 100%; content: " "; height:; width:; position: absolute; pointer-events: none; border-style: solid; border-color: transparent; }
&:after { border-right-color: @color; border-width: unit(@w, px); @margin: -@w; margin-top: unit(@margin, px); }
&:before { border-right-color: @border-color; @arrbo: @w+@border-w; border-width: unit(@arrbo, px); @margin-bo: -@arrbo; margin-top: unit(@margin-bo, px); }
}
.arrow-with-border(right, @w: 10px, @color, @border-w: 1px, @border-color, @y: 50%) {
position: relative;
&:before, &:after { top: @y; left: 100%; content: " "; height:; width:; position: absolute; pointer-events: none; border-style: solid; border-color: transparent; }
&:after { border-left-color: @color; border-width: unit(@w, px); @margin: -@w; margin-top: unit(@margin, px); }
&:before { border-left-color: @border-color; @arrbo: @w+@border-w; border-width: unit(@arrbo, px); @margin-bo: -@arrbo; margin-top: unit(@margin-bo, px); }
} /*-------------------------------------
├ 组件 ┆
└------------------------------------*/ // 吸顶导航
.fix-header(@h: 70px) {
.fixed();
top:;
left:;
width: 100%;
height: @h;
z-index:;
// background-color: rgba(256, 256, 256, .92);
// border-bottom: 1px solid rgba(7, 17, 27, 0.1);
// box-shadow: 0px 0px 20px rgba(0,0,0,0.2);
} // 吸底导航
.fix-header(@h: 70px) {
.fixed();
left:;
bottom:;
width: 100%;
height: @h;
z-index:;
} // 输入框
.input-text() {
display: block;
width: 100%;
padding: 4px 8px;
font-size: 14px;
line-height: 1.42858;
color: #333;
border: 1px solid #ddd;
background-color: #fff;
border-radius: 3px;
} // 分割线
// <span class="separator">|/-</span>
.separator() {
margin: 0 10px;
color: #999;
font-size: 14px;
} // 分割线 / (面包屑导航)
.separator2() {
&:before {
padding: 0 5px;
color: #ccc;
content: "/\00a0";
}
} // <hr class="hr">
// 支付宝:我也是有底线的
.hr() {
height: 1px;
margin: 10px 0;
border:;
clear: both;
background-color: #e2e2e2;
} // 改装的 fieldset
// <fieldset><legend>返璞归真</legend></fieldset>
.fieldset() {
border-color: #d2d2d2;
border-width: 1px 0 0;
border-style: solid;
legend {
padding: 0 20px;
text-align: center;
font-size: 20px;
font-weight:;
}
} // 引用区块(模仿 Layui)
// <div class="blockquote">Lorem ipsum dolor sit amet.</div>
.blockquote() {
margin-bottom: 10px;
padding: 15px;
line-height: 22px;
border-left: 5px solid #009688;
border-radius: 0 2px 2px 0;
background-color: #f2f2f2;
} // 徽章 (椭圆、小圆点)
// <span class="badge">10</span>
.badge(...) {
position: relative;
display: inline-block;
font-size: 12px;
color: #fff;
background-color: #FF5722;
}
.badge(ellipse) {
min-width: 8px;
height: 18px;
padding: 2px 6px;
text-align: center;
line-height: 18px;
border-radius: 9px;
}
.badge(dot) {
width: 8px;
height: 8px;
border-radius: 50%;
} // 关闭按钮
// <button class="close" type="button"><span>×</span></button>
.close() {
position: relative;
-webkit-appearance: none;
padding:;
cursor: pointer;
background: 0 0;
border:;
font-size: 20px;
font-weight:;
line-height:;
color: #000;
text-shadow: 0 1px 0 #fff;
filter: alpha(opacity=20);
opacity: .2;
&:hover {
color: #000;
text-decoration: none;
cursor: pointer;
filter: alpha(opacity=50);
opacity: .5;
}
&:before {
content: '';
position: absolute;
top: -10px;
left: -10px;
right: -10px;
bottom: -10px;
}
} // 1 像素边框问题
.onepx(...) {
position: relative;
&:after {
content: '';
display: block;
position: absolute;
left:;
width: 100%;
border-top: 1px solid rgba(7, 17, 27, 0.1);
transform: scaleY(0.5);
}
}
.onepx(top) { &:after { top: 0; } }
.onepx(bottom) { &:after { bottom: 0; } }
.onepx-easy(top, @color: #ccc) { box-shadow: inset 0px -1px 1px -1px @color; }
.onepx-easy(bottom, @color: #ccc) { box-shadow: inset 0px 1px 1px -1px @color; }
5.2 reset
@charset "utg-8";
/* CSS Document */
html,body,h1,h2,h3,h4,h5,h6,div,dl,dt,dd,ul,ol,li,p,blockquote,pre,hr,figure,table,caption,th,td,form,fieldset,legend,input,button,textarea,menu{margin:;padding:;}
body{ background-color:#fff;}
html,body,fieldset,img,iframe,abbr{border:;}
li{list-style:none;}
textarea{overflow:auto;resize:none;}
a,button{cursor:pointer;}
h1,h2,h3,h4,h5,h6,em,strong,b{font-weight:bold;}
a,a:hover{text-decoration:none;}
body,textarea,input,button{
color:#62a1c9;
} html,body{
width:100%;
min-height: 930px;
height: auto;
} .hide{
display: none;
} .text-shadow (@string: 0 1px 3px rgba(0, 0, 0, 0.25)) {
text-shadow: @string;
}
.box-shadow (@string) {
-webkit-box-shadow: @string;
-moz-box-shadow: @string;
box-shadow: @string;
}
.drop-shadow (@x: 0, @y: 1px, @blur: 2px, @spread: 0, @alpha: 0.25) {
-webkit-box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);
-moz-box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);
box-shadow: @x @y @blur @spread rgba(0, 0, 0, @alpha);
}
.inner-shadow (@x: 0, @y: 1px, @blur: 2px, @spread: 0, @alpha: 0.25) {
-webkit-box-shadow: inset @x @y @blur @spread rgba(0, 0, 0, @alpha);
-moz-box-shadow: inset @x @y @blur @spread rgba(0, 0, 0, @alpha);
box-shadow: inset @x @y @blur @spread rgba(0, 0, 0, @alpha);
} .box-sizing (@type: border-box) {
-webkit-box-sizing: @type;
-moz-box-sizing: @type;
box-sizing: @type;
} .border-radius (@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius; -moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
}
.border-radiuses (@topright: 0, @bottomright: 0, @bottomleft: 0, @topleft: 0) {
-webkit-border-top-right-radius: @topright;
-webkit-border-bottom-right-radius: @bottomright;
-webkit-border-bottom-left-radius: @bottomleft;
-webkit-border-top-left-radius: @topleft; -moz-border-radius-topright: @topright;
-moz-border-radius-bottomright: @bottomright;
-moz-border-radius-bottomleft: @bottomleft;
-moz-border-radius-topleft: @topleft; border-top-right-radius: @topright;
border-bottom-right-radius: @bottomright;
border-bottom-left-radius: @bottomleft;
border-top-left-radius: @topleft; -moz-background-clip: padding;
-webkit-background-clip: padding-box;
background-clip: padding-box;
} .opacity (@opacity: 0.5) {
@tempOpacity: @opacity * 100;
-webkit-opacity: @opacity;
-moz-opacity: @opacity;
opacity: @opacity;
filter:alpha(opacity=@tempOpacity);
} .gradient (@startColor: #eee, @endColor: white) {
background-color: @startColor;
background: -webkit-gradient(linear, left top, left bottom, from(@startColor), to(@endColor));
background: -webkit-linear-gradient(top, @startColor, @endColor);
background: -moz-linear-gradient(top, @startColor, @endColor);
background: -ms-linear-gradient(top, @startColor, @endColor);
background: -o-linear-gradient(top, @startColor, @endColor);
}
.horizontal-gradient (@startColor: #eee, @endColor: white) {
background-color: @startColor;
background-image: -webkit-gradient(linear, left top, right top, from(@startColor), to(@endColor));
background-image: -webkit-linear-gradient(left, @startColor, @endColor);
background-image: -moz-linear-gradient(left, @startColor, @endColor);
background-image: -ms-linear-gradient(left, @startColor, @endColor);
background-image: -o-linear-gradient(left, @startColor, @endColor);
background-image: linear-gradient(left, @startColor, @endColor);
} .animation (@name, @duration: 300ms, @delay: 0, @ease: ease) {
-webkit-animation: @name @duration @delay @ease;
-moz-animation: @name @duration @delay @ease;
-ms-animation: @name @duration @delay @ease;
animation: @name @duration @delay @ease;
} .transition (@transition) {
-webkit-transition: @transition;
-moz-transition: @transition;
-ms-transition: @transition;
-o-transition: @transition;
transition: @transition;
}
.transform(@string){
-webkit-transform: @string;
-moz-transform: @string;
-ms-transform: @string;
-o-transform: @string;
transform: @string;
}
.scale (@factor) {
-webkit-transform: scale(@factor);
-moz-transform: scale(@factor);
-ms-transform: scale(@factor);
-o-transform: scale(@factor);
transform: scale(@factor);
}
.rotate (@deg) {
-webkit-transform: rotate(@deg);
-moz-transform: rotate(@deg);
-ms-transform: rotate(@deg);
-o-transform: rotate(@deg);
transform: rotate(@deg);
}
.skew (@deg, @deg2) {
-webkit-transform: skew(@deg, @deg2);
-moz-transform: skew(@deg, @deg2);
-ms-transform: skew(@deg, @deg2);
-o-transform: skew(@deg, @deg2);
transform: skew(@deg, @deg2);
}
.translate (@x, @y:0) {
-webkit-transform: translate(@x, @y);
-moz-transform: translate(@x, @y);
-ms-transform: translate(@x, @y);
-o-transform: translate(@x, @y);
transform: translate(@x, @y);
}
.translate3d (@x, @y: 0, @z: 0) {
-webkit-transform: translate3d(@x, @y, @z);
-moz-transform: translate3d(@x, @y, @z);
-ms-transform: translate3d(@x, @y, @z);
-o-transform: translate3d(@x, @y, @z);
transform: translate3d(@x, @y, @z);
}
.perspective (@value: 1000) {
-webkit-perspective: @value;
-moz-perspective: @value;
-ms-perspective: @value;
perspective: @value;
}
.transform-origin (@x:center, @y:center) {
-webkit-transform-origin: @x @y;
-moz-transform-origin: @x @y;
-ms-transform-origin: @x @y;
-o-transform-origin: @x @y;
transform-origin: @x @y;
} .keyframes(@name, @frames) {
@-webkit-keyframes @name { @frames(); }
@-moz-keyframes @name { @frames(); }
@-ms-keyframes @name { @frames(); }
@-o-keyframes @name { @frames(); }
@keyframes @name { @frames(); }
} .animation(@arg){
-moz-animation:@arg;
-webkit-animation:@arg;
-o-animation:@arg;
-ms-animation:@arg;
animation:@arg;
}
5.3 手机端 rem
关键代码 js
(function(doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function() {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
if(clientWidth>=750){
docEl.style.fontSize = '100px'
}else{
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
} };
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
unit less
@size: 100*1rem;
/*修改大小的函数*/
.width(@num) {
width: @num / @size;
} .height(@num) {
height: @num / @size;
}
web less
.wrap{ .width(100); }
6.参考链接
less 经典范例 bootstrap 的 less 版本 常用 less 代码的更多相关文章
- asp.net的3个经典范例(ASP.NET Starter Kit ,Duwamish,NET Pet Shop)学习资料
asp.net的3个经典范例(ASP.NET Starter Kit ,Duwamish,NET Pet Shop)学习资料 NET Pet Shop .NET Pet Shop是一个电子商务的实例, ...
- HTML 5+CSS 3网页设计经典范例 (李俊民,黄盛奎) 随书光盘
<html 5+css 3网页设计经典范例(附cd光盘1张)>共分为18章,涵盖了html 5和css3中各方面的技术知识.主要内容包括html 5概述.html 5与html 4的区别. ...
- IOS开发-OC学习-常用功能代码片段整理
IOS开发-OC学习-常用功能代码片段整理 IOS开发中会频繁用到一些代码段,用来实现一些固定的功能.比如在文本框中输入完后要让键盘收回,这个需要用一个简单的让文本框失去第一响应者的身份来完成.或者是 ...
- SAP FI CO模块常用事务代码
...
- legend3---lavarel常用操作代码
legend3---lavarel常用操作代码 一.总结 一句话总结: 要自己总结一下常用代码,这样才方便,也才有收获 1.路由示例:Route::get('/login','Home\Login\L ...
- NC65在日常开发中常用的代码写法
标题 NC65开发相关代码 版本 1.0.1 作者 walton 说明 收集NC在日常开发中常用的代码写法,示例展示 1.查询 1.1 通过BaseDAO查询结果集并转换 //通过BaseDAO进行查 ...
- 工作中总结的常用PHP代码
[目录] ◆PHP常用的代码 ◆HTML常用代码 [值传递 和 引用传递] [单例模式] [魔术常量] [代码调试(自定义一个简单的debug函数)] [thinkphp多表查询] [获取客户端IP地 ...
- 10个经典的C语言面试基础算法及代码
10个经典的C语言面试基础算法及代码作者:码农网 – 小峰 原文地址:http://www.codeceo.com/article/10-c-interview-algorithm.html 算法是一 ...
- IOS开发效率之为Xcode添加常用的代码片段
IOS开发效率之为Xcode添加常用的代码片段 原文地址:http://blog.csdn.net/pingchangtan367/article/details/30041285 tableview ...
随机推荐
- yum源问题
配置本地yum源 1.使用工具将iso文件上传到操作系统,或者直接挂载iso文件 2.配置yum #cd /etc/yum.repos.d/ 删除多余的repo文件 # vi /etc/yum.rep ...
- Cortex-M3 R0~R15寄存器组 & 特殊功能寄存器组
[R0~R15寄存器组] Cortex-M3处理器拥有R0~R15的寄存器组,如: [R0~R12通用寄存器]R0~R12都是32位通用寄存器,用于数据操作.其中: R0~R7为低组寄存器,所有的指令 ...
- openerp学习笔记 tree视图增加复选处理按钮
wizard:用于确认或选择 wizard/sale_multi_action.py # -*- encoding: utf-8 -*-from openerp.osv import fields, ...
- html+xml+servlet 通讯录案例demo
首先导入dom4j和xPath技术以及测试对应的jar包 package com.loaderman.demo.entity; /** * 实体对象 * @author APPle * */ publ ...
- Python re 正则表达式【一】【转】
数量词的贪婪模式与非贪婪模式 正则表达式通常用于在文本中查找匹配的字符串.Python里数量词默认是贪婪的(在少数语言里也可能是默认非贪婪),总是尝试匹配尽可能多的字符:非贪婪的则相反,总是尝试匹配尽 ...
- 2019.11.07【每天学点SAP小知识】Day2 - ABAP 7.40新语法 - 内表
今天学习一下内表的表达式在ABAP 7.4之后的语法: SELECT * FROM mara INTO TABLE @DATA(gt_mara)UP TO 10 ROWS. DATA gt_mara_ ...
- 如何在VUE中使用leaflet地图框架
前言:在leaflet的官方文档只有静态的HTML演示并没有结合VUE的demo 虽然也有一些封装好的leaflet库例如Vue-Leaflet,但是总感觉用起来不是那么顺手,有些业务操作还是得用l ...
- 微信小程序省市区联动,自定义地区字典
最近在做一个项目的时候遇到了这么一个问题,就是省市区的联动呢,我们需要自定义字典来设置,那么微信小程序自带的省市区选择就不能用了,经过三根烟的催化,终于写出来了.下面献上代码示例. 首先是在utils ...
- 【JulyEdu-Python基础】第 3 课:容器以及容器的访问使用
大纲 容器切片 list/tupledictset 切片 列表推导 生成器 迭代器 容器 list 列表 序列是Python中最基本的数据结构.序列中的每个元素都分配一个数字 - 它的位置,或索引,第 ...
- 【经典问题】maximum subset sum of vectors
AtCoder Beginner Contest 139 Task F Engines 题目大意 给定 $n$ 个二维向量,从中选出若干个,使得它们的和的模最大. 分析 这是一个经典问题,还有一种提法 ...