CSS
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CSS相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/off' title='off'>off htm uml rtm 杈撳叆 otc bmc 閾炬帴
CSS浠嬬粛
CSS锛?strong>Cascading Style Sheet锛屽眰鍙犳牱寮忚〃)瀹氫箟濡備綍鏄剧ずHTML鍏冪礌銆?/p>
褰撴祻瑙堝櫒璇诲埌涓€涓牱寮忚〃锛屽畠灏变細鎸夌収杩欎釜鏍峰紡琛ㄦ潵瀵规枃妗h繘琛屾牸寮忓寲锛堟覆鏌擄級銆?/p>
CSS璇硶
CSS瀹炰緥
姣忎釜CSS鏍峰紡鐢变袱涓粍鎴愰儴鍒嗭細閫夋嫨鍣ㄥ拰澹版槑銆傚0鏄庡張鍖呮嫭灞炴€у拰灞炴€у€笺€傛瘡涓0鏄庝箣鍚庣敤鍒嗗彿缁撴潫銆?/p>
CSS娉ㄩ噴
/*杩欐槸娉ㄩ噴*/
娉ㄩ噴鏄唬鐮佷箣姣嶃€?/p>
CSS鐨勫嚑绉嶅紩鍏ユ柟寮?/span>
琛屽唴鏍峰紡
琛屽唴寮忔槸鍦ㄦ爣璁扮殑style灞炴€т腑璁惧畾CSS鏍峰紡銆備笉鎺ㄨ崘澶ц妯′娇鐢ㄣ€?/p>
<p style="color: red">Hello world.</p>
鍐呴儴鏍峰紡
宓屽叆寮忔槸灏咰SS鏍峰紡闆嗕腑鍐欏湪缃戦〉鐨?lt;head></head>鏍囩瀵圭殑<style></style>鏍囩瀵逛腑銆傛牸寮忓涓嬶細
<head> <meta charset="UTF-8"> <title>Title</title> <style> p background-color: #2b99ff; </style> </head>
澶栭儴鏍峰紡
澶栭儴鏍峰紡灏辨槸灏哻ss鍐欏湪涓€涓崟鐙殑鏂囦欢涓紝鐒跺悗鍦ㄩ〉闈㈣繘琛屽紩鍏ュ嵆鍙€傛帹鑽愪娇鐢ㄦ鏂瑰紡銆?/p>
<link href="mystyle.css" rel="stylesheet" type="text/css"/>
CSS閫夋嫨鍣?/span>
鍩烘湰閫夋嫨鍣?/span>
鍏冪礌閫夋嫨鍣?/h3>
p color: "red";
ID閫夋嫨鍣?/h3>
#i1
background-color: red;
绫婚€夋嫨鍣?/h3>
.c1
font-size: 14px;
p.c1
color: red;
p color: "red";
#i1 background-color: red;
绫婚€夋嫨鍣?/h3>
.c1
font-size: 14px;
p.c1
color: red;
.c1 font-size: 14px;
p.c1
color: red;
娉ㄦ剰锛?/p>
鏍峰紡绫诲悕涓嶈鐢ㄦ暟瀛楀紑澶达紙鏈夌殑娴忚鍣ㄤ笉璁わ級銆?/p>
鏍囩涓殑class灞炴€у鏋滄湁澶氫釜锛岃鐢ㄧ┖鏍煎垎闅斻€?/p>
閫氱敤閫夋嫨鍣?/h3>
*
color: white;
缁勫悎閫夋嫨鍣?/span>
鍚庝唬閫夋嫨鍣?/h3>
/*li鍐呴儴鐨刟鏍囩璁剧疆瀛椾綋棰滆壊*/
li a
color: green;
鍎垮瓙閫夋嫨鍣?/h3>
/*閫夋嫨鎵€鏈夌埗绾ф槸 <div> 鍏冪礌鐨?<p> 鍏冪礌*/
div>p
font-family: "Arial Black", arial-black, cursive;
姣楅偦閫夋嫨鍣?/h3>
/*閫夋嫨鎵€鏈夌揣鎺ョ潃<div>鍏冪礌涔嬪悗鐨?lt;p>鍏冪礌*/
div+p
margin: 5px;
寮熷紵閫夋嫨鍣?/h3>
/*i1鍚庨潰鎵€鏈夌殑鍏勫紵p鏍囩*/
#i1~p
border: 2px solid royalblue;
灞炴€ч€夋嫨鍣?/span>
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€х殑鍏冪礌銆?/
p[title]
color: red;
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€у拰鍊肩殑鍏冪礌銆?/
p[title="213"]
color: green;
*鎵惧埌鎵€鏈塼itle灞炴€т互hello寮€澶寸殑鍏冪礌*/
[title^="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€т互hello缁撳熬鐨勫厓绱?/
[title$="hello"]
color: yellow;
/*鎵惧埌鎵€鏈塼itle灞炴€т腑鍖呭惈锛堝瓧绗︿覆鍖呭惈锛塰ello鐨勫厓绱?/
[title*="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€?鏈夊涓€兼垨鍊间互绌烘牸鍒嗗壊)涓湁涓€涓€间负hello鐨勫厓绱狅細*/
[title~="hello"]
color: green;
鍒嗙粍鍜屽祵濂?/span>
鍒嗙粍
* color: white;
/*li鍐呴儴鐨刟鏍囩璁剧疆瀛椾綋棰滆壊*/ li a color: green;
鍎垮瓙閫夋嫨鍣?/h3>
/*閫夋嫨鎵€鏈夌埗绾ф槸 <div> 鍏冪礌鐨?<p> 鍏冪礌*/
div>p
font-family: "Arial Black", arial-black, cursive;
姣楅偦閫夋嫨鍣?/h3>
/*閫夋嫨鎵€鏈夌揣鎺ョ潃<div>鍏冪礌涔嬪悗鐨?lt;p>鍏冪礌*/
div+p
margin: 5px;
寮熷紵閫夋嫨鍣?/h3>
/*i1鍚庨潰鎵€鏈夌殑鍏勫紵p鏍囩*/
#i1~p
border: 2px solid royalblue;
灞炴€ч€夋嫨鍣?/span>
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€х殑鍏冪礌銆?/
p[title]
color: red;
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€у拰鍊肩殑鍏冪礌銆?/
p[title="213"]
color: green;
*鎵惧埌鎵€鏈塼itle灞炴€т互hello寮€澶寸殑鍏冪礌*/
[title^="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€т互hello缁撳熬鐨勫厓绱?/
[title$="hello"]
color: yellow;
/*鎵惧埌鎵€鏈塼itle灞炴€т腑鍖呭惈锛堝瓧绗︿覆鍖呭惈锛塰ello鐨勫厓绱?/
[title*="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€?鏈夊涓€兼垨鍊间互绌烘牸鍒嗗壊)涓湁涓€涓€间负hello鐨勫厓绱狅細*/
[title~="hello"]
color: green;
鍒嗙粍鍜屽祵濂?/span>
鍒嗙粍
/*閫夋嫨鎵€鏈夌埗绾ф槸 <div> 鍏冪礌鐨?<p> 鍏冪礌*/ div>p font-family: "Arial Black", arial-black, cursive;
/*閫夋嫨鎵€鏈夌揣鎺ョ潃<div>鍏冪礌涔嬪悗鐨?lt;p>鍏冪礌*/ div+p margin: 5px;
寮熷紵閫夋嫨鍣?/h3>
/*i1鍚庨潰鎵€鏈夌殑鍏勫紵p鏍囩*/
#i1~p
border: 2px solid royalblue;
灞炴€ч€夋嫨鍣?/span>
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€х殑鍏冪礌銆?/
p[title]
color: red;
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€у拰鍊肩殑鍏冪礌銆?/
p[title="213"]
color: green;
*鎵惧埌鎵€鏈塼itle灞炴€т互hello寮€澶寸殑鍏冪礌*/
[title^="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€т互hello缁撳熬鐨勫厓绱?/
[title$="hello"]
color: yellow;
/*鎵惧埌鎵€鏈塼itle灞炴€т腑鍖呭惈锛堝瓧绗︿覆鍖呭惈锛塰ello鐨勫厓绱?/
[title*="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€?鏈夊涓€兼垨鍊间互绌烘牸鍒嗗壊)涓湁涓€涓€间负hello鐨勫厓绱狅細*/
[title~="hello"]
color: green;
鍒嗙粍鍜屽祵濂?/span>
鍒嗙粍
/*i1鍚庨潰鎵€鏈夌殑鍏勫紵p鏍囩*/ #i1~p border: 2px solid royalblue;
/*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€х殑鍏冪礌銆?/ p[title] color: red; /*鐢ㄤ簬閫夊彇甯︽湁鎸囧畾灞炴€у拰鍊肩殑鍏冪礌銆?/ p[title="213"] color: green;
*鎵惧埌鎵€鏈塼itle灞炴€т互hello寮€澶寸殑鍏冪礌*/
[title^="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€т互hello缁撳熬鐨勫厓绱?/
[title$="hello"]
color: yellow;
/*鎵惧埌鎵€鏈塼itle灞炴€т腑鍖呭惈锛堝瓧绗︿覆鍖呭惈锛塰ello鐨勫厓绱?/
[title*="hello"]
color: red;
/*鎵惧埌鎵€鏈塼itle灞炴€?鏈夊涓€兼垨鍊间互绌烘牸鍒嗗壊)涓湁涓€涓€间负hello鐨勫厓绱狅細*/
[title~="hello"]
color: green;
褰撳涓厓绱犵殑鏍峰紡鐩稿悓鐨勬椂鍊欙紝鎴戜滑娌℃湁蹇呰閲嶅鍦颁负姣忎釜鍏冪礌閮借缃牱寮忥紝鎴戜滑鍙互閫氳繃鍦ㄥ涓€夋嫨鍣ㄤ箣闂翠娇鐢ㄩ€楀彿鍒嗛殧鐨勫垎缁勯€夋嫨鍣ㄦ潵缁熶竴璁剧疆鍏冪礌鏍峰紡銆?span data-key="10196">
div, p color: red;
涓婇潰鐨勪唬鐮佷负div鏍囩鍜宲鏍囩缁熶竴璁剧疆瀛椾綋涓虹孩鑹层€?/span>
div, p color: red;
宓屽
澶?span data-offset-key="10242-0">绉嶉€夋嫨鍣ㄥ彲浠ユ贩鍚堣捣鏉ヤ娇鐢紝姣斿锛?span data-offset-key="10242-1">.c1绫诲唴閮ㄦ墍鏈?span data-offset-key="10242-3">p鏍囩璁剧疆瀛椾綋棰滆壊涓虹孩鑹层€?/span>
.c1 p color: red;
浼被閫夋嫨鍣?/span>
/* 鏈闂殑閾炬帴 */ a:link color: #FF0000 /* 榧犳爣绉诲姩鍒伴摼鎺ヤ笂 */ a:hover color: #FF00FF /* 閫夊畾鐨勯摼鎺?*/ a:active color: #0000FF /* 宸茶闂殑閾炬帴 */ a:visited color: #00FF00 /*input杈撳叆妗嗚幏鍙栫劍鐐规椂鏍峰紡*/ input:focus outline: none; background-color: #eee;
浼厓绱犻€夋嫨鍣?/span>
first-letter
甯哥敤鐨勭粰棣栧瓧姣嶈缃壒娈婃牱寮忥細
p:first-letter font-size: 48px; color: red;
before
/*鍦ㄦ瘡涓?lt;p>鍏冪礌涔嬪墠鎻掑叆鍐呭*/ p:before content:"*"; color:red;
after
/*鍦ㄦ瘡涓?lt;p>鍏冪礌涔嬪悗鎻掑叆鍐呭*/ p:after content:"[?]"; color:blue;
before鍜宎fter澶氱敤浜庢竻闄ゆ诞鍔ㄣ€?/p>
閫夋嫨鍣ㄧ殑浼樺厛绾?/span>
CSS缁ф壙
缁ф壙鏄疌SS鐨勪竴涓富瑕佺壒寰侊紝瀹冩槸渚濊禆浜庣鍏?鍚庝唬鐨勫叧绯荤殑銆傜户鎵挎槸涓€绉嶆満鍒讹紝瀹冨厑璁告牱寮忎笉浠呭彲浠ュ簲鐢ㄤ簬鏌愪釜鐗瑰畾鐨勫厓绱狅紝杩樺彲浠ュ簲鐢ㄤ簬瀹冪殑鍚庝唬銆備緥濡備竴涓猙ody瀹氫箟浜嗙殑瀛椾綋棰滆壊鍊间篃浼氬簲鐢ㄥ埌娈佃惤鐨勬枃鏈腑銆?/p>
body color: red;
姝ゆ椂椤甸潰涓婃墍鏈夋爣绛鹃兘浼氱户鎵縝ody鐨勫瓧浣撻鑹层€傜劧鑰孋SS缁ф壙鎬х殑鏉冮噸鏄潪甯镐綆鐨勶紝鏄瘮鏅€氬厓绱犵殑鏉冮噸杩樿浣庣殑0銆?/p>
鎴戜滑鍙缁欏搴旂殑鏍囩璁剧疆瀛椾綋棰滆壊灏卞彲瑕嗙洊鎺夊畠缁ф壙鐨勬牱寮忋€?/p>
p color: green;
姝ゅ锛岀户鎵挎槸CSS閲嶈鐨勪竴閮ㄥ垎锛屾垜浠敋鑷充笉鐢ㄥ幓鑰冭檻瀹冧负浠€涔堣兘澶熻繖鏍凤紝浣咰SS缁ф壙涔熸槸鏈夐檺鍒剁殑銆傛湁涓€浜涘睘鎬т笉鑳借缁ф壙锛屽锛歜order, margin, padding, background绛夈€?/p>
閫夋嫨鍣ㄧ殑浼樺厛绾?/h3>
鎴戜滑涓婇潰瀛︿簡寰堝鐨勯€夋嫨鍣紝涔熷氨鏄鍦ㄤ竴涓狧TML椤甸潰涓湁寰堝绉嶆柟寮忔壘鍒颁竴涓厓绱犲苟涓斾负鍏惰缃牱寮忥紝閭f祻瑙堝櫒鏍规嵁浠€涔堟潵鍐冲畾搴旇搴旂敤鍝釜鏍峰紡鍛紵
鍏跺疄鏄寜鐓т笉鍚岄€夋嫨鍣ㄧ殑鏉冮噸鏉ュ喅瀹氱殑锛屽叿浣撶殑閫夋嫨鍣ㄦ潈閲嶈绠楁柟寮忓涓嬪浘锛?/p>
闄ゆ涔嬪杩樺彲浠ラ€氳繃娣诲姞 !important鏂瑰紡鏉ュ己鍒惰鏍峰紡鐢熸晥锛屼絾骞朵笉鎺ㄨ崘浣跨敤銆傚洜涓哄鏋滆繃澶氱殑浣跨敤!important浼氫娇鏍峰紡鏂囦欢娣蜂贡涓嶆槗缁存姢銆?/p>
涓囦笉寰楀凡鍙互浣跨敤!important
琛屽唴鏍峰紡 > id閫夋嫨鍣?> 绫婚€夋嫨鍣?> 鏍囩閫夋嫨鍣?> 閫氱敤閫夋嫨鍣?/em>
以上是关于CSS的主要内容,如果未能解决你的问题,请参考以下文章
css [css:fadeout / fadein] css示例。 #css
css 深度提示#css中的css base builder CSS