溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

CSS初始化的方法

發(fā)布時(shí)間:2021-08-10 22:41:51 來源:億速云 閱讀:137 作者:chen 欄目:web開發(fā)

這篇文章主要講解了“CSS初始化的方法”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“CSS初始化的方法”吧!


為什么要初始化CSS?

CSS初始化是指重設(shè)瀏覽器的樣式。不同的瀏覽器默認(rèn)的樣式可能不盡相同,所以開發(fā)時(shí)的第一件事可能就是如何把它們統(tǒng)一。如果沒對(duì)CSS初始化往往會(huì)出現(xiàn)瀏覽器之間的頁面差異。每次新開發(fā)網(wǎng)站或新網(wǎng)頁時(shí)候通過初始化CSS樣式的屬性,為我們將用到的CSS或html標(biāo)簽更加方便準(zhǔn)確,使得我們開發(fā)網(wǎng)頁內(nèi)容時(shí)更加方便簡潔,同時(shí)減少CSS代碼量,節(jié)約網(wǎng)頁下載時(shí)間。
CSS初始化示例代碼

CSS Code復(fù)制內(nèi)容到剪貼板

  1. /* css reset www.admin10000.com */  

  2. body,div,dl,dt,dd,ul,ol,li,h2,h3,h4,h5,h6,h7,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { margin:0; padding:0; }   

  3. body { background:#fffcolor:#555font-size:14pxfont-familyVerdanaArialHelveticasans-serif; }   

  4. td,th,caption { font-size:14px; }   

  5. h2, h3, h4, h5, h6, h7 { font-weight:normalfont-size:100%; }   

  6. address, caption, cite, code, dfn, em, strong, th, var { font-style:normalfont-weight:normal;}   

  7. a { color:#555text-decoration:none; }   

  8. a:hover { text-decoration:underline; }   

  9. img { border:none; }   

  10. ol,ul,li { list-style:none; }   

  11. input, textarea, select, button { font:14px Verdana,Helvetica,Arial,sans-serif; }   

  12. table { border-collapse:collapse; }   

  13. html {overflow-y: scroll;}   

  14. /* css common */  

  15. .clearfix:after {content"."displayblockheight:0; clear:bothvisibilityhidden;}   

  16. .clearfix { *zoom:1; }  

上面是CSS重置代碼,這段代碼是我比較喜歡用的一種方式,雖然還不夠完美但是常用的幾乎已經(jīng)都包括了。 

下面順便給出html模板,用于每次新開發(fā)頁面使用。

XML/HTML Code復(fù)制內(nèi)容到剪貼板

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  

  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">  

  3. <head>  

  4.   <title>網(wǎng)站標(biāo)題 - Admin10000.com </title>  

  5.  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

  6.  <meta http-equiv="Content-Language" content="zh-CN" />  

  7.  <meta name="Author" content="網(wǎng)頁作者" />    

  8.  <meta name="Copyright" content="網(wǎng)站版權(quán)" />    

  9.  <meta name="keywords" content="網(wǎng)站關(guān)鍵字" />  

  10.  <meta name="description" content="網(wǎng)站描述" />  

  11.  <link rel="Shortcut Icon" href="網(wǎng)站.ico圖標(biāo)路徑" />  

  12.  <link type="text/css" rel="stylesheet" href="CSS文件路徑" />  

  13.  <script type="text/javascript" src="JS文件路徑"></script>  

  14. </head>  

  15. <body>  

  16. </body>  

  17. </html>  

感謝各位的閱讀,以上就是“CSS初始化的方法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)CSS初始化的方法這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

css
AI