在线编译

因为 less 的语法毕竟相对简单,所以一些在线工具可以很轻松的做到。比如 http://less.cnodejs.net http://www.ostools.net/less  一般都有两个框,左侧输入less,右侧呈现编译的 css,方便在线学习和测试。

修改 bootstrap 中的 less

如下图,入口文件是 bootstrap.less 和 responsive.less 文件——


这个入口文件 bootstrap.less 是这样引用其他 less 文件的:


了解这份 less 的内容很有必要。通过这个入口文件,逐步了解 bootstrap 的全部内容,才能更加方便的自定义它。

比如,如果要修改每栏 column 的宽度,可以打开 variables.less ,修改其中的 @gridColumnWidth 变量的值。

Bootstrap变量

基础设置

@bodyBackground @white 页面背景色  
@textColor @grayDark 默认的文字颜色  
@linkColor #08c 默认的链接颜色  
@linkColorHover darken(@linkColor, 15%) 默认链接hover样式  

页面栅格

@gridColumns 12
@gridColumnWidth 60px
@gridGutterWidth 20px
@fluidGridColumnWidth 6.382978723%
@fluidGridGutterWidth 2.127659574%

字体

@sansFontFamily “Helvetica Neue”, Helvetica, Arial, sans-serif
@serifFontFamily Georgia, "Times New Roman", Times, serif
@monoFontFamily Menlo, Monaco, “Courier New”, monospace
@baseFontSize 13px 以像素为单位
@baseFontFamily @sansFontFamily
@baseLineHeight 18px 以像素为单位
@altFontFamily @serifFontFamily
@headingsFontFamily inherit
@headingsFontWeight bold
@headingsColor inherit

表格tables

@tableBackground transparent
@tableBackgroundAccent #f9f9f9
@tableBackgroundHover #f5f5f5
@tableBorder ddd

冷色调

@black #000  
@grayDarker #222  
@grayDark #333  
@gray #555  
@grayLight #999  
@grayLighter #eee  
@white #fff  

暖色调

@blue #049cdb  
@green #46a546  
@red #9d261d  
@yellow #ffc40d  
@orange #f89406  
@pink #c3325f  
@purple #7a43b6  

组件

按钮buttons

@btnBackground @white  
@btnBackgroundHighlight darken(@white, 10%)  
@btnBorder darken(@white, 20%)  
@btnPrimaryBackground @linkColor  
@btnPrimaryBackgroundHighlight spin(@btnPrimaryBackground, 15%)  
@btnInfoBackground #5bc0de  
@btnInfoBackgroundHighlight #2f96b4  
@btnSuccessBackground #62c462  
@btnSuccessBackgroundHighlight 51a351  
@btnWarningBackground lighten(@orange, 15%)  
@btnWarningBackgroundHighlight @orange  
@btnDangerBackground #ee5f5b  
@btnDangerBackgroundHighlight #bd362f  
@btnInverseBackground @gray  
@btnInverseBackgroundHighlight @grayDarker  

表单Forms

@placeholderText @grayLight
@inputBackground @white
@inputBorder #ccc
@inputBorderRadius 3px
@inputDisabledBackground @grayLighter
@formActionsBackground #f5f5f5

表单Form提示背景及文字颜色

@warningText #c09853  
@warningBackground #f3edd2  
@errorText #b94a48  
@errorBackground #f2dede  
@successText #468847  
@successBackground #dff0d8  
@infoText #3a87ad  
@infoBackground #d9edf7  
导航栏

@navbarHeight 40px  
@navbarBackground @grayDarker  
@navbarBackgroundHighlight @grayDark  
@navbarText @grayLight  
@navbarLinkColor @grayLight  
@navbarLinkColorHover @white  
@navbarLinkColorActive @navbarLinkColorHover  
@navbarLinkBackgroundHover transparent  
@navbarLinkBackgroundActive @navbarBackground  
@navbarSearchBackground lighten(@navbarBackground, 25%)  
@navbarSearchBackgroundFocus @white  
@navbarSearchBorder darken(@navbarSearchBackground, 30%)  
@navbarSearchPlaceholderColor #ccc  
@navbarBrandColor @navbarLinkColor  

下拉Dropdowns

@dropdownBackground @white
@dropdownBorder rgba(0,0,0,.2)
@dropdownLinkColor @grayDark
@dropdownLinkColorHover @white
@dropdownLinkBackgroundHover @linkColor

Hero unit

@heroUnitBackground @grayLighter  
@heroUnitHeadingColor inherit  
@heroUnitLeadColor inhereit  

Bootstrap混合

关于混合

基础的混合
混合就是将一段需要进行合并的样式通过less的一种申明方式写到一起,它可以方便的被其他样式调用,从而达到能够重用的目的。

.element {
.clearfix();
}

带参数的混合
这种混合和基础混合比较类似,它增加接受参数的功能,当然如果你不传任何参数,它会提供一个默认值

.element {
.border-radius(4px);
}

易于扩展
所有的混合都是存储在mixins.less中的,如果各位有什么需要增加的混合可以直接集成到utilities.less中,方便调用。

