CSS樣式控制頁面的幾種方式

來源:互聯網
上載者:User

1.行內樣式。

把樣式寫在元素標記之間。

<p style="font-size:24px;color:#aaafff">用css控制頁面樣式的行內樣式</p>

2.內嵌式

把樣式寫在head之間,並且用<style></style>包括起來。

<head><style>

p{

font-size:24px;

}

</style></head>

3、連結式

連結式是使用頻率最高,最為實用的方式。實現了html代碼和css樣式完全分離,前期美工和後期維護都十分方便,也有助於前端和後台開發人員同時進行。使用樣式的時候才連結

<link   href="demo.css"  type="text/css" rel="stylesheet">

4、匯入式

和連結式差不多,只是文法不一樣。在html格式化的時候,匯入式把css檔案匯入,作為html的一部分。效果類似於內嵌時。也可以在css檔案裡面匯入其他的樣式檔案。

<style>

<import url="demo.css">

</style>

優先順序別(最高-》最低):

行內樣式——》連結式——》內嵌式——》a匯入式。

設計網站的時候,最好使用1-2中方式,有助於後期的維護。防止樣式撞車。

相關文章

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.