CSS 指层叠样式表 (Cascading Style Sheets)

CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明。

 h1 {color:red; font-size:14px;} h1为选择器,color:red为声明,color为属性,red为值,多个声明用分号;隔开

派生选择器 li strong { font-style: italic; font-weight: normal; } 只有li 元素中的 strong 元素的样式为斜体字

id选择器以"#"来定义 #red {color:red;}  <p id="red">这个段落是红色。</p> 

类选择器以"."为开头 .center {text-align: center}  <h1 class="center"> This heading will be center-aligned </h1> 

属性选择器 [title] { color:red; } 属性和值选择器 [title=W3School] { border:5px solid blue; } 指定值的 title 属性的所有元素设置样式 [title~=hello] { color:red; } 

插入样式表

外部样式表 <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head> 

内部样式表  使用<style></style>

<head>
<style type="text/css">
  hr {color: sienna;}
  p {margin-left: 20px;}
  body {background-image: url("images/back40.gif");}
</style>
</head>

内联样式 <p style="color: sienna; margin-left: 20px"> This is a paragraph </p> 

背景色 p {background-color: gray;} 

背景图像 body {background-image: url(/i/eg_bg_04.gif);} 

背景定位 background-position:center; 

posted on 2020-04-23 16:57  邓阮叶  阅读(191)  评论(0)    收藏  举报