bootstrap包含的混合

常用混合

混合 参数 用途
.clearfix() none 清除浮动
.tab-focus() none 自动聚焦
.center-block() none 居中,相当于margin: auto
.ie7-inline-block() none 让IE6,7支持display: inline-block
.size() @height @width 设置容器宽高
.square() @size 设置该容器为正方形,参数为边长
.opacity() @opacity 设置容器透明度

表单forms

混合 参数 用途
.placeholder() @color: @placeholderText 设置输入框的默认文案

字体

混合 参数 用途
#font > #family > .serif() none 设置这个元素的字体为有衬线字体
#font > #family > .sans-serif() none 设置这个元素的字体为无衬线字体
#font > #family > .monospace() none 设置这个元素的字体为等宽字体
#font > .shorthand() @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight 简单的设置字体的大小粗细等等
#font > .serif() @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight 设置该字体为有衬线字体,并设置字体的大小粗细等等
#font > .sans-serif() @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight 设置该字体为无衬线字体,并设置字体的大小粗细等等
#font > .monospace() @size: @baseFontSize, @weight: normal, @lineHeight: @baseLineHeight 设置该字体为等宽字体,并设置字体的大小粗细等等

栅格系统
相关的less代码在mixins.less中

混合 参数 用途
.container-fixed() none 指定该容器为居中
#grid > .core() @gridColumnWidth, @gridGutterWidth 初始化栅格系统,参数传递分别为栅格的列宽和栅格之间的距离
#grid > .fluid() @fluidGridColumnWidth, @fluidGridGutterWidth 初始化栅格系统,参数传递分别为每个栅格的所占栅格总宽度的百分比和栅格之间的距离所占栅格总宽度的百分比
#grid > .input() @gridColumnWidth, @gridGutterWidth 生成input相关元素的栅格布局,参数传递分别为栅格的列宽和栅格之间的距离
.makeColumn @columns: 1, @offset: 0 在栅格系统中初始化一个占几列的div容器,columns为该容器跨域的列数,offset为改容器的左偏移

css3属性

混合 参数 用途
.border-radius() @radius css3圆角,参数为圆角像素
.box-shadow() @shadow css3阴影
.transition() @transition css3动画,(如, all .2s linear)
.rotate() @degrees 旋转一个元素,参数为旋转的度数
.scale() @ratio 缩放元素,参数为缩放后和元尺寸的比列
.translate() @x, @y 在平面上移动元素,参数对应分别为相对于x轴和y轴的移动距离
.background-clip() @clip 背景裁剪,传入clip,clip选择border | padding | content
.background-size() @size 通过css3来控制背景图片的尺寸
.box-sizing() @boxmodel 改变容器的盒模型,例如我们可以改变类似input button的盒模型为传统的IE模型,即设置第一个参数为border-box就可以达到所有浏览器兼容的目的
.user-select() @select 用来控制内容的可选择性
.backface-visibility() @visibility: visible css3D动画效果是否隐藏内容的背面,
.resizable() @direction: both 让元素可以进行向右和向下的拉伸缩放
.content-columns() @columnCount, @columnGap: @gridGutterWidth 让容器具有css3的属性content-count和column-gap,第一个参数为列数,第二个参数为列数之间的间距

背景和渐变

混合 参数 用途
#translucent > .background() @color: @white, @alpha: 1 给元素半透明的背景色,第一个参数为背景色,第二个参数为透明度
#translucent > .border() @color: @white, @alpha: 1 给元素半透明的边框色,第一个参数为边框颜色,第二个参数为透明度
#gradient > .vertical() @startColor, @endColor 让一个容器从自上而下颜色渐变,兼容任何浏览器,第一个参数是开始的颜色,第二个参数是结束的颜色
#gradient > .horizontal() @startColor, @endColor 让一个容器从自左而右颜色渐变,兼容任何浏览器,第一个参数是开始的颜色,第二个参数是结束的颜色
#gradient > .directional() @startColor, @endColor, @deg 让一个容器按照一个角度进行渐变,第一个参数是开始的演示,第二个参数是结束的颜色,第三个参数是进行渐变的角度
#gradient > .vertical-three-colors() @startColor, @midColor, @colorStop, @endColor 让一个容器按照开始颜色和中间颜色以及结束颜色进行渐变,第一个参数是开始的颜色,第二个参数是中间的颜色,第三个参数是中间渐变结束的位置,最后一个参数是渐变结束的颜色
#gradient > .radial() @innerColor, @outerColor 让一个容器放射性渐变,第一个参数是容器中心的颜色,第二个参数是容器最外层的颜色
#gradient > .striped() @color, @angle 条纹渐变,第一个参数为渐变的颜色,第二个参数为渐变的角度
#gradientBar() @primaryColor, @secondaryColor 主要用于按钮和提示框的垂直颜色渐变

