前情回顾

1、前期准备

2、html基础

3、css基本选择器

/css样式语法/
选择器{
css样式名称:值;
}

今日内容

1、css常用属性

  1. 文本
  2. 字体
  3. 颜色
  4. 背景

    1. <div id="box">
    2. css常用属性
    3. </div>
    1. #box{
    2. /*a 文本*/
    3. /*text-align: center;*/
    4. text-indent: 2em;
    5. /*text-decoration: underline;*/
    6. text-decoration: line-through;
    7. /*b 字体*/
    8. font-size: 50px;
    9. font-family: "楷体";
    10. font-weight: bold;
    11. font-style:italic;
    12. /*c 颜色*/
    13. /*color: #008000;*/
    14. color: rgb(255,0,0);
    15. /*css属性来自 设计稿*/
    16. /*d 背景*/
    17. /*background: orange url("img/taohua2.jpg");*/
    18. /*background: orange url("img/taohua2.jpg") repeat-x;*/
    19. /*background: orange url("img/taohua2.jpg") repeat-y;*/
    20. background: orange url("img/taohua2.jpg") no-repeat;
    21. /*background-size: 100%,100%;*/
    22. background-size: 10%,10%;
    23. /*盒子模型*/
    24. width:300px;
    25. height: 400px;
    26. }

    2、盒子模型

    盒子模型.png
    每个标签看成一个盒子都有下面5个属性网页的布局,排版就是由一个个标签组成的,也就是一个个盒子组成。通过下面5个属性,就可以设置每个盒子(标签)的 宽,高,内边距,外边距,边框

  5. 内边距:内容与边框的距离
  6. 外边距:盒子之间的距离
  7. 边框

    1. #box {
    2. width: 70px;
    3. margin: 10px;
    4. padding: 5px;
    5. }

    image.png

    3、布局-浮动

    改变元素布局的一种方式,默认块级元素独占一行(不会换行),要让块级元素水平排列,可以使用浮动,同时会脱离文档流,不占文档位置(会飘起来)。
    常见块元素:div,p,h1-h6,ul li,ol li,dl dt dd,table,form
    布局11.jpg ```html

  1. <a name="b4WcJ"></a>
  2. ### 4、布局-定位
  3. 改变元素位置,布局的一种方案,适合复杂布局,让一个元素在另一个元素上,不占文档位置。<br />![布局13.png](https://cdn.nlark.com/yuque/0/2022/png/575742/1646381515356-cdff5901-2eb4-43e8-a956-1e9050941c9e.png#clientId=u1319279e-05e5-4&crop=0&crop=0&crop=1&crop=1&from=ui&id=uafd2c54a&margin=%5Bobject%20Object%5D&name=%E5%B8%83%E5%B1%8013.png&originHeight=768&originWidth=1024&originalType=binary&ratio=1&rotation=0&showTitle=false&size=6307&status=done&style=none&taskId=u77c72235-68c6-4740-891d-56a7e39b5d4&title=)
  4. ```html
  5. <style type="text/css">
  6. *{padding:0;margin: 0;}
  7. body{
  8. /*整个给背景*/
  9. background:#FEBE4F;
  10. }
  11. #nav{
  12. height: 50px;
  13. background-color: #C79DFF;
  14. width: 100%;
  15. margin:50px 0;
  16. /*给一个定位属性,作为里面被包含的元素 定位的 参考点*/
  17. position: relative;
  18. }
  19. #nav div{
  20. width: 200px;
  21. height: 80px;
  22. background: #82FF26;
  23. /*参考最近的父元素(标签) 进行绝对定位*/
  24. position: absolute;
  25. /*父元素是50,当前元素是80,往上走-15相信刚好垂直居中*/
  26. top:-15px;
  27. left: 30px;
  28. }
  29. .wrap{
  30. height: 480px;
  31. width: 1200px;
  32. /*background: darkorange;*/
  33. margin:0 auto;
  34. }
  35. /*left,right 是div标签,是块元素,默认会垂直排列,所以要使用浮动让水平排列*/
  36. .wrap .left{
  37. width: 590px;
  38. /*里面 3个 item 每个height:150px,在加上 前2个item 又
  39. 下边距12px*/
  40. /*150*3 + 2*15 = 480*/
  41. height: 480px;
  42. float:left;
  43. /*background-color: #FF005A;*/
  44. /*background-color: green;*/
  45. }
  46. .wrap .left .item{
  47. width: 100%;
  48. height: 150px;
  49. background: #FF005A;
  50. margin-bottom: 15px;
  51. }
  52. /*去掉最后一个的 下边距*/
  53. .wrap .left .item:last-child{
  54. margin-bottom: 0;
  55. }
  56. .wrap .right{
  57. width: 590px;
  58. height: 480px;
  59. float:right;
  60. background-color: #3494FF;
  61. }
  62. #footer{
  63. /*满屏:宽度为100%*/
  64. width: 100%;
  65. height: 80px;
  66. background:#E60BFF;
  67. margin-top: 30px;
  68. }
  69. </style>
  70. <div id="nav">
  71. <div></div>
  72. </div>
  73. <div class="wrap">
  74. <div class="left">
  75. <div class="item"></div>
  76. <div class="item"></div>
  77. <div class="item"></div>
  78. </div>
  79. <div class="right"></div>
  80. </div>
  81. <div id="footer"></div>

5、练习

1、演示代码

  • day02 中演示代码
  • 下图效果图实现

image.png
素材:
arrow_rb.jpg
p3.pngp1.pngp2.png

2、博雅互动布局实现(选做)

博雅.png