博客列表 >html文档结构及元素样式定义

html文档结构及元素样式定义

leverWang
leverWang原创
2020年06月12日 15:03:281087浏览

html文档结构

  1. <html>
  2. <head>
  3. <meta charset='UTF-8'>
  4. <title>网页文档标题</title>
  5. </head>
  6. <body>
  7. 网页内容
  8. </body>
  9. </html>

html元素的三大通用属性

  • id相当于身份证,用来唯一标示网页元素
  • class相当于标签的类属性,用于元素分类
  • style属性是用来描述元素样式

    例子:

<h1 id="abc" class="ab" style="color:red;">example</h1>


元素,类,id不同级别的样式规则

id 用#来定义样式,例如:

  1. <style>
  2. #example{
  3. background-color: blue;
  4. }
  5. </style>
  6. <div id="example">示例</div>

类class 用.来定义样式,例如:

  1. <style>
  2. .example{
  3. background-color: blue;
  4. }
  5. </style>
  6. <div class="example">示例</div>

元素用标签来定义样式,例如:

  1. <style>
  2. p{
  3. background-color: red;
  4. }
  5. </style>
  6. <p>示例</p>

样式优先级style>id>class ,内联式css样式表,优先级最高的样式表,会覆盖元素,类,id中相同的样式,下例中内联样式的绿色背景色会覆盖id,class中定义的背景色

  1. <style>
  2. #example{
  3. background-color: blue;
  4. }
  5. .example{
  6. background-color: yellow;
  7. }
  8. p{
  9. background-color: red;
  10. }
  11. </style>
  12. <p id="example" class="example" style="background-color: green;">示例</p>
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议