亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
簡(jiǎn)介 更新歷史 關(guān)于樣式表 屬性 定位 布局 position z-index top right bottom left clip display float clear visibility overflow overflow-x overflow-y 尺寸 width min-width max-width height min-height max-height 外補(bǔ)白 margin margin-top margin-right margin-bottom margin-left 內(nèi)補(bǔ)白 padding padding-top padding-right padding-bottom padding-left 邊框 border border-width border-style border-color border-top border-top-width border-top-style border-top-color border-right border-right-width border-right-style border-right-color border-bottom border-bottom-width border-bottom-style border-bottom-style border-bottom-color border-left border-left-width border-left-style border-left-color border-radius border-top-left-radius border-top-right-radius border-bottom-right-radius border-bottom-left-radius box-shadow border-image border-image-source border-image-slice border-image-width border-image-outset border-image-repeat 背景 background background-color background-image background-repeat background-attachment background-position background-origin background-clip background-size 顏色 color opacity 字體 font font-style font-variant font-weight font-size font-family font-stretch font-size-adjust 文本 text-transform white-space tab-size word-break word-wrap overflow-wrap text-align text-align-last text-justify word-spacing letter-spacing text-indent vertical-align line-height text-size-adjust 文本裝飾 text-decoration text-decoration-line text-decoration-color text-decoration-style text-decoration-skip text-underline-position text-shadow 書寫模式 direction unicode-bidi writing-mode 列表 list-style list-style-image list-style-position list-style-type 表格 table-layout border-collapse border-spacing caption-side empty-cells 內(nèi)容 content counter-increment counter-reset quotes 用戶界面 appearance text-overflow outline outline-width outline-color outline-style outline-offset nav-index nav-up nav-right nav-down nav-left cursor zoom box-sizing resize ime-mode user-select pointer-events 多列 columns column-width column-count column-gap column-rule column-rule-width column-rule-style column-rule-color column-span column-fill column-break-before column-break-after column-break-inside 伸縮盒(舊) box-orient box-pack box-align box-flex box-flex-group box-ordinal-group box-direction box-lines 伸縮盒(新) flex flex-grow flex-shrink flex-basis flex-flow flex-direction flex-wrap align-content align-items align-self justify-content order 變換 transform transform-origin transform-style perspective perspective-origin backface-visibility 過渡 transition transition-property transition-duration transition-timing-function transition-delay 動(dòng)畫 animation animation-name animation-duration animation-timing-function animation-delay animation-iteration-count animation-direction animation-play-state animation-fill-mode 打印 page page-break-before page-break-after page-break-inside 媒體查詢 width height device-width device-height orientation aspect-ratio device-aspect-ratio color color-index monochrome resolution scan grid Only IE scrollbar-3dlight-color scrollbar-darkshadow-color scrollbar-highlight-color scrollbar-shadow-color scrollbar-arrow-color scrollbar-face-color scrollbar-track-color scrollbar-base-color filter behavior Only webkit -webkit-text-fill-color -webkit-text-stroke -webkit-text-stroke-width -webkit-text-stroke-color -webkit-box-reflect -webkit-tap-highlight-color -webkit-user-drag -webkit-overflow-scrolling 選擇符 元素選擇符 通配選擇符(*) 類型選擇符(E) ID選擇符(E#id) 類選擇符(E.class) 關(guān)系選擇符 包含選擇符(E F) 子選擇符(E>F) 相鄰選擇符(E+F) 兄弟選擇符(E~F) 屬性選擇符 E[att] E[att="val"] E[att~="val"] E[att^="val"] E[att$="val"] E[att*="val"] E[att|="val"] 偽類選擇符 E:link E:visited E:hover E:active E:focus E:lang(fr) E:not(s) E:root E:first-child E:last-child E:only-child E:nth-child(n) E:nth-last-child(n) E:first-of-type E:last-of-type E:only-of-type E:nth-of-type(n) E:nth-last-of-type(n) E:empty E:checked E:enabled E:disabled E:target @page:first @page:left @page:right 偽對(duì)象選擇符 E:first-letter/E::first-letter E:first-line/E::first-line E:before/E::before E:after/E::after E::placeholder E::selection 語(yǔ)法與規(guī)則 !important /*comment*/ @import @charset @media @font-face @page @keyframes @supports 取值與單位 長(zhǎng)度 <length> em ex ch rem vw vh vmax vmin cm mm q in pt pc px 角度 <angle> deg grad rad turn 時(shí)間 <time> s ms 頻率 <frequency> Hz kHz 布局 <fraction> <grid> fr gr 分辨率 <resolution> dpi dpcm dppx 顏色 <color> Color Name HEX RGB RGBA HSL HSLA transparent currentColor 文本 inherit initial unset <string> <url> <identifier> 函數(shù) calc() toggle() 生成內(nèi)容 counter() counters() attr() 圖像 <image> image() image-set() <gradient> linear-gradient() radial-gradient() repeating-linear-gradient() repeating-radial-gradient() 數(shù)字 <number> <integer> <percentage> 附錄 顏色關(guān)鍵字 媒體類型 CSS Hack 條件Hack 屬性級(jí)Hack 選擇符級(jí)Hack 問題和經(jīng)驗(yàn) Bugs和解決方案 技巧和經(jīng)驗(yàn) 其它經(jīng)驗(yàn)
characters

CSS技巧和經(jīng)驗(yàn)列表(以下實(shí)例默認(rèn)運(yùn)行環(huán)境都為Standard mode):

  1. 如何清除圖片下方出現(xiàn)幾像素的空白間隙?

    方法1:

    img{display:block;}

    方法2:

    img{vertical-align:top;}

    除了top值,還可以設(shè)置為text-top | middle | bottom | text-bottom,甚至特定的<length>和<percentage>值都可以

    方法3:

    #test{font-size:0;line-height:0;}

    #test為img的父元素

  2. 如何讓文本垂直對(duì)齊文本輸入框?

    方法:

    input{vertical-align:middle;}
  3. 如何讓單行文本在容器內(nèi)垂直居中?

    方法:

    #test{height:25px;line-height:25px;}

    只需設(shè)置文本的行高等于容器的高度即可

  4. 如何讓超鏈接訪問后和訪問前的顏色不同且訪問后仍保留hover和active效果?

    方法:

    a:link{color:#03c;}
    a:visited{color:#666;}
    a:hover{color:#f30;}
    a:active{color:#c30;}

    按L-V-H-A的順序設(shè)置超鏈接樣式即可,可速記為L(zhǎng)oVe(喜歡)HAte(討厭)

  5. 為什么Standard mode下IE無(wú)法設(shè)置滾動(dòng)條的顏色?

    方法:

    html{
    	scrollbar-3dlight-color:#999;
    	scrollbar-darkshadow-color:#999;
    	scrollbar-highlight-color:#fff;
    	scrollbar-shadow-color:#eee;
    	scrollbar-arrow-color:#000;
    	scrollbar-face-color:#ddd;
    	scrollbar-track-color:#eee;
    	scrollbar-base-color:#ddd;
    }

    將原來設(shè)置在body上的滾動(dòng)條顏色樣式定義到html標(biāo)簽選擇符上即可

  6. 如何使文本溢出邊界不換行強(qiáng)制在一行內(nèi)顯示?

    方法:

    #test{width:150px;white-space:nowrap;}

    設(shè)置容器的寬度和white-space為nowrap即可,其效果類似<nobr>標(biāo)簽

  7. 如何使文本溢出邊界顯示為省略號(hào)?

    方法(此方法Firefox5.0尚不支持):

    #test{width:150px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}

    首先需設(shè)置將文本強(qiáng)制在一行內(nèi)顯示,然后將溢出的文本通過overflow:hidden截?cái)?,并以text-overflow:ellipsis方式將截?cái)嗟奈谋撅@示為省略號(hào)。

  8. 如何使連續(xù)的長(zhǎng)字符串自動(dòng)換行?

    方法:

    #test{width:150px;word-wrap:break-word;}

    word-wrap的break-word值允許單詞內(nèi)換行

  9. 如何清除浮動(dòng)?

    方法1:

    #test{clear:both;}

    #test為浮動(dòng)元素的下一個(gè)兄弟元素

    方法2:

    #test{display:block;zoom:1;overflow:hidden;}

    #test為浮動(dòng)元素的父元素。zoom:1也可以替換為固定的width或height

    方法3:

    #test{zoom:1;}
    #test:after{display:block;clear:both;visibility:hidden;height:0;content:'';}

    #test為浮動(dòng)元素的父元素

  10. 如何定義鼠標(biāo)指針的光標(biāo)形狀為手型并兼容所有瀏覽器?

    方法:

    #test{cursor:pointer;}

    若將cursor設(shè)置為hand,將只有IE和Opera支持,且hand為非標(biāo)準(zhǔn)屬性值

  11. 如何讓已知高度的容器在頁(yè)面中水平垂直居中?

    方法:

    #test{position:absolute;top:50%;left:50%;width:200px;height:200px;margin:-100px 0 0 -100px;}

    Know More:已知高度的容器如何在頁(yè)面中水平垂直居中

  12. 如何讓未知尺寸的圖片在已知寬高的容器內(nèi)水平垂直居中?

    方法:

    #test{display:table-cell;*display:block;*position:relative;width:200px;height:200px;text-align:center;vertical-align:middle;}
    #test p{*position:absolute;*top:50%;*left:50%;margin:0;}
    #test p img{*position:relative;*top:-50%;*left:-50%;vertical-align:middle;}

    #test是img的祖父節(jié)點(diǎn),p是img的父節(jié)點(diǎn)。Know More:未知尺寸的圖片如何水平垂直居中

  13. 如何設(shè)置span的寬度和高度(即如何設(shè)置內(nèi)聯(lián)元素的寬高)?

    方法:

    span{display:block;width:200px;height:100px;}

    要使內(nèi)聯(lián)元素可以設(shè)置寬高,只需將其定義為塊級(jí)或者內(nèi)聯(lián)塊級(jí)元素即可。所以方法非常多樣,既可以設(shè)置display屬性,也可以設(shè)置float屬性,或者position屬性等等。

  14. 如何給一個(gè)元素定義多個(gè)不同的css規(guī)則?

    方法:

    .a{color:#f00;}
    .b{background:#eee;}
    .c{background:#ccc;}
    
    <div class="a b">測(cè)試1</div>
    <div class="a c">測(cè)試2</div>

    多個(gè)規(guī)則之間使用空格分開,并且只有class能同時(shí)使用多個(gè)規(guī)則,id不可以

  15. 如何讓某個(gè)元素充滿整個(gè)頁(yè)面?

    方法:

    html,body{height:100%;margin:0;}
    #test{height:100%;}
  16. 如何讓某個(gè)元素距離窗口上右下左4邊各10像素?

    方法:

    html,body{height:100%;margin:0;}
    html{_padding:10px;}
    #test{position:absolute;top:10px;right:10px;bottom:10px;left:10px;_position:static;_height:100%;}
  17. 如何去掉超鏈接的虛線框?

    方法:

    a{outline:none;}

    IE7及更早瀏覽器由于不支持outline屬性,需要通過js的blur()方法來實(shí)現(xiàn),如<a onfocus="this.blur();"...

  18. 如何容器透明,內(nèi)容不透明?

    方法1:

    .outer{width:200px;height:200px;background:#000;filter:alpha(opacity=20);opacity:.2;}
    .inner{width:200px;height:200px;margin-top:-200px;}
    
    <div class="outer"><!--我是透明的容器--></div>
    <div class="inner">我是不透明的內(nèi)容</div>

    原理是容器層與內(nèi)容層并級(jí),容器層設(shè)置透明度,內(nèi)容層通過負(fù)margin或者position絕對(duì)定位等方式覆蓋到容器層上

    方法2:

    .outer{width:200px;height:200px;background:rgba(0,0,0,.2);background:#000\9;filter:alpha(opacity=20)\9;}
    .outer .inner{position:relative\9;}
    
    <div class="outer">
    	<div class="inner">我是不透明的內(nèi)容</div>
    </div>

    高級(jí)瀏覽器直接使用rgba顏色值實(shí)現(xiàn);IE瀏覽器在定義容器透明的同時(shí),讓子節(jié)點(diǎn)相對(duì)定位,也可達(dá)到效果

  19. 如何讓整個(gè)頁(yè)面水平居中?

    方法:

    body{text-align:center;}
    #test2{width:960px;margin:0 auto;text-align:left;}

    定義body的text-align值為center將使得IE5.5也能實(shí)現(xiàn)居中

  20. 為什么容器的背景色沒顯示出來?為什么容器無(wú)法自適應(yīng)內(nèi)容高度?

    方法:

    清除浮動(dòng),方法請(qǐng)參考本頁(yè)第9條

    通常出現(xiàn)這樣的情況都是由于沒有清除浮動(dòng)而引起的,所以Debug時(shí)應(yīng)第一時(shí)間想到是否有未清除浮動(dòng)的地方

  21. 如何做1像素細(xì)邊框的table?

    方法1:

    #test{border-collapse:collapse;border:1px solid #ddd;}
    #test th,#test td{border:1px solid #ddd;}
    
    <table id="test">
    	<tr><th>姓名</th><td>Joy Du</td></tr>
    	<tr><th>年齡</th><td>26</td></tr>
    </table>

    方法2:

    #test{border-spacing:1px;background:#ddd;}
    #test tr{background:#fff;}
    
    <table id="test" cellspacing="1">
    	<tr><th>姓名</th><td>Joy Du</td></tr>
    	<tr><th>年齡</th><td>26</td></tr>
    </table>

    IE7及更早瀏覽器不支持border-spacing屬性,但是可以通過table的標(biāo)簽屬性cellspacing來替代。

  22. 如何使頁(yè)面文本行距始終保持為n倍字體大小的基調(diào)?

    方法:

    body{line-height:n;}

    注意,不要給n加單位。Know More:如何使頁(yè)面文本行距始終保持為n倍字體大小的基調(diào)

  23. 標(biāo)準(zhǔn)模式Standard mode和怪異模式Quirks mode下的盒模型區(qū)別?

    方法:

    標(biāo)準(zhǔn)模式下:Element width = width + padding + border
    怪異模式下:Element width = width

    相關(guān)資料請(qǐng)參閱CSS3屬性box-sizing

  24. 以圖換字的幾種方法及優(yōu)劣分析

    思路1:使用text-indent的負(fù)值,將內(nèi)容移出容器

    .test1{width:200px;height:50px;text-indent:-9999px;background:#eee url(*.png) no-repeat;}
    
    <div class="test">以圖換字之內(nèi)容負(fù)縮進(jìn)法</div>

    該方法優(yōu)點(diǎn)在于結(jié)構(gòu)簡(jiǎn)潔,不理想的地方:1.由于使用場(chǎng)景不同,負(fù)縮進(jìn)的值可能會(huì)不一樣,不易抽象成公用樣式;2.當(dāng)該元素為鏈接時(shí),在非IE下虛線框?qū)⒆兊貌煌暾?.如果該元素被定義為內(nèi)聯(lián)級(jí)或者內(nèi)聯(lián)塊級(jí),不同瀏覽器下會(huì)有較多的差異

    思路2:使用display:none或visibility:hidden將內(nèi)容隱藏;

    .test{width:200px;height:50px;background:#eee url(*.png) no-repeat;}
    .test span{visibility:hidden;/* 或者display:none */}
    
    <div class="test"><span>以圖換字之內(nèi)容隱藏法</span></div>

    該方法優(yōu)點(diǎn)在于兼容性強(qiáng)并且容易抽象成公用樣式,缺點(diǎn)在于結(jié)構(gòu)較復(fù)雜

    思路3:使用padding或者line-height將內(nèi)容擠出容器之外;

    .test{overflow:hidden;width:200px;height:0;padding-top:50px;background:#eee url(*.png) no-repeat;}
    .test{overflow:hidden;width:200px;height:50px;line-height:50;background:#eee url(*.jpg) no-repeat;}
    
    <div class="test">以圖換字之內(nèi)容排擠法</div>

    該方法優(yōu)點(diǎn)在于結(jié)構(gòu)簡(jiǎn)潔,缺點(diǎn)在于:1.由于使用場(chǎng)景不同,padding或line-height的值可能會(huì)不一樣,不易抽象成公用樣式;2.要兼容IE5.5及更早瀏覽器還得hack

    思路4:使用超小字體和文本全透明法;

    .test{overflow:hidden;width:200px;height:50px;font-size:0;line-height:0;color:rgba(0,0,0,0);background:#eee url(*.png) no-repeat;}
    
    <div class="test">以圖換字之超小字體+文本全透明法</div>

    該方法結(jié)構(gòu)簡(jiǎn)單易用,推薦使用

  25. 為什么2個(gè)相鄰div的margin只有1個(gè)生效?

    方法:

    .box1{margin:10px 0;}
    .box2{margin:20px 0;}
    
    <div class="box1">box1</div>
    <div class="box2">box2</div>

    本例中box1的底部margin為10px,box2的頂部margin為20px,但表現(xiàn)在頁(yè)面上2者之間的間隔為20px,而不是預(yù)想中的10+20px=30px,結(jié)果是選擇2者之間最大的那個(gè)margin,我們把這種機(jī)制稱之為“外邊距合并”;外邊距合并不僅僅出現(xiàn)在相鄰的元素間,父子間同樣會(huì)出現(xiàn)。

    簡(jiǎn)單列舉幾點(diǎn)注意事項(xiàng):
     外邊距合并只出現(xiàn)在塊級(jí)元素上;
     浮動(dòng)元素不會(huì)和相鄰的元素產(chǎn)生外邊距合并;
     絕對(duì)定位元素不會(huì)和相鄰的元素產(chǎn)生外邊距合并;
     內(nèi)聯(lián)塊級(jí)元素間不會(huì)產(chǎn)生外邊距合并;
     根元素間不會(huì)不會(huì)產(chǎn)生外邊距合并(如html與body間);
     設(shè)置了屬性overflow且值不為visible的塊級(jí)元素不會(huì)與它的子元素發(fā)生外邊距合并;

  26. 如何在文本框中禁用中文輸入法?

    方法:

    input,textarea{ime-mode:disabled;}

    ime-mode為非標(biāo)準(zhǔn)屬性,寫該文檔時(shí)只有IE和Firefox支持

  27. 如何解決列表中l(wèi)ist-style-image不能精準(zhǔn)定位的問題?

    方法:

    不使用list-style-image來定義列表項(xiàng)目標(biāo)記符號(hào),而用background-image來代替,并通過background-position來進(jìn)行定位
  28. 如何解決偽對(duì)象:before和:after在input標(biāo)簽上的怪異表現(xiàn)的問題?

    現(xiàn)象:

    在編寫本條目時(shí),除了Opera,在所有瀏覽器下input標(biāo)簽使用偽對(duì)象:before和:after都沒有效果,即使Opera的表現(xiàn)也同樣令人詫異。大家可以試玩一下。瀏覽器版本:IE6-IE10, Firefox6.0, Chrome13.0, Safari5.1, Opera11.51
  29. 如何解決偽對(duì)象:before和:after無(wú)法在Chrome,Safari,Opera上定義過渡和動(dòng)畫的問題?

    現(xiàn)象:

    在編寫本條目時(shí),除了Firefox,在所有瀏覽器下偽對(duì)象:before和:after無(wú)法定義過渡和動(dòng)畫效果。瀏覽器版本:IE6-IE10, Firefox6.0, Chrome13.0, Safari5.1, Opera11.51。如果這個(gè)過渡或動(dòng)畫效果是必須,可以考慮使用真實(shí)對(duì)象。


Previous article: Next article: