1. <html>
    2. <head>
    3. <meta charset="UTF-8">
    4. <!--内部样式表-->
    5. <style type="text/css">
    6. /*被style标签包围的范围是CSS环境,可以写CSS代码*/
    7. /*标签样式表*/
    8. p{
    9. color:red
    10. }
    11. /*类样式*/
    12. .f20{
    13. font.size:20px;
    14. }
    15. /*ID样式*/
    16. #p4{
    17. background-color:pink;
    18. font-size:24px;
    19. font-weight:bolder;
    20. font-style:italic;
    21. font-family:"华文彩云";
    22. }
    23. /*组合样式*/
    24. div p{
    25. color:blue;
    26. }
    27. div .f32{
    28. font-size:32px;
    29. font-family:"黑体";
    30. }
    31. </style>
    32. <!--外部样式表-->
    33. <link rel="stylesheet" href="CSS格式文件的地址">
    34. </head>
    35. <body>
    36. <!--
    37. <p><font color="red">这里是段落一<font></p>
    38. <p><font color="red">这里是段落二<font></p>
    39. -->
    40. <p>这里是段落一</p>
    41. <p>这里是段落二</p>
    42. <p class="f20">这里是段落三</p>
    43. <p id="p4">这里是段落四</p><!--id属性在整个HTML文档中,尽量保持唯一(虽然重复也不会报错)-->
    44. <div>
    45. <!--嵌入式样式表-->
    46. <p><span style="font-size:60px;font-weigth:bolder;color:yellow;">HELLO</span></p>
    47. <span class="f32">WORLD</span>
    48. <p class="f32">!!!</p>
    49. </div>
    50. </body>
    51. </html>
    52. <!--
    53. 1、为什么需要CSS
    54. 2、CSS的分类:标签样式表、类样式表、ID样式表、组合样式表
    55. 3、CSS从位置上的分类:嵌入式样式表、内部样式表、外部样式表
    56. -->
    1. <html>
    2. <head>
    3. <meta charset="UTF-8">
    4. <!--内部样式表-->
    5. <style type="text/css">
    6. #div1{
    7. width:400px;
    8. height:400px;
    9. background-color:greenyellow;
    10. /*border边框样式*/
    11. border-width:1px; /*边框粗细*/
    12. border-style:solid; /*边框样式:solid(实线),dotted(点状线)*/
    13. border-color:blue; /*边框颜色*/
    14. /*border:4px double blue;*/
    15. /*border-top:4px dotted blue;*/
    16. }
    17. #div2{
    18. width:150px;
    19. height:150px;
    20. background-color:darkorange;
    21. margin-top:100px;
    22. margin-left:100px;
    23. /*margin:100px 100px 50px 150px;*/ /*一个值,四个方向统一;两个值:上下、左右;三个值:上、左右、下;四个值:上右下左*/
    24. /*padding:填充*/
    25. padding-top:50px;
    26. padding-left:50px;
    27. }
    28. #div3{
    29. width:100px;
    30. height:100px;
    31. background-color:aquamarine;
    32. /*
    33. margin-top:50px;
    34. margin-left:50px;
    35. */
    36. }
    37. #div4{
    38. width:200px;
    39. height:200px;
    40. margin-left:100px;
    41. background-color:greenyellow;
    42. }
    43. body{
    44. margin:0;
    45. padding:0;'p
    46. }
    47. </style>
    48. </head>
    49. <body>
    50. <div id="div1">
    51. <div id="div2">
    52. <div id="div3">&nbsp;</div>
    53. </div>
    54. </div>
    55. <div id="div4">&nbsp;</div>
    56. </body>
    57. </html>
    58. <!--
    59. IE浏览器:实际尺寸=width
    60. Chrome浏览器:实际尺寸=width+左右border的width+padding的值
    61. 盒子模型:
    62. 1、border 边框
    63. 2、margin 间距
    64. 3、padding 填充
    65. -->
    1. <html>
    2. <head>
    3. <meta charset="utf-8">
    4. <style type="text/css">
    5. body{
    6. margin:0;
    7. padding:0;
    8. }
    9. #div1{
    10. width:200px;
    11. height:50px;
    12. background-color:greenyellow;
    13. /* 绝对定位 */
    14. position:absolute;
    15. left:100px;
    16. top:100px;
    17. }
    18. #div2{
    19. width:200px;
    20. height:50px;
    21. background-color:pink;
    22. position:relative;
    23. float:left;
    24. margin-left:20px;
    25. }
    26. #div3{
    27. height:50px;
    28. background-color:darkorange;
    29. }
    30. #div4{
    31. width:200px;
    32. height:50px;
    33. background-color:aqua;
    34. float:left;
    35. }
    36. #div5{
    37. width:200px;
    38. height:50px;
    39. background-color:olivedrab;
    40. float:left;
    41. }
    42. div{
    43. position:relative;
    44. }
    45. </style>
    46. </head>
    47. <body>
    48. <!--
    49. <div id="div1">&nbsp;</div>
    50. <div id="div2">&nbsp;</div>
    51. -->
    52. <div id="div3">
    53. <div id="div4">&nbsp;</div>
    54. <div id="div5">&nbsp;</div>
    55. </div>
    56. </body>
    57. </html>
    58. <!--
    59. position: absolute -- 绝对定位 , 需要配合使用 left , top
    60. relative -- 相对定位 , 一般会和 float , margin , padding .... 一起使用
    61. float
    62. -->
    1. <html>
    2. <head>
    3. <meta charset="utf-8">
    4. <style type="text/css">
    5. body{
    6. margin:0;
    7. padding:0;
    8. background-color:#808080;
    9. }
    10. div{
    11. position:relative;
    12. }
    13. #div_top{
    14. background-color: orange;
    15. height:20%;
    16. }
    17. #div_left{
    18. background-color: greenyellow;
    19. height:80%;
    20. width:15%;
    21. float:left;
    22. }
    23. #div_main{
    24. background-color: whitesmoke;
    25. height:70%;
    26. float:left;
    27. width:85%;
    28. }
    29. #div_bottom{
    30. background-color: sandybrown;
    31. height:10%;
    32. width:85%;
    33. float:left;
    34. }
    35. #div_container{
    36. width:80%;
    37. height:100%;
    38. border:0px solid blue;
    39. margin-left:10%;
    40. float:left;
    41. }
    42. </style>
    43. </head>
    44. <body>
    45. <div id="div_container">
    46. <div id="div_top">div_top</div>
    47. <div id="div_left">div_left</div>
    48. <div id="div_main">div_main</div>
    49. <div id="div_bottom">div_bottom</div>
    50. </div>
    51. </body>
    52. </html>
    1. <html>
    2. <head>
    3. <meta charset="utf-8">
    4. <link rel="stylesheet" href="css/demo05.css">
    5. </head>
    6. <body>
    7. <div id="div_container">
    8. <div id="div_fruit_list">
    9. <table id="tbl_fruit">
    10. <tr>
    11. <th class="w20">名称</th>
    12. <th class="w20">单价</th>
    13. <th class="w20">数量</th>
    14. <th class="w20">小计</th>
    15. <th>操作</th>
    16. </tr>
    17. <tr>
    18. <td>苹果</td>
    19. <td>5</td>
    20. <td>20</td>
    21. <td>100</td>
    22. <td><img src="imgs/del.jpg" class="delImg"/></td>
    23. </tr>
    24. <tr>
    25. <td>西瓜</td>
    26. <td>3</td>
    27. <td>20</td>
    28. <td>60</td>
    29. <td><img src="imgs/del.jpg" class="delImg"/></td>
    30. </tr>
    31. <tr>
    32. <td>菠萝</td>
    33. <td>4</td>
    34. <td>25</td>
    35. <td>100</td>
    36. <td><img src="imgs/del.jpg" class="delImg"/></td>
    37. </tr>
    38. <tr>
    39. <td>榴莲</td>
    40. <td>3</td>
    41. <td>30</td>
    42. <td>90</td>
    43. <td><img src="imgs/del.jpg" class="delImg"/></td>
    44. </tr>
    45. <tr>
    46. <td>总计</td>
    47. <td colspan="4">999</td>
    48. </tr>
    49. </table>
    50. </div>
    51. </div>
    52. </body>
    53. </html>
    54. *{
    55. color: threeddarkshadow;
    56. }
    57. body{
    58. margin:0;
    59. padding:0;
    60. background-color:#808080;
    61. }
    62. div{
    63. position:relative;
    64. float:left;
    65. }
    66. #div_container{
    67. width:80%;
    68. height:100%;
    69. border:0px solid blue;
    70. margin-left:10%;
    71. float:left;
    72. background-color: honeydew;
    73. border-radius:8px;
    74. }
    75. #div_fruit_list{
    76. width:100%;
    77. border:0px solid red;
    78. }
    79. #tbl_fruit{
    80. width:60%;
    81. line-height:28px;
    82. margin-top:120px;
    83. margin-left:20%;
    84. }
    85. #tbl_fruit , #tbl_fruit tr , #tbl_fruit th , #tbl_fruit td{
    86. border:1px solid gray;
    87. border-collapse:collapse;
    88. text-align:center;
    89. font-size:16px;
    90. font-family:"黑体";
    91. font-weight:lighter;
    92. }
    93. .w20{
    94. width:20%;
    95. }
    96. .delImg{
    97. width:24px;
    98. height:24px;
    99. }
    100. .btn{
    101. border:1px solid lightgray;
    102. width:80px;
    103. height:24px;
    104. }