前言


一、认识

From: http://www.runoob.com/css/css-tutorial.html

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

解决内容与表现分离的问题。

 

 

二、结构

  • 形式:属性-值

[UI] 01 - CSS

 

  • class 选择器
<style>
body {background-color:tan;}
h1   {color:maroon;font-size:20pt;}
hr   {color:navy;}
p    {font-size:11pt;margin-left:15px;}
a:link    {color:green;}
a:visited {color:yellow;}
a:hover   {color:black;}
a:active  {color:blue;}
</style>

 

  • id 选择器
<style>
#para1
{
    text-align:center;
    color:red;
} 
</style>
</head>

<body>
<p >Hello World!</p>
</body>

 

  • 分组 选择器 

为了尽量减少代码,你可以使用分组选择器。

h1
{
    color:green;
}
h2
{
    color:green;
}
p
{
    color:green;
}
----------------> 简写为如下
h1,h2,p
{
    color:green;
}

 

  • 嵌套 选择器
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8"> 
  <title>菜鸟教程(runoob.com)</title> 
  <style>   p   {    color:blue;    text-align:center;   }   .marked   {    background-color:red;   }   .marked p   {    color:white;   }   p.marked{    text-decoration:underline;   }   </style>
</head> <body>   <p>这个段落是蓝色文本,居中对齐。</p>   <div class="marked">     <p>这个段落不是蓝色文本。</p>   </div>   <p>所有 class="marked"元素内的 p 元素指定一个样式,但有不同的文本颜色。</p>   <p class="marked">带下划线的 p 段落。</p> </body> </html>
p{ }: 为所有 p 元素指定一个样式。
.marked{ }: 为所有 class="marked" 的元素指定一个样式。
.marked p{ }: 为所有 class="marked" 元素内的 p 元素指定一个样式。
p.marked{ }: 为所有 class="marked" 的 p 元素指定一个样式。
设置了三个样式

相关文章:

  • 2022-12-23
  • 2021-10-07
  • 2021-12-09
  • 2022-01-15
  • 2021-10-11
  • 2022-02-01
  • 2021-12-06
  • 2022-03-07
猜你喜欢
  • 2022-12-23
  • 2021-09-10
  • 2022-12-23
  • 2021-12-13
  • 2021-12-12
  • 2021-06-20
  • 2021-11-13
相关资源
相似解决方案