本来想看看栅格系统,但后来发现有点多,而且个人有些懒了,就看看button组件算了。做个笔记,缓解下枯燥烦闷的自学。
minxin文件夹中的buttons.less 文件规定按钮 伪类,按钮颜色,禁用选项,主要是用来给上一级文件夹中对应buttons.less调用。其中内容如下:
.button-variant(@color; @background; @border) {
color: @color;
background-color: @background;
border-color: @border;
&:focus,
&.focus {
color: @color;
background-color: darken(@background, 10%);
border-color: darken(@border, 25%);
}
&:hover {
color: @color;
background-color: darken(@background, 10%);
border-color: darken(@border, 12%);
}
&:active,
&.active,
.open > .dropdown-toggle& {
color: @color;
background-color: darken(@background, 10%);
border-color: darken(@border, 12%);
&:hover,
&:focus,
&.focus {
color: @color;
background-color: darken(@background, 17%);
border-color: darken(@border, 25%);
}
}
&:active,
&.active,
.open > .dropdown-toggle& {
background-image: none;
}
&.disabled,
&[disabled],
fieldset[disabled] & {
&:hover,
&:focus,
&.focus {
background-color: @background;
border-color: @border;
}
}
.badge {
color: @background;
background-color: @color;
}
}
再来看看less文件夹下buttons.less,规定按钮基础样式,默认备用按钮,按钮模拟a链接标签(可能是我菜,搞不懂为何如此使用),按钮大小,按钮(inline-block)转成块级元素(block),兄弟按钮之间添加高度,特殊属性的input默认样式重写
.btn {
display: inline-block;
margin-bottom: 0; // For input.btn
font-weight: @btn-font-weight;
text-align: center;
vertical-align: middle;
touch-action: manipulation;
cursor: pointer;
background-image: none; // Reset unusual Firefox-on-Android default style; see https://github.com/necolas/normalize.css/issues/214
border: 1px solid transparent;
white-space: nowrap;
.button-size(@padding-base-vertical; @padding-base-horizontal; @font-size-base; @line-height-base; @btn-border-radius-base);
.user-select(none);
&,
&:active,
&.active {
&:focus,
&.focus {
.tab-focus();
}
}
&:hover,
&:focus,
&.focus {
color: @btn-default-color;
text-decoration: none;
}
&:active,
&.active {
outline: 0;
background-image: none;
.box-shadow(inset 0 3px 5px rgba(0,0,0,.125));
}
&.disabled,
&[disabled],
fieldset[disabled] & {
cursor: @cursor-disabled;
.opacity(.65);
.box-shadow(none);
}
a& {
&.disabled,
fieldset[disabled] & {
pointer-events: none; // Future-proof disabling of clicks on `` elements
}
}
}
.btn-default {
.button-variant(@btn-default-color; @btn-default-bg; @btn-default-border);
}
备用按钮,里面有些我们国内不常用的警告,危险,成功什么的。调用mixin文件同名less文件的类
.btn-link {
color: @link-color;
font-weight: normal;
border-radius: 0;
&,
&:active,
&.active,
&[disabled],
fieldset[disabled] & {
background-color: transparent;
.box-shadow(none);
}
&,
&:hover,
&:focus,
&:active {
border-color: transparent;
}
&:hover,
&:focus {
color: @link-hover-color;
text-decoration: @link-hover-decoration;
background-color: transparent;
}
&[disabled],
fieldset[disabled] & {
&:hover,
&:focus {
color: @btn-link-disabled-color;
text-decoration: none;
}
}
}
.btn-lg {
// line-height: ensure even-numbered height of button next to large input
.button-size(@padding-large-vertical; @padding-large-horizontal; @font-size-large; @line-height-large; @btn-border-radius-large);
}
.btn-sm {
// line-height: ensure proper height of button next to small input
.button-size(@padding-small-vertical; @padding-small-horizontal; @font-size-small; @line-height-small; @btn-border-radius-small);
}
.btn-xs {
.button-size(@padding-xs-vertical; @padding-xs-horizontal; @font-size-small; @line-height-small; @btn-border-radius-small);
}
// Button sizes
.button-size(@padding-vertical; @padding-horizontal; @font-size; @line-height; @border-radius) {
padding: @padding-vertical @padding-horizontal;
font-size: @font-size;
line-height: @line-height;
border-radius: @border-radius;
}
里面设置好内边距,字体大小,行距,边框圆角
接下来就简单了,按钮转块级元素,兄弟按钮垂直方向给个外边距,特殊属性的input进行宽度重写
.btn-block {
display: block;
width: 100%;
}
// Vertically space out multiple block buttons
.btn-block + .btn-block {
margin-top: 5px;
}
// Specificity overrides
input[type="submit"],
input[type="reset"],
input[type="button"] {
&.btn-block {
width: 100%;
}
}
到此,button组件less文件表层研究完毕,里面使用的无非就是平时网页经常用到的按钮颜色,鼠标事件,背景图片,规定好大中小尺寸,圆角等一切属性。简单吧?嗯,表面上看挺简单的,当然,如果不是为了学习移动端布局,我还不知道有这么个东西。
果然自己渣渣不是环境不好,而是知道的太少!
PS:比起zepto.js源码,我觉得很爽!!!!