样式表与选择器

样式表的分类:

内联样式表:<div style=""></ div>   样式写在标签里    (代码重用性差,但控制精确)

内嵌样式表:<style type="text/css"></style>  嵌在网页的某个位置    (代码重用性高一些,控制性不如内联精确)

外部样式表:<link href="Untitled—2.css" rel="stylesheet" type="text/css"/>   样式是写在一个外部文件里面  (代码重用性最高,控制精确度最低) 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text.css">样式文字</style>
<link href="Untitled-2.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div style="">文字</div>
</body>
</html>

通过选择器找元素:

id=""   每个元素都可以加,id不能重复,以字母开头

class=""  类名,每个元素都可以加,可重复

name=""  只针对于表单元素

标签选择器  div{放样式}多个元素

ID选择器  以“#”开头,#title{}只能取到一个元素

class选择器   .biaoti{} 多个元素

特殊的   *{} 所有元素

复合选择器

1)用","隔开表示并列      div,span   逗号

2)用空格隔开,表示后代     #title  a      空格

3)筛选"."    div.biaoti       点

关于样式表的优先级:内联>内嵌=外部

关于选择器的优先级:id选择器>class选择器>标签选择器> *所有

!important 打破优先级最优先

 

原文地址:https://www.cnblogs.com/jgjk/p/6963737.html