提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
4.4 KiB

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <!--外部CSS
  8. 只需修改一个文件即可改变整个网站的外观
  9. -->
  10. <link rel="stylesheet" type="text/css" href="mystyle.css">
  11. <style>
  12. /*内部CSS
  13. 在 head 部分的 <style>
  14. */
  15. /*元素选择器*/
  16. p {
  17. text-align: center;
  18. color: red;
  19. border: 2px solid red;
  20. border-radius: 5px;/*圆角边框*/
  21. }
  22. /*id选择器*/
  23. #para1 {
  24. text-align: center;
  25. color: red;
  26. }
  27. /*类选择器*/
  28. .center {
  29. text-align: center;
  30. color: red;
  31. }
  32. /*通配符选择器 * { } */
  33. /*分组选择器*/
  34. h1, h2, p {
  35. text-align: center;
  36. color: red;
  37. }
  38. /*设置背景颜色
  39. 有效的颜色名称 - 比如 "red"
  40. 十六进制值 - 比如 "#ff0000"
  41. RGB 值 - 比如 "rgb(255,0,0)"
  42. */
  43. body {
  44. background-color: lightblue;
  45. /*background: rgba(0, 128, 0, 0.3) 30% 不透明度的绿色背景 */
  46. background-image: url("paper.gif");/*背景图像*/
  47. background-repeat: repeat-x;/*背景图像重复方式 repeat-y垂直*/
  48. background-position: right top;/*背景图像位置*/
  49. background-attachment: fixed;/*背景图像是否随内容滚动 scroll*/
  50. /*简写属性顺序:
  51. background-color
  52. background-image
  53. background-repeat
  54. background-attachment
  55. background-position
  56. */
  57. }
  58. /*盒模型
  59. 每个 HTML 元素都可以看作是一个盒子
  60. 总元素的宽度=宽度+左填充+右填充+左边框+右边框+左边距+右边距
  61. 盒子模型由四个部分组成:
  62. 边距(margin):清除元素周围的区域,外边距是透明的
  63. 边框(border):围绕内边距和内容的边框
  64. 内边距(padding):清除内容周围的区域,内边距也是透明的
  65. 内容(content):包含文本和图像的实际内容
  66. */
  67. div {
  68. width: 300px;
  69. border: 25px solid green;
  70. padding: 25px;
  71. margin: 25px; /*水平居中用 auto*/
  72. }
  73. p.ex {
  74. outline: 5px solid yellow; /*轮廓线,不占空间*/
  75. outline-offset: 25px;/*轮廓线与元素边框的距离*/
  76. }
  77. a {
  78. text-decoration: none;
  79. }
  80. /* unvisited link */
  81. a:link {
  82. color: red;
  83. }
  84. /* visited link */
  85. a:visited {
  86. color: green;
  87. }
  88. /* mouse over link */
  89. a:hover {
  90. color: hotpink;
  91. }
  92. /* selected link */
  93. a:active {
  94. color: blue;
  95. }
  96. </style>
  97. </head>
  98. <body>
  99. <!--
  100. CSS 指的是层叠样式表* (Cascading Style Sheets)
  101. CSS 描述了如何在屏幕、纸张或其他媒体上显示 HTML 元素
  102. CSS 节省了大量工作。它可以同时控制多张网页的布局
  103. 外部样式表存储在 CSS 文件中-->
  104. <p>每个段落都会受到样式的影响。</p>
  105. <p id="para1">1111111</p>
  106. <h1 class="center">居中的红色标题</h1>
  107. <p class="center">居中的红色段落。</p>
  108. <!--行内CSS
  109. 在相关元素的 "style" 属性中定义
  110. -->
  111. <h1 style="color:blue;text-align:center;">This is a heading</h1>
  112. <!--如果在不同样式表中为同一选择器(元素)定义了一些属性
  113. 则将使用最后读取的样式表中的值。
  114. 层叠顺序:行内样式(在 HTML 元素中)
  115. 外部和内部样式表(在 head 部分)
  116. 浏览器默认样式
  117. -->
  118. <!--边框颜色-->
  119. <h1 style="border:2px solid Tomato;">Hello World</h1>
  120. <h1 style="background-color:rgb(255, 99, 71);">...</h1><!--红绿蓝-->
  121. <h1 style="background-color:#ff6347;">...</h1><!--十六进制-->
  122. <h1 style="background-color:hsl(9, 100%, 64%);">...</h1><!--色相、饱和度和明度-->
  123. <p class="ex">5 像素的黄色实线轮廓。</p>
  124. <p>没有下划线的链接:
  125. <a href="https://www.w3school.com.cn">W3School.com.cn</a>
  126. </p>
  127. <h1>CSS 链接</h1>
  128. <p><b><a href="/index.html" target="_blank">这是一个链接</a></b></p>
  129. <!--在 CSS 定义中
  130. a:hover 必须位于 a:link 和 a:visited 之后才能生效。
  131. a:active 必须位于 a:hover 之后才能生效。-->
  132. <!--导航菜单=链接列表-->
  133. <ul>
  134. <li><a href="#home">Home</a></li>
  135. <li><a href="#news">News</a></li>
  136. <li><a href="#contact">Contact</a></li>
  137. <li><a href="#about">About</a></li>
  138. </ul>
  139. </body>
  140. </html>