CSS 的簡(jiǎn)寫屬性

原文地址?http://www.mark.ah.cn

定義

簡(jiǎn)寫屬性是可以讓你同時(shí)設(shè)置其他幾個(gè) CSS 屬性值的 CSS 屬性。使用簡(jiǎn)寫屬性,Web 開(kāi)發(fā)人員可以編寫更簡(jiǎn)潔、更具可讀性的樣式表督函,節(jié)省時(shí)間和精力。

CSS 規(guī)范定義簡(jiǎn)寫屬性的目的在于將那些關(guān)于同一主題的常見(jiàn)屬性的定義集中在一起激挪。比如 CSS 的 background 屬性就是一個(gè)簡(jiǎn)寫屬性辰狡,它可以定義 background-color、background-image垄分、background-repeat 和 background-position 的值宛篇。類似地,最常見(jiàn)的字體相關(guān)的屬性可以使用 font 的簡(jiǎn)寫锋喜,盒子(box)各方向的外邊距(margin) 可以使用 margin 這個(gè)簡(jiǎn)寫。

1. Font 屬性

font-family嘿般,font-style段标,font-variant,font-weight炉奴,font-size逼庞,font

font-family(字體族): “Arial”、“Times New Roman”瞻赶、“宋體”赛糟、“黑體”等;

font-style(字體樣式): normal(正常)、italic(斜體)或oblique(傾斜);

font-variant (字體變化): normal(正常)或small-caps(小體大寫字母);

font-weight (字體濃淡):是normal(正常)或bold(加粗)砸逊。有些瀏覽器甚至支持采用100到900之間的數(shù)字(以百為單位);

font-size(字體大需的稀): 可通過(guò)多種不同單位(比如像素或百分比等)來(lái)設(shè)置, 如:12xp,12pt师逸,120%司倚,1em

如果用 font 屬性的話,就可以把幾個(gè)樣式進(jìn)行簡(jiǎn)化,減少書的情況动知;font 屬性的值應(yīng)按以下次序書寫(各個(gè)屬性之間用空格隔開(kāi)):

字體樣式 ? | 字體變化 ? ? | 字體濃淡 ? ?| 字體大小 ?| 字體族

font-style | font-variant | font-weight | font-size | font-family

例如:

.text{

font-style:italic;

font-variant:normal;

font-weight:bold;

font-size:30px;

font-family:arial, sans-serif;?

}

上面的樣式簡(jiǎn)寫為:

.text{font:italic normal bold12pxarial,verdana;}

2. Background 屬性

background-color:#999999皿伺; //元素的背景色

background-image : url("bg-img.png"); //設(shè)置背景圖像

background-repeat : repeat-x | repeat-y | repeat | no-repeat; //設(shè)置重復(fù)方式

background-attachment : fixed | scroll; //設(shè)置背景圖片的固定方式

background-position : X軸坐標(biāo),Y軸坐標(biāo)[top,bottom,center,left,right,20px,10%];

//設(shè)置背景的左上角位置,坐標(biāo)可以是以百分比或固定單位

background ?可以用這個(gè)屬性把前面幾個(gè)綜合起來(lái)進(jìn)行簡(jiǎn)寫

background 各個(gè)值的次序依次如下:

背景色| 背景圖 | 背景圖重復(fù)方式 | 背景圖固定方式 | 背景圖坐標(biāo)

background-color | background-image ?| background-repeat | background-attachment | background-position

如果省略某個(gè)屬性不寫出來(lái),那么將自動(dòng)為它取缺省值盒粮。

比如鸵鸥,如果去掉background-attachment和background-position的話:

background:#FFCC66url("bg-img.png") no-repeat;

例如:

