当前位置: 首页 > 编程日记 > 正文

Bootstrap3.x - 源代码分析

参照http://v3.bootcss.com/css/ 文档与源代码

colors

比较全面定义总结有意义的颜色。所有uI要用的颜色,都先从已定义的读,这样保证样式的同一性,而且方便以后开发主题库。(建议想自己写css模块的,可以参考一下bootstrap里颜色定义)

  • 语义颜色(四钟颜色)
    有含义的颜色,当然也可以不止这四种,如:disabled、empty
@brand-success:         #5cb85c; // 成功颜色
@brand-info:            #5bc0de; // 信息颜色
@brand-warning:         #f0ad4e; // 警告颜色
@brand-danger:          #d9534f; // 危险颜色
  • 灰度颜色
    主要包含文本、文字、背景色等。
@gray-base:              #000;   // 基本的灰度
@gray-darker:            lighten(@gray-base, 13.5%); // #222
@gray-dark:              lighten(@gray-base, 20%);   // #333
@gray:                   lighten(@gray-base, 33.5%); // #555
@gray-light:             lighten(@gray-base, 46.7%); // #777
@gray-lighter:           lighten(@gray-base, 93.5%); // #eee
  • 文字、背景色、链接状态
@body-bg:               #fff;
@text-color:            @gray-dark;
@link-color:            @brand-primary;
@link-hover-color:      darken(@link-color, 15%);
@link-hover-decoration: underline;

字体

字体大小必须是在已有基础上,做计算。从h1~h4间隔都是6px;h5~h6分别是14px、12px;而14是基础字体

@font-family-sans-serif:  "Helvetica Neue", Helvetica, Arial, sans-serif;
@font-family-serif:       Georgia, "Times New Roman", Times, serif;
@font-family-monospace:   Menlo, Monaco, Consolas, "Courier New", monospace;
@font-family-base:        @font-family-sans-serif;@font-size-base:          14px;
@font-size-large:         ceil((@font-size-base * 1.25)); // ~18px
@font-size-small:         ceil((@font-size-base * 0.85)); // ~12px@font-size-h1:            floor((@font-size-base * 2.6)); // ~36px
@font-size-h2:            floor((@font-size-base * 2.15)); // ~30px
@font-size-h3:            ceil((@font-size-base * 1.7)); // ~24px
@font-size-h4:            ceil((@font-size-base * 1.25)); // ~18px
@font-size-h5:            @font-size-base;
@font-size-h6:            ceil((@font-size-base * 0.85)); // ~12px

行高

但是它不仅局限在行高上,可以推算出高度,已知字体大小与行高时
如:@line-height-computed: floor((@font-size-base * @line-height-base));//20px
一些通用的组件属性都需要这个值,margin、padding、top、height、line-height...
所以定义好字体大小与行高的重要性不言而喻了吧。

//'line-height' for use in components like buttons.
@line-height-base:        1.428571429; // 20/14

padding与border-radius

bootstrap 有关尺寸命名的格式"-xs-" 有四种尺寸: xs、small、base、large。
而上下、左右的是:-vertical--horizontal-

@padding-base-vertical:     6px;
@padding-base-horizontal:   12px;@padding-large-vertical:    10px;
@padding-large-horizontal:  16px;@padding-small-vertical:    5px;
@padding-small-horizontal:  10px;@padding-xs-vertical:       1px;
@padding-xs-horizontal:     5px;@line-height-large:         1.33;
@line-height-small:         1.5;@border-radius-base:        4px;
@border-radius-large:       6px;
@border-radius-small:       3px;

Z-index

有时关于设置z-index时,我们会乱掉,只要不遮盖就行,但是有问题时,难修改、难排查;一般我们uI上有bug,会先从js上排查,最后才到css;即使找到了,发现需要一层一层的往父级找。因此可以在最初时写的时候避免它,先定义好,再使用。

@zindex-navbar:            1000;
@zindex-dropdown:          1000;
@zindex-popover:           1060;
@zindex-tooltip:           1070;
@zindex-navbar-fixed:      1030;
@zindex-modal:             1040;

操作伪类

有用户操作动作的,需要定义伪类样式如:active,hover,focus,disabled
有些组件有可能是多个或者是一个的伪类,最好在定义基础样式时,预先定好。
不一定只有伪类定义,也可以定义类似伪类的类如:.active,.hover,.focus,.disabled。

