doubleselect css,Nib 基于 Stylus 的扩展用于跨浏览器 CSS3 兼容性 - 文章教程

4c4e371972f43ce4179123ed24d31513.png

Nib 是一个小而精湛的 CSS3 预处理扩展,基于 Stylus CSS language, 而开发的,主要针对 CSS3 属性的跨浏览器兼容性。

body {

background: linear-gradient(top, white, black);

}

body {

background: -webkit-gradient(linear,

left top,

left bottom,

color-stop(0, #fff),

color-stop(1, #000));

background: -webkit-linear-gradient(top, #fff 0%, #000 100%);

background: -moz-linear-gradient(top, #fff 0%, #000 100%);

background: linear-gradient(top, #fff 0%, #000 100%);

}

Installation

To get started you’ll first want to add nib to your package.json file, along with stylus. Once installed you can use Stylus and Nib with your Connect or Express application as shown in the following snippet. The simple .use(nib()) call is all that is required to expose itself to Stylus

var connect = require('connect')

, stylus = require('stylus')

, nib = require('nib');

var app = connect();

function compile(str, path) {

return stylus(str)

.set('filename', path)

.set('compress', true)

.use(nib());

}

app.use(stylus.middleware({

src: __dirname

, compile: compile

}));

app.listen(3000);

From within a .styl file you can then @import nib, or a portion of nib:

@import 'nib'

@import 'nib/gradients'

@import 'nib/buttons'

Rather than manually @import-ing nib within your Stylus source you can import it via the JavaScript API as well:

return stylus(str)

.set('filename', path)

.set('compress', true)

.use(nib())

.import('nib');

Gradients

Nib’s gradient support is by far the largest feature it

provides, not only is the syntax extremely similar to what you would

normally write, it’s more forgiving, expands to vendor equivalents, and

can even produce a PNG for older browsers with node-canvas.

body {

background: linear-gradient(top, white, black);

}

yields:

body {

background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #fff), color-stop(1, #000));

background: -webkit-linear-gradient(top, #fff 0%, #000 100%);

background: -moz-linear-gradient(top, #fff 0%, #000 100%);

background: linear-gradient(top, #fff 0%, #000 100%);

}

28a6408d2aab29dfc9c5079cf0d22d0c.png

Any number of color stops may be provided:

body {

background: linear-gradient(bottom left, white, red, blue, black);

}

ab793f940b6de45397a02edfe0e65c1b.png

Units may be placed before, or after the color:

body {

background: linear-gradient(left, 80% red, #000);

background: linear-gradient(top, #eee, 90% white, 10% black);

}

6653cd41bcb70ec379a8d10419031404.png

061458afffac7729afe951726b3d4a43.png

Position mixins

The position mixins absolute, fixed, and relative provide a shorthand variant to what is otherwise three CSS properties. The syntax is as follows:

fixed|absolute|relative: top|bottom [n] left|right [n]

The following example will default to (0,0):

#back-to-top {

fixed: bottom right;

}

yielding:

#back-to-top {

position: fixed;

bottom: 0;

right: 0;

}

You may also specify the units:

#back-to-top {

fixed: bottom 10px right 5px;

}

yielding:

#back-to-top {

position: fixed;

bottom: 10px;

right: 5px;

}

Clearfix

The clearfix mixin currently takes no arguments, so it may be called as shown below:

.clearfix {

clearfix();

}

yielding:

.clearfix {

zoom: 1;

}

.clearfix:before,

.clearfix:after {

content: "";

display: table;

}

.clearfix:after {

clear: both;

}

Border radius

Nib’s border-radius supports both the regular syntax as well as augmenting it to make the value more expressive.

button {

border-radius: 1px 2px / 3px 4px;

}

button {

border-radius: 5px;

}

button {

border-radius: bottom 10px;

}

yielding:

button {

-webkit-border-radius: 1px 2px/3px 4px;

-moz-border-radius: 1px 2px/3px 4px;

border-radius: 1px 2px/3px 4px;

}

button {

-webkit-border-radius: 5px;

-moz-border-radius: 5px;

border-radius: 5px;

}

button {

-moz-border-radius-topleft: 10px;

-webkit-border-top-left-radius: 10px;

border-top-left-radius: 10px;

-moz-border-radius-bottomright: 10px;

-webkit-border-bottom-right-radius: 10px;

border-bottom-right-radius: 10px;

}

Responsive

The image mixin allows you to define a background-image for both the normal image, and a doubled image for devices with a higher pixel ratio such as retina displays. This works by using a @media query to serve an “@2x” version of the file.

#logo {

image: '/images/branding/logo.main.png'

}

#logo {

image: '/images/branding/logo.main.png' 50px 100px

}

yields:

#logo {

background-image: url("/images/branding/logo.main.png");

}

@media all and (-webkit-min-device-pixel-ratio: 1.5) {

#logo {

background-image: url("/images/branding/logo.main@2x.png");

background-size: auto auto;

}

}

#logo {

background-image: url("/images/branding/logo.main.png");

}

@media all and (-webkit-min-device-pixel-ratio: 1.5) {

#logo {

background-image: url("/images/branding/logo.main@2x.png");

background-size: 50px 100px;

}

}

Ellipsis

The overflow property is augmented with a “ellipsis” value, expanding to what you see below.

button {

overflow: ellipsis;

}

yielding:

button {

white-space: nowrap;

overflow: hidden;

text-overflow: ellipsis;

}

Reset

Nib comes bundled with Eric Meyer’s style reset support, you

can choose to apply the global or any specifics that you wish. To view

the definitions view reset.styl

global-reset()

nested-reset()

reset-font()

reset-box-model()

reset-body()

reset-table()

reset-table-cell()

reset-html5()

Miscellaneous properties

The following properties follow vendor expansion much like border-radius, however without augmentation, as well as some aliases such as whitespace instead of white-space.

no-wrap == nowrap

whitespace == white-space

box-shadow

user-select

column-count

column-gap

column-rule

column-rule-color

column-rule-width

column-rule-style

column-width

background-size

transform

border-image

transition

transition-property

transition-duration

transition-timing-function

transition-delay

backface-visibility

opacity

box-sizing

box-orient

box-flex

box-flex-group

box-align

box-pack

box-direction

animation

animation-name

animation-duration

animation-delay

animation-direction

animation-iteration-count

animation-timing-function

animation-play-state

animation-fill-mode

border-image

hyphens

appearance

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值