.bg{background-color:#FFCC66;background-image:url("bg-img.png");background-repeat:no-repeat;background-attachment:fixed;background-position:left top;}

上面可以簡(jiǎn)寫為:

.bg{background:#FFCC66url("bg-img.png")? no-repeat? fixed? left? top; }

3. Border 屬性

border:[border-width ||border-style ||border-color |inherit];

border-width:1px;border-style:solid;border-color:#000;

可以簡(jiǎn)寫成?border:1pxsolid#000;

屬性

border-top:1pxsolid#000;

border-right:2pxsolid#000;

border-bottom:3pxsolid#000;

border-left:4pxsolid#000;

可以簡(jiǎn)寫成

border:1px solid#0002px solid #0003px solid #0004px solid #000;

border-style取值

none

No border.

*hidden

Same as 'none', but in the collapsing border model, also inhibits any other border (see the section on border conflicts).

dotted

The border is a series of dots.

dashed

The border is a series of short line segments.

solid

The border is a single line segment.

double

The border is two solid lines. The sum of the two lines and the space between them equals the value of 'border-width'.

groove

The border looks as though it were carved into the canvas.

ridge

The opposite of 'groove': the border looks as though it were coming out of the canvas.

*inset

In the separated borders model, the border makes the entire box look as though it were embedded in the canvas. In the collapsing border model, drawn the same as 'ridge'.

*outset

In the separated borders model, the border makes the entire box look as though it were coming out of the canvas. In the collapsing border model, drawn the same as 'groove'.

4. border-radius 圓角屬性

border-top-left-radius? ??

border-top-right-radius? ??

border-bottom-right-radius? ??

border-bottom-left-radius

類似邊框border屬性
取值 [<length>? |<percentage>? ]{1,2}

border-top-left-radius:5px30%;

border-top-right-radius:5px30%;

border-bottom-right-radius:5px30%;

border-bottom-left-radius:5px30%;

border-radius:5px30%;

如果實(shí)現(xiàn)一個(gè)圓可以

div{width:100px;height:100px;border:2pxsolid red;border-radius:50%;background:#00ffff;}

5. Margin 和 Padding 屬性

注意,值是從 top 順時(shí)針開(kāi)始的:top丹皱、right妒穴、bottom、接著是 left

上 ?| 右 | 下 ?| 左

padding-top | padding-right | padding-bottom | padding-left

margin-top ?| margin-right ?| margin-bottom ?| margin-left

padding : 1px 2px 3px 4px;

margin : 1px 2px 3px 4px;

6. border-image 屬性

引入圖片

border-image-source

border-image-source:url(image url);

切割引入的圖片

border-image-slice

border-image-slice: [<number>? |<percentage>?]{1,4}&& fill?

邊框的寬度

border-image-width

border-image-width: [<length>? |<percentage>? |<number>? | auto ]{1,4}

圖片的排列方式

border-image-repeat

border-image-repeat: [ stretch | repeat | round ]{1,2}

border-image對(duì)表格table的影響

https://drafts.csswg.org/css-backgrounds-3/#border-image-tables

https://www.w3.org/TR/2011/REC-CSS2-20110607/tables.html#border-conflict-resolution

7. transition 過(guò)渡

transition 是一個(gè)簡(jiǎn)寫屬性种呐,可設(shè)置 transition-property, transition-duration, transition-timing-function,? transition-delay宰翅。 transition用來(lái)定義元素在兩種狀態(tài)之間的過(guò)渡。不同狀態(tài)可以用:hover 爽室、:active之類的 pseudo-classes 定義,或者使用 JavaScript 動(dòng)態(tài)設(shè)置淆攻。

幾種動(dòng)畫效果

ease:(逐漸變慢)默認(rèn)值阔墩,ease函數(shù)等同于貝塞爾曲線(0.25, 0.1, 0.25, 1.0).

linear:(勻速),linear 函數(shù)等同于貝塞爾曲線(0.0, 0.0, 1.0, 1.0).

ease-in:(加速)瓶珊,ease-in 函數(shù)等同于貝塞爾曲線(0.42, 0, 1.0, 1.0).

ease-out:(減速)啸箫,ease-out 函數(shù)等同于貝塞爾曲線(0, 0, 0.58, 1.0).

ease-in-out:(加速然后減速),ease-in-out 函數(shù)等同于貝塞爾曲線(0.42, 0, 0.58, 1.0)

cubic-bezier:(該值允許你去自定義一個(gè)時(shí)間曲線)伞芹, 特定的cubic-bezier曲線忘苛。 (x1, y1, x2, y2)四個(gè)值特定于曲線上點(diǎn)P1和點(diǎn)P2。所有值需在[0, 1]區(qū)域內(nèi)唱较,否則無(wú)效扎唾。

其是cubic-bezier為通過(guò)貝賽爾曲線來(lái)計(jì)算“轉(zhuǎn)換”過(guò)程中的屬性值,如下曲線所示南缓,通過(guò)改變P1(x1, y1)和P2(x2, y2)的坐標(biāo)可以改變整個(gè)過(guò)程的Output Percentage胸遇。初始默認(rèn)值為default.

樣式

a{

-moz-transition:background0.5sease-in,color0.3sease-out;

-webkit-transition:background0.5sease-in,color0.3sease-out;

-o-transition:background0.5sease-in,color0.3sease-out;

transition:background0.5sease-in,color0.3sease-out;

}

p{

-webkit-transition:all .5sease-in-out1s;

-o-transition:all .5sease-in-out1s;

-moz-transition:all .5sease-in-out1s;

transition:all .5sease-in-out1s;

}

8. list-style 屬性

CSS list-style 屬性是設(shè)置list-style-type, list-style-image 和 list-style-position? 的簡(jiǎn)寫屬性。

list-style-type取值

none

disc?實(shí)心圓點(diǎn) (默認(rèn)值)

circle?空心圓點(diǎn)

square 實(shí)心方塊

decimal 十進(jìn)制阿拉伯?dāng)?shù)字 從1開(kāi)始

cjk-decimal 中日韓十進(jìn)制數(shù) 例如: 一, 二, 三, ..., 九八, 九九, 一〇〇

decimal-leading-zero Decimal numbers Padded by initial zeros E.g. 01, 02, 03, … 98, 99

lower-roman Lowercase roman numerals E.g. i, ii, iii, iv, v…

...

list-style-position

取值

outside 標(biāo)記盒在主塊盒的外面汉形。

inside 標(biāo)記盒是主要塊盒中的第一個(gè)行內(nèi)盒纸镊,處于元素的內(nèi)容流之后。

參考文獻(xiàn)

https://developer.mozilla.org/zh-CN/docs/Web/CSS/Shorthand_properties

http://blog.csdn.net/shenzhennba/article/details/7356095

https://drafts.csswg.org/css-backgrounds-3/#the-border-shorthands

http://www.w3cplus.com/content/css3-border-image

http://www.zhangxinxu.com/wordpress/2010/01/css3-border-image/

https://developer.mozilla.org/zh-CN/docs/Web/CSS/border

https://developer.mozilla.org/zh-CN/docs/Web/CSS/transition

https://drafts.csswg.org/css-transitions/#transitions

https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Transitions/Using_CSS_transitions

http://www.w3cplus.com/content/css3-transition

https://developer.mozilla.org/zh-CN/docs/Web/CSS/list-style

https://developer.mozilla.org/zh-CN/docs/Web/CSS/list-style-type

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末概疆,一起剝皮案震驚了整個(gè)濱河市逗威,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌岔冀,老刑警劉巖凯旭,帶你破解...
    沈念sama閱讀 217,542評(píng)論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡尽纽,警方通過(guò)查閱死者的電腦和手機(jī)咐蚯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,822評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)弄贿,“玉大人春锋,你說(shuō)我怎么就攤上這事〔畎迹” “怎么了期奔?”我有些...
    開(kāi)封第一講書人閱讀 163,912評(píng)論 0 354
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)危尿。 經(jīng)常有香客問(wèn)我呐萌,道長(zhǎng),這世上最難降的妖魔是什么谊娇? 我笑而不...
    開(kāi)封第一講書人閱讀 58,449評(píng)論 1 293
  • 正文 為了忘掉前任肺孤,我火速辦了婚禮,結(jié)果婚禮上济欢,老公的妹妹穿的比我還像新娘赠堵。我一直安慰自己,他們只是感情好法褥,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,500評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布茫叭。 她就那樣靜靜地躺著,像睡著了一般半等。 火紅的嫁衣襯著肌膚如雪揍愁。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,370評(píng)論 1 302
  • 那天杀饵,我揣著相機(jī)與錄音莽囤,去河邊找鬼。 笑死凹髓,一個(gè)胖子當(dāng)著我的面吹牛烁登,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播蔚舀,決...
    沈念sama閱讀 40,193評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼饵沧,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了赌躺?” 一聲冷哼從身側(cè)響起狼牺,我...
    開(kāi)封第一講書人閱讀 39,074評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎礼患,沒(méi)想到半個(gè)月后是钥,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體掠归,經(jīng)...
    沈念sama閱讀 45,505評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,722評(píng)論 3 335
  • 正文 我和宋清朗相戀三年悄泥,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了虏冻。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,841評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡弹囚,死狀恐怖厨相,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情鸥鹉,我是刑警寧澤蛮穿,帶...
    沈念sama閱讀 35,569評(píng)論 5 345
  • 正文 年R本政府宣布,位于F島的核電站毁渗,受9級(jí)特大地震影響践磅,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜灸异,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,168評(píng)論 3 328
  • 文/蒙蒙 一府适、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧绎狭,春花似錦细溅、人聲如沸。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,783評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)恍风。三九已至蹦狂,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間朋贬,已是汗流浹背凯楔。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,918評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留锦募,地道東北人摆屯。 一個(gè)月前我還...
    沈念sama閱讀 47,962評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像糠亩,于是被迫代替她去往敵國(guó)和親虐骑。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,781評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 1赎线、垂直對(duì)齊 如果你用CSS廷没,則你會(huì)有困惑:我該怎么垂直對(duì)齊容器中的元素?現(xiàn)在垂寥,利用CSS3的Transform颠黎,...
    kiddings閱讀 3,164評(píng)論 0 11
  • 1.CSS3 邊框 border-radius CSS屬性用來(lái)設(shè)置邊框圓角另锋。當(dāng)使用一個(gè)半徑時(shí)確定一個(gè)圓形;當(dāng)使用兩...
    garble閱讀 643評(píng)論 0 0
  • 選擇qi:是表達(dá)式 標(biāo)簽選擇器 類選擇器 屬性選擇器 繼承屬性: color狭归,font夭坪,text-align,li...
    love2013閱讀 2,314評(píng)論 0 11
  • 微醺的酒意仿佛帶著我回到了多年以前。 那些年驕陽(yáng)似火潭流,你與我都帶著任性與不羈的笑容竞惋。 我竟不知是從什么時(shí)候開(kāi)始越加...
    熊心中的小蓮花閱讀 488評(píng)論 0 2
  • 姥姥有一個(gè)自己的小院子拆宛,小但繽紛。毛茸茸的冬瓜讼撒,直挺挺的小蔥浑厚,還有韭菜,西紅柿根盒,豆角钳幅,小白菜...姥姥待它們就像待...
    辣么大之閱讀 145評(píng)論 0 1