04-button.html 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. <!-- 将body中要使用的样式 抽取到head中 -->
  8. <style>
  9. /* 对input元素生效 这里是css的注释方式*/
  10. /* input {
  11. width: 60px;
  12. height: 40px;
  13. background-color: bisque;
  14. border: 1px solid yellowgreen;
  15. font-size: 22px;
  16. font-family: '隶书';
  17. border-radius: 5px;
  18. } */
  19. /*
  20. 元素选择器
  21. 根据标签名找到要作用的范围
  22. */
  23. /*
  24. id选择器
  25. id是用来识别一个唯一元素的属性 id值是唯一的
  26. */
  27. /* #btn2 {
  28. width: 60px;
  29. height: 40px;
  30. background-color: bisque;
  31. border: 1px solid yellowgreen;
  32. font-size: 22px;
  33. font-family: '隶书';
  34. border-radius: 5px;
  35. } */
  36. /*
  37. class选择器
  38. 根据元素class属性的值 确定作用范围
  39. class属性 可以使用一个对应的样式 也可以使用多个
  40. */
  41. .shapeClass {
  42. width: 60px;
  43. height: 40px;
  44. border-radius: 5px;
  45. }
  46. .colorClass {
  47. background-color: bisque;
  48. border: 1px solid yellowgreen;
  49. color: red;
  50. }
  51. .fontClass {
  52. font-size: 22px;
  53. font-family: '隶书';
  54. }
  55. button {
  56. padding: 5px 16px;
  57. background-color: #f0f0f0;
  58. border: none;
  59. border-radius: 4px;
  60. transition: background-color 0.3s ease;
  61. }
  62. button:active {
  63. background-color: #007bff;
  64. color: white;
  65. }
  66. </style>
  67. </head>
  68. <body>
  69. <!-- 内嵌式 css -->
  70. <!-- 缺点:生效范围在当前的html页面中 如果想要复用这个效果 在新的页面还需要复制一份 -->
  71. <input id="btn1" class="shapeClass colorClass fontClass" type="button" value="按钮1" />
  72. <br />
  73. <br />
  74. <input id="btn2" class="shapeClass" type="button" value="按钮2" />
  75. <br />
  76. <br />
  77. <input id="btn3" class="fontClass" type="button" value="按钮3" />
  78. <br />
  79. <br />
  80. <button id="btn4">按钮</button>
  81. </body>
  82. </html>