//buttons
.btn {display: inline-block;margin-bottom: 0; // For input.btnfont-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/214border: 1px solid transparent;white-space: nowrap;.button-size(@padding-base-vertical; @padding-base-horizontal; @font-size-base; @line-height-base; @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;pointer-events: none; // Future-proof disabling of clicks.opacity(.65);.box-shadow(none);}
}

栅格系统

bootstrap最核心的就是栅格系统。

  • 创造了.col-xs-1~.col-xs-12、.col-sm-1~.col-sm-12、.col-md-1~.col-md-12、.col-lg-1~.col-lg-12类的样式

.make-grid-columns() {// 先循环出.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1.col(@index) when (@index = 1) { // initial@item: ~".col-xs-@{index}, .col-sm-@{index}, .col-md-@{index}, .col-lg-@{index}";.col((@index + 1), @item);}//再把.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1,与之后的递增的类拼接起来形成// .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1,.col-xs-2, .col-sm-2, .col-md-2, .col-lg-2,//.col-xs-1, .col-sm-1, .col-md-1, .col-lg-1,.col-xs-3, .col-sm-3, .col-md-3, .col-lg-3,.col(@index, @list) when (@index =< @grid-columns) { // general; "=<" isn't a typo@item: ~".col-xs-@{index}, .col-sm-@{index}, .col-md-@{index}, .col-lg-@{index}";.col((@index + 1), ~"@{list}, @{item}");}//最后把4*12 = 48 个类的样式统一设置.col(@index, @list) when (@index > @grid-columns) { // terminal@{list} {position: relative;// Prevent columns from collapsing when emptymin-height: 1px;// Inner gutter via paddingpadding-left:  (@grid-gutter-width / 2);padding-right: (@grid-gutter-width / 2);}}.col(1); // kickstart it
}
  • 为每个带col-xs-x, .col-sm-x, .col-md-x, .col-lg-x;添加浮动。
