主題:關於CSS細節集合(一)

來源:互聯網
上載者:User

標籤:style   http   color   os   io   使用   java   strong   ar   

一、當文字與圖片在一行,需要將文字與圖片底對齊,需要這樣寫:
1 <li>記住密碼<img src="" align="bottom" style="margin-bottom:-4px"/></li>
二、當文字與圖片在一行,需要將文字與圖片置中對齊,需要這樣寫:
1 <li>記住密碼<img src="static/img/xyx.jpg" align="middle"/></li>
三、更改IE“查看原始碼”菜單開啟的編輯器
  1. 開啟登錄編輯程式,在開始-運行中輸入regedit前端UI分享
  2. 找到以下位置: HKEY_LOCAL_MACHINE”SOFTWARE”Microsoft”Internet Explorer”View SourceEditor”Editor Name”修改預設的資料為”D:”Program Files”EmEditor”EmEditor.exe”

切換到IE中查看原始碼就可以看到效果了。
如果View Source Editor”Editor Name項沒有,可以自己建立。

四、自動已最大化的視窗,在 <body> 與 </body> 之間加入:
1234 <SCRIPT language="javascript">setTimeout(‘top.moveTo(0,0)‘,5000);setTimeout(‘top.resizeTo(screen.availWidth,screen.availHeight)‘,5000);</script>
五、window.opener 實際上就是用window.open開啟的表單的父表單。

比如在父表單parentForm裡面 通過 window.open(“subForm.html”),那麼在subform.html中 window.opener
就代表parentForm,可以通過這種方式設定父表單的值或者調用js方法。

  1. window.opener.test(); —調用父表單中的test()方法;
  2. 如果window.opener存在,設定parentForm中stockBox的值。 前端UI分享
1234 if (window.opener && !window.opener.closed)    {       window.opener.document.parentForm.stockBox.value = symbol;    }
六、重新整理頁面的方法

Javascript重新整理頁面的方法:

  1. history.go(0)
  2. location.reload()
  3. location=location
  4. location.assign(location)
  5. document.execCommand(‘Refresh’)
  6. window.navigate(location)
  7. location.replace(location)
  8. document.URL=location.href

自動重新整理頁面的方法:

  1. 頁面自動重新整理:把<meta http-equiv=”refresh” content=”20″>加入<head>地區中
  2. 頁面自動跳轉:把<meta http-equiv=”refresh” content=”20;url=http://www.wyxg.com”>加入<head>地區中 前端UI分享
  3. js自動重新整理頁面:
1234567 <script language="JavaScript">function myrefresh(){       window.location.reload();}setTimeout(‘myrefresh()‘,1000); //指定1秒重新整理一次</script>
一、IE6及以下不識別a 標籤外的:hover偽類,在Firefox,IE7裡能正確達到效果,解決辦法:.代碼  
  1. #show li.s1{ border:1px solid #ff9900; background:#454242;}  
  2. #show li.s2{ border:1px solid #D9D8D8; background:#312E2E;}  

 

二、為元素設定hasLayout

很多IE6(或IE7)的問題可以用設定hasLayout值的方法來解決,最簡單的給元素設定hasLayout值的方法是給加上CSS 的height或width(當然,zoom也可以用,但這不是CSS的一部分)。比如設定為height:1%。如果父元素沒有設定高度,那麼元素的物理高度並不會改變,但是,已經具備hasLayout屬性。

三、IE6下字元重複出現

確保浮動元素設定了 display:inline;

在浮動元素中使用 margin-right:-3px;前端UI分享

四、樣式優先順序

1,內聯樣式 [1.0.0.0]
2,ID選取器 [0.1.0.0]
3,類,屬性,偽類 選取器 [0.0.1.0]
4,元素標籤,虛擬元素 選取器 [0.0.0.1]

五、一個元素垂直置中的css寫法.代碼  
  1. #exm{  
  2.     position:absolute;  
  3.     left:50%;  
  4.     top:50%;  
  5.     z-index:1;  
  6.     width:200px;  
  7.    
  8.     height:100px;  
  9.     margin-left:-100px;  
  10.     margin-top:-52px;  
  11. }  
 六、zoom : normal | number

設定或檢索對象的縮放比例。設定或更改一個已被呈遞的對象的此屬性值將導致環繞對象的內容重新流動。雖然此屬性不可繼承,但是它會影響對象的所有子物件( children )。前端UI分享

七、圖片跟文字並排時, 要實現圖片文字垂直置中:
  1. 將line-height:設定成圖片的高度,或者圖片父元素的高度.
  2. 再將圖片的CSS設定vertical-align:middle;
八、li 元素中包含 a img 元素的時候,IE6下出現空白

解決方案 一:

使 li 浮動,並設定 img 為區塊層級元素

解決方案 二:

設定 ul 的 font-size:0;

解決方案 三:

設定 img 的 vertical-align: bottom;

解決方案 四:

設定 img 的 margin-bottom: -5px;

九、被點擊瀏覽過的超連結樣式不在具有hover和active

解決方案:改變CSS屬性的排列順序: L-V-H-A

十、FF下連續長欄位不能自動換行

解決方案:

.代碼  
  1. div{word-wrap:break-word;overflow:hidden;}  
 十一、FF下父容器高度不能自適應

解決辦法:清除子項目的浮動

十二、IE片下方產生空隙

