行内样式

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport"
  7. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum=1.0, user-scalable=no">
  8. <title>行内样式</title>
  9. </head>
  10. <body>
  11. <!--
  12. width:宽度
  13. height:高度
  14. background-color:背景颜色
  15. -->
  16. <div style="width: 100%; height: 100px; background-color: red;"></div>
  17. </body>
  18. </html>

image.png

内部样式

<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum=1.0, user-scalable=no">
  <title>内部样式</title>
  <style>
    div {
      width: 100%;
      height: 100px;
      background-color: skyblue;
    }
  </style>
</head>

<body>
  <div></div>
</body>

</html>

image.png

外部样式

<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum=1.0, user-scalable=no">
  <title>外部样式</title>
  <link rel="stylesheet" href="style.css">
</head>

<body>
  <div></div>
</body>

</html>
div {
  width: 100%;
  height: 100px;
  background-color: greenyellow;
}

image.png