.float-grid-columns(@class) {.col(@index) when (@index = 1) { // initial@item: ~".col-@{class}-@{index}";.col((@index + 1), @item);}.col(@index, @list) when (@index =< @grid-columns) { // general@item: ~".col-@{class}-@{index}";.col((@index + 1), ~"@{list}, @{item}");}.col(@index, @list) when (@index > @grid-columns) { // terminal@{list} {float: left;}}.col(1); // kickstart it
}
  • 添加列偏移列排序,计算各个的宽度
.calc-grid-column(@index, @class, @type) when (@type = width) and (@index > 0) {.col-@{class}-@{index} {width: percentage((@index / @grid-columns));}
}
.calc-grid-column(@index, @class, @type) when (@type = push) and (@index > 0) {.col-@{class}-push-@{index} {left: percentage((@index / @grid-columns));}
}
.calc-grid-column(@index, @class, @type) when (@type = push) and (@index = 0) {.col-@{class}-push-0 {left: auto;}
}
.calc-grid-column(@index, @class, @type) when (@type = pull) and (@index > 0) {.col-@{class}-pull-@{index} {right: percentage((@index / @grid-columns));}
}
.calc-grid-column(@index, @class, @type) when (@type = pull) and (@index = 0) {.col-@{class}-pull-0 {right: auto;}
}
.calc-grid-column(@index, @class, @type) when (@type = offset) {.col-@{class}-offset-@{index} {margin-left: percentage((@index / @grid-columns));}
}
  • 最后是调用
@grid-columns:12;
// Basic looping in LESS
.loop-grid-columns(@index, @class, @type) when (@index >= 0) {.calc-grid-column(@index, @class, @type);// next iteration.loop-grid-columns((@index - 1), @class, @type);
}// Create grid for specific class
.make-grid(@class) {.float-grid-columns(@class);.loop-grid-columns(@grid-columns, @class, width);.loop-grid-columns(@grid-columns, @class, pull);.loop-grid-columns(@grid-columns, @class, push);.loop-grid-columns(@grid-columns, @class, offset);
}.make-grid-columns();.make-grid(xs);@media (min-width: @screen-sm-min) {.make-grid(sm);
}@media (min-width: @screen-md-min) {.make-grid(md);
}@media (min-width: @screen-lg-min) {.make-grid(lg);
}

mixins

border-radius

.border-top-radius(@radius) {border-top-right-radius: @radius;border-top-left-radius: @radius;
}
.border-right-radius(@radius) {border-bottom-right-radius: @radius;border-top-right-radius: @radius;
}
.border-bottom-radius(@radius) {border-bottom-right-radius: @radius;border-bottom-left-radius: @radius;
}
.border-left-radius(@radius) {border-bottom-left-radius: @radius;border-top-left-radius: @radius;
}

backgrounds

.bg-variant(@color) {background-color: @color;a&:hover {background-color: darken(@color, 10%);}
}

center-block

.center-block() {display: block;margin-left: auto;margin-right: auto;
}

clearfix

.clearfix() {&:before,&:after {content: " "; // 1display: table; // 2}&:after {clear: both;}
}

hide-text

.hide-text() {font: ~"0/0" a;color: transparent;text-shadow: none;background-color: transparent;border: 0;
}

img-responsive、.img-retina

.img-responsive(@display: block) {display: @display;max-width: 100%; // Part 1: Set a maximum relative to the parentheight: auto; // Part 2: Scale the height according to the width, otherwise you get stretching
}.img-retina(@file-1x; @file-2x; @width-1x; @height-1x) {background-image: url("@{file-1x}");@mediaonly screen and (-webkit-min-device-pixel-ratio: 2),only screen and (   min--moz-device-pixel-ratio: 2),only screen and (     -o-min-device-pixel-ratio: 2/1),only screen and (        min-device-pixel-ratio: 2),only screen and (                min-resolution: 192dpi),only screen and (                min-resolution: 2dppx) {background-image: url("@{file-2x}");background-size: @width-1x @height-1x;}
}

opacity

.opacity(@opacity) {opacity: @opacity;// IE8 filter@opacity-ie: (@opacity * 100);filter: ~"alpha(opacity=@{opacity-ie})";
}

text-overflow

.text-overflow() {overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
}

Vendor Prefixes

在vendor-prefixes.less里包含了

  1. Animations、Backface visibility
  2. Box shadow
  3. Box sizing
  4. Content columns
  5. Hyphens
  6. Placeholder text
  7. Transformations
  8. Transitions
  9. User Select

以上是看bootstrap源码的初步理解与感悟,都是自己感觉重要与技巧的总结;如有不足之处请多多指教。
最后在前端的道路上蹒跚前行着。

相关文章:

清除Squid缓存的小工具

[ 2007-11-2 17:49 | by 张宴 ] 以前我写过一篇《清除指定squid缓存文件的脚本》&#xff0c;但在取URL时存在10%的错误率。如今找到一款老外的程序&#xff0c;可以批量清除某类URL的Squid缓存&#xff0c;支持正则表达式。下载网址&#xff1a;http://www.wa.apana.org.au/~d…

谷歌 AI 编舞师,连张艺兴最喜欢的 Krump 都不在话下

编译 | 禾木木 出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09; 舞蹈一直是文化、仪式和庆祝活动的重要组成部分&#xff0c;也是一种自我表达的方式。今天&#xff0c;存在多种形式的舞蹈&#xff0c;从舞厅到迪斯科。然而&#xff0c;舞蹈是一种需要练习的艺术形…

Python 字典(Dictionary)

Python 字典(Dictionary)字典是另一种可变容器模型&#xff0c;且可存储任意类型对象。字典的每个键值(key>value)对用冒号(:)分割&#xff0c;每个对之间用逗号(,)分割&#xff0c;整个字典包括在花括号({})中 ,格式如下所示&#xff1a;d {key1 : value1, key2 : value2 …

Varnish Cache 3.0.0安装

https://www.varnish-cache.org/installation/redhat Installation on RedHat 先按需要的模块 在安装软件包之前首先看看主机上的 automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig软件包是否已经安装 如果没有那么就要首先安装&#xff…

three.js绘制过程(二)

2019独角兽企业重金招聘Python工程师标准>>> 同一个场景中可以有多个摄像机&#xff0c;同一个屏幕缓冲区可以分块绘制不同的物体。 WeblGLRender 中autoClear 设定为false之后&#xff0c; 每次绘制不会清空缓冲区&#xff1b; setSize 设定canvas的大小 setViewpo…

AI 不可以作为专利认证发明人,“因为它不是人”

编译 | 禾木木 出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09; 英格兰和威尔士上诉法院本周驳回了一名男子的请求&#xff0c;该男子要求法院承认他的人工智能系统为两项专利的发明者。 总部位于美国的 Imagination Engines 的创始人 Stephen Thaler 想要给智能机器…

使用工作集(Working Set)整理项目

Eclipse鼓励将不同的功能模块划分为独立的项目存在&#xff0c;这样不但结构清晰&#xff0c;组织起来还非常灵活&#xff0c;因为我们可以用feature对这些项目进行不同的组合&#xff0c;输出后得到具有不同功能的产品。 不过这样一来Package Explorer里的项目会以更快的速度增…

深入探讨Varnish缓存命中率

也许你还在为刚才动态内容获得7336.76 reqs/s的吞吐率感到振奋&#xff0c;等等&#xff0c;理想和现实是有差距的&#xff0c;你要忍受现实的残酷&#xff0c;别忘了&#xff0c;我们压力测试中的动态内容都处于全缓存情况下&#xff0c;也就是每次请求都命中缓存&#xff0c;…

网易有道词典笔 —— 73 岁“人类高质量”奶奶梅耶马斯克的中文学习之选

继埃隆马斯克发微博称7000年后英语将不复存在后&#xff0c;他的忠实粉丝&#xff0c;同时也是他的母亲——梅耶马斯克也正式开启了学习新语言行动&#xff0c;值得注意的是&#xff0c;梅耶的语种选择是中文。近日&#xff0c;埃隆马斯克的母亲——梅耶马斯克使用有道词典笔学…

Android类库打包方法探究

为什么80%的码农都做不了架构师&#xff1f;>>> 开发Android应用的时候&#xff0c;对于可用于多个应用的公用的部分&#xff0c;或是打算发布给第三方进行应用集成的部分&#xff0c;要把这部分打包成类库怎么做呢? 众所周知&#xff0c;Android应用使用ADT打包成…

大叔也说并行和串行`性能提升N倍(N由操作系统位数和cpu核数决定)

并行是.net4.5主打的技术&#xff0c;同时被封装到了System.Threading.Tasks命名空间下&#xff0c;对外提供了静态类Parallel&#xff0c;我们可以直接使用它的静态方法&#xff0c;它可以并行一个委托数组&#xff0c;或者一个IEnumerable的迭代&#xff0c;而今天主要通过一…

这7个开源技术,支撑起整个互联网时代

转载自 钛媒体 - 这7个开源技术&#xff0c;支撑起整个互联网时代 开源软件现在成为整个互联网时代的支撑技术&#xff0c;你可能已经无法离开由开源软件构建起来的网络世界了。下面我们就来看看一些最重要的开源技术。 为互联网而生的操作系统linux Linux是一款免费的操作系统…

WebDriver 识别反爬虫的原理和破解方法~

作者|志斌来源|python笔记有时候我们在爬取动态网页的时候&#xff0c;会借助渲染工具来进行爬取&#xff0c;这个“借助”实际上就是通过使用相应的浏览器驱动(即WebDriver)向浏览器发出命令。但是有时候使用浏览器驱动来爬取网页时&#xff0c;会遇到这种情况这时&#xff0c…

Linux下文件如果没有权限不能被Apache访问

通过 apache的网站 php和图片都可以显示 就是 Htm页面不行 报错 Forbidden You dont have permission to access /me/1.html on this server. 其实是权限设置问题 可以 到文件所在目录 使用命令查看权限 #ls -al 再使用chmod命令给予足够权限即可 #chmod 0644 文件名…

html标签的显示模式(块级标签,行内标签,行内块标签)(转)

html标签的显示模式&#xff08;块级标签&#xff0c;行内标签&#xff0c;行内块标签&#xff09; 今天讲课的时候&#xff0c;讲到了html中的标签的显示模式&#xff0c;大致分为块级标签和行内标签。那么初学者在刚使用标签的时候会发现有些属性在一些标签上不起作用&#x…

RT-thread内核之进程间通信

一、进程间通信机制 rt-thread操作系统的IPC&#xff08;Inter-Process Communication&#xff0c;进程间同步与通信&#xff09;包含有中断锁、调度器锁、信号量、互斥锁、事件、邮箱、消息队列。其中前5个主要表现为线程间同步&#xff0c;邮箱与消息队列表现为线程间通信。本…

Linux内核学习四库全书

关于内核学习我建议不要上来就读内核而是先了解内核的构成和特性&#xff0c;然后通过思考发现疑问这时再去读内核源码。即先了解概貌在读局部细节。而且内核分成好多部分&#xff0c;不要只是按照顺序去读&#xff0c;应该针对某一部分比如内存管理或进程管理横向读几本书&…

46W 奖金池等你来战!微众银行第三届金融科技高校技术大赛火热报名中!

青春是什么&#xff1f;张爱玲曾说过&#xff0c;青春是个奇形怪状的玩意儿&#xff0c;短短的身子偏偏拖了一个长长的尾巴&#xff0c;像翅膀一样的招摇着&#xff0c;久久不肯离去。对于你我而言&#xff0c;青春是什么&#xff1f;青春也许是大学里点点滴滴的记忆&#xff1…

spring cloud快速搭建

为什么80%的码农都做不了架构师&#xff1f;>>> 一&#xff1a;注册中心 服务提供者&#xff08;简单&#xff09; 注册中心本身就可以是服务提供者&#xff0c;如果有需求可以分开。 1&#xff1a;pom.xml <?xml version"1.0" encoding"UTF-8…

ubuntu操作系统下载

原文网址&#xff1a;http://www.cyberciti.biz/linux-news/download-ubuntu-14-4-cd-dvd-iso-images/ Download of the day: Ubuntu Linux 14.04 LTS CD / DVD ISO by NIXCRAFT on APRIL 17, 2014 5 COMMENTS LAST UPDATED APRIL 17, 2014 in LINUX NEWS, OPEN SOURCE Ubuntu…

Linux内核模块编程入门

针对2.6内核的Linux系统&#xff0c;需要你的机器上已经安装了kernel-devel这个包&#xff0c;也就是编译模块所必须的东西&#xff1a;内核的头文件和一些Makefile。 一&#xff0c;Hello World程序&#xff1a; [code:1:fbc83fc10a]/*file: hello.c*/ #ifndef __KERNEL__ #…

2021中国国际消费电子博览会和青岛国际软件融合创新博览会盛大开幕

9月24日&#xff0c;备受瞩目的2021中国国际消费电子博览会(简称“电博会”)和青岛国际软件融合创新博览会(简称“软博会”)在青岛国际会展中心盛大开幕。国家工信部原副部长杨学山&#xff0c;国家工信部信息技术发展司副司长江明涛&#xff0c;中国机电产品进出口商会秘书长郭…

oracle 11g wm_concat 、 listagg 函数的使用(合并数据)

方法一 wn_concat() 函数 1、把以下图中Name一样的数据合并为一条&#xff0c;而且NO的值要这样显示如 C.1,C.2 2、实现这种效果的操作如下&#xff0c;先把Name的值进行分组&#xff08;group by&#xff09;&#xff0c;再把NO的值用 wm_concat()函数合并起来&#xff08;注意…

使用Cacti监控你的网络Cacti的安装

声明&#xff1a;本系列文档出自石头记&#xff0c;如若转载请注明出处&#xff0c;本人保留文档的所有权&#xff0c;并欢迎转载。本系列文档的其他部分链接如下&#xff1a;一、概述及Cacti的工作流程二、Cacti的安装三、Cacti的使用四、Cacti脚本及模板五、Cacti插件六、Cac…

AI 被当做炒作工具?

编译 | 禾木木 出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09; 上班路上由于高峰期&#xff0c;眼看就要迟到了&#xff0c;这个时候会想“如果汽车能自动完成这种高度重复的动作&#xff0c;我就可以在路上参加我的会议了”。但是你必须每几秒踩一次油门&#xff0…

毕业五年后差距

毕业五年后差距正如"打工皇帝"唐骏说&#xff1a;"我觉得有两种人不要跟别人争利益和价值回报。第一种人就是刚刚进入企业的人&#xff0c;头5年千万不要说你能不能多给我一点儿工资&#xff0c;最重要的是能在企业里学到什么&#xff0c;对发展是不是有利……&…

我的新技术博客

我是一个技术小白&#xff0c;我开启一片新的空间转载于:https://blog.51cto.com/13526168/2048988

Varnish使用小结

文章原始出处和作者信息及 本声明http://iyubo.blogbus.com/logs/35085709.html此日志会随时更新&#xff0c;当然&#xff0c;是随着我的应用积累:) 实现静态文件压缩 Varnish itself does not compress or decompress objects, although that has been on our wish list fo…

EF 通用数据层类

EF 通用数据层父类方法小结 转载&#xff1a;http://www.cnblogs.com/yq-Hua/p/4165344.html MSSql 数据库 数据层 父类 增删改查&#xff1a; using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Data.Entity.Infra…

最新的B站弹幕和评论爬虫,你们要的冰冰来啦!

作者 | 周萝卜 来源 | 萝卜大杂烩 最近想爬下B站的弹幕和评论&#xff0c;发现网上找到的教程基本都失效了&#xff0c;毕竟爬虫和反爬是属于魔高一尺、道高一丈的双方&#xff0c;程序员小哥哥们在网络的两端斗智斗勇&#xff0c;也是精彩纷呈。 当然了&#xff0c;对于爬虫…