解決辦法:

  • 定義img 為display:block,或vertical-align為top/bottom/middle/text-bottom
  • 定義父容器的字型大小為零,font-size:0
十三、IE6下浮動元素和它相鄰的非浮動元素之間有3px空隙

解決辦法:

  • 相鄰的非浮動元素也設定浮動;
  • 浮動元素相對IE6定義_margin-right:-3px;
十四、LI內容超長後以省略符號顯示

解決辦法: white-space:nowrap;(文本不換行)text-overflow:ellipsis; -o-text-overflow:ellipsis; overflow: hidden;

十五、文本不能垂直置中

解決辦法:行高和容器高度相等line-height=height;

十六、文本輸入框和相鄰的文本不能對齊

解決辦法:設定文本輸入框vertical-align:middle;前端UI分享

十七、IE設定捲軸樣式

解決辦法:

.代碼  
  1. body{  
  2. scrollbar-face-color:#f6f6f6;  
  3. scrollbar-highlight-color:#fff;  
  4. scrollbar-shadow-color:#eeeeee;  
  5. scrollbar-3dlight-color:#eeeeee;  
  6. scrollbar-arrow-color:#000;  
  7. scrollbar-track-color:#fff;  
  8. scrollbar-darkshadow-color:#fff;  
  9. }  

 

十八、IE6無法定義高度為1px的容器

解決辦法:

.代碼  
  1. div{  
  2. overflow:hidden;  
  3. zoom:0.8;  
  4. line-height:1px;  
  5. }  
一、讓層顯示在flash之上

解決辦法:給FLASH設定透明<param name=”wmode” value=”transparent” />或者<param name=”wmode” value=”opaque” />

二、使一個層垂直置中瀏覽器中

解決辦法:使用百分比絕對位置,與外補丁負值的方法。

.代碼 
  1. {position:absolute;  
  2.     top:50%;  
  3.     left:50%;  
  4.     margin:-100px auto auto -100px;  
  5.     width:200px;  
  6.     height:200px;  
  7. }  
 三、加入收藏夾前端架構分享

解決辦法:

.代碼 
  1. <script type="text/javascript">  
  2. // <![CDATA[  
  3. function bookmark(){  
  4. var title=document.title  
  5. var url=document.location.href  
  6. if (window.sidebar) window.sidebar.addPanel(title, url,"");  
  7. else if( window.opera && window.print ){  
  8. var mbm = document.create_r_rElement_x(‘a‘);  
  9. mbm.setAttribute(‘rel‘,‘sidebar‘);  
  10. mbm.setAttribute(‘href‘,url);  
  11. mbm.setAttribute(‘title‘,title);  
  12. mbm.click();}  
  13. else if( document.all ) window.external.AddFavorite( url, title);  
  14. }  
  15. // ]]>  
  16. </script>  
 .代碼 
  1. <a href="javascript:bookmark()">加入收藏夾</a>  
 

四、IE實現頁面背景漸層(FF及chrome不支援)

從上到下:

.代碼 
  1. body{filter: progid:DXImageTransform.Microsoft.Gradient(gradientType=0,startColorStr=#ffffff,endColorStr=#000000);}  
 

左上至右下:

.代碼 
  1. body{  
  2. filte: Alpha( style=1,opacity=25,finishOpacity=100,startX=50,finishX=100,startY=50,finishY=100); skyblue;  
  3. }  
 

從左至右:

.代碼 
  1. body{FILTER: progid:DXImageTransform.Microsoft.Gradient(gradientType=1,startColorStr=#ffffff,endColorStr=#000000);}  
 

從上到下:

.代碼 
  1. style="filter:progid:DXImageTransform.microsoft.gradient(gradienttype=0,startColorStr=blue,endColorStr=white);"  
 五、border:none;與border:0區別

理論上的效能差異:

前端架構分享

border:0;把border設為“0”像素雖然在頁面上看不見,但按border預設值理解,瀏覽器依然對border-width/border-color進行了渲染,即已經佔用了記憶體值。border:none;把border設為“none”即沒有,瀏覽器解析“none”時將不作出渲染動作,即不會消耗記憶體值。

相容性差異:

相容性差異只針對瀏覽器IE6、IE7與標籤button、input而言,在win、win7、vista 的XP主題下均會出現此情況。

當border為“none”時似乎對IE6/7無效邊框依然存在,當border為“0”時,感覺比“none”更有效,所有瀏覽器都一致把邊框隱藏,如何讓border:none;實現全相容?只需要在同一選擇符上添加背景屬性即可

六、css實現多列等高布局,正內邊距與負外邊距

給每個需要實現等高的列應用樣式:

.代碼 
  1. .e{padding-bottom:32767px;margin-bottom:-32767px;}  
 

七、display:inline-block;顧名思義,就是在內聯情況下的塊狀,可以設定高度寬度。前端架構分享.代碼 
  1. .element-class {  
  2. display: -moz-inline-stack; //Firefox only code  
  3. display: inline-block; //some standard browsers  
  4. zoom: 1; //IE only  
  5. *display: inline; //Only IE know this code (CSS Hack)  
  6. }  
 八、清理浮動.代碼 
  1. .clearfix:after{visibility:hidden;display:block;font-size:0;content:" ";clear:both;height:0;}  
  2. .clearfix {zoom:1;}  

 

九、文字用省略符號截斷.代碼 
  1. div{width:200px;height:100px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}  
 

主題:關於CSS細節集合(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.