Bootstrap中的less基础的更多相关文章

  1. 针对BootStrap中tabs控件的美化和完善

    BootStrap中的tabs控件以其简单易用而很受广大开发者的欢迎.但是,它的样式比较单一,如何才能在其原有的基础上做出更加美观的效果呢,我一直在考虑这个问题.另外,Bootstrap中的tabs必 ...

  2. Bootstrap定制(二)less基础语法

    前几日花了一天去看less,这几日在捣鼓其他东西,项目也在有序的进行中,今天花点时间整理下less的基础语法,也分享实际中的一些经验,与众人共享. 本篇笔者以less的基础语法着手,并配合bootst ...

  3. bootstrap学习笔记之基础导航条 http://www.imooc.com/code/3111

    基础导航条 在Bootstrap框中,导航条和导航从外观上差别不是太多,但在实际使用中导航条要比导航复杂得多.我们先来看导航条中最基础的一个--基础导航条. 使用方法: 在制作一个基础导航条时,主要分 ...

  4. Bootstrap 中文文档教程

    Bootstrap 中文文档教程 Bootstrap 中文文档教程 全局样式和grid布局—Bootstrap中文使用指南 全局样式1.要求html5文档类型 Bootstrap使用的css属性和ht ...

  5. 参考bootstrap中的popover.js的css画消息弹框

    前段时间小颖的大学同学给小颖发了一张截图,图片类似下面这张图: 小颖当时大概的给她说了下,其实小颖也不知道上面那个三角形怎么画嘻嘻,给她说了DOM结构,具体的css让她自己百度,今天小颖自己参考boo ...

  6. 如何在ASP.NET Core中实现一个基础的身份认证

    注:本文提到的代码示例下载地址> How to achieve a basic authorization in ASP.NET Core 如何在ASP.NET Core中实现一个基础的身份认证 ...

  7. bootstrap中popover.js(弹出框)使用总结+案例

    bootstrap中popover.js(弹出框)使用总结+案例 *转载请注明出处: 作者:willingtolove: http://www.cnblogs.com/willingtolove/p/ ...

  8. Bootstrap 中的 Typeahead 组件 -- AutoComplete

    Bootstrap 中的 Typeahead 组件就是通常所说的自动完成 AutoComplete,功能很强大,但是,使用上并不太方便.这里我们将介绍一下这个组件的使用. 第一,简单使用 首先,最简单 ...

  9. [转]如何在ASP.NET Core中实现一个基础的身份认证

    本文转自:http://www.cnblogs.com/onecodeonescript/p/6015512.html 注:本文提到的代码示例下载地址> How to achieve a bas ...

随机推荐

  1. Vijos P1325桐桐的糖果计划

    > P1325桐桐的糖果计划 标签:**图结构 强连通分量** 描述 桐桐很喜欢吃棒棒糖.他家处在一大堆糖果店的附近. 但是,他们家的区域经常出现塞车.塞人等情况,这导致他不得不等到塞的车或人走 ...

  2. OpenJudge/Poj 1753 Flip Game

    1.链接地址: http://bailian.openjudge.cn/practice/1753/ http://poj.org/problem?id=1753 2.题目: 总时间限制: 1000m ...

  3. 第48条:如果需要精确的答案,请避免使用float和double

    float和double主要为了科学计算和工程计算而设计,执行二进制浮点运算,这是为了在广泛的数值范围上提供较为精确的快速近似计算而精心设计的.然而,它们没有提供完全精确的结果,所以不适合用于需要精确 ...

  4. asp.net发送E-mail

    发送电子邮件也是项目开发当中经常用到的功能,这里我整理了一个发送电子邮件(带附件,支持多用户发送,主送.抄送)的类库,供大家参考. 先上两个实体类,用于封装成Mail对象. /// <summa ...

  5. win7 64位。未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序

    win7或win8 64位调试程序,出现这样的错误提示:未在本地计算机上注册 Microsoft.Jet.OLEDB.4.0 提供程序 解决方法如下: 方法一:“设置应用程序池默认属性”/“常规”/” ...

  6. EF 的 霸气配置

    通过EF 作为操作数据库的工具有一段时间了,也做了几个相对不大的项目,慢慢的也对EF的使用摸索出来了一些规则,虽然说不是技术难点,但是,我说的是但是,能够提高我们开发效率的棉花糖有时我们还是必须要吃的 ...

  7. PHP输出

    样例: $a = true;$b = false;$c = 086;$d = 0x86;echo "$a hase value: ".$a; echo "<br/& ...

  8. php socket connect permission denied

    Linux在php socket连接时报错:permission denied 解决办法: # setsebool httpd_can_network_connect=1 参考来源: http://w ...

  9. MVC 4 网页版发送 邮件的配置问题

    有时项目要用到邮箱验证就要发送邮件传统的解决方案: public void SendResetPasswordEmail(string email) { MailAddress from = new ...

  10. cf Round 601

    A.The Two Routes(BFS) 给出n个城镇,有m条铁路,铁路的补图是公路,汽车和火车同时从1出发,通过每条路的时间为1,不能同时到达除了1和n的其它点,问他们到达n点最少要用多长时间. ...