九宫格

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <link rel="stylesheet" href="./css/font-awesome.min.css">
  7. <link rel="stylesheet" href="./css/icon.css">
  8. </head>
  9. <body>
  10. <style>
  11. body{
  12. background-color: #f4f4f4;
  13. }
  14. ul{
  15. padding: 0;
  16. margin: 0;
  17. list-style: none;
  18. /*box-sizing: border-box;*/
  19. }
  20. ul,li{
  21. box-sizing: border-box;
  22. }
  23. .clearfix::after{
  24. content: "";
  25. display: table;
  26. clear: both;
  27. }
  28. .funcs-container{
  29. width: 290px;
  30. height: 232px;
  31. margin: 100px auto;
  32. /*border: 1px solid red;*/
  33. background-color:#fff;
  34. overflow: hidden;
  35. }
  36. .funcs-container .funcs-list{
  37. width: 294px;
  38. height: 232px;
  39. /*border: 1px solid #000000;*/
  40. margin-left: -2px ;
  41. border-bottom: 1px solid #ddd;
  42. }
  43. .funcs-container .funcs-list .funcs-item{
  44. float: left;
  45. width: 25%;
  46. height: 77px;
  47. border-top: 1px solid #dddddd;
  48. border-left:1px solid #dddddd;
  49. /*border-right: 1px solid #000000;*/
  50. }
  51. .funcs-container .funcs-list .funcs-item .funcs-link{
  52. display: block;
  53. width: 100%;
  54. height: 100%;
  55. }
  56. a{
  57. text-decoration: none;
  58. }
  59. p{
  60. matgin:0;
  61. }
  62. .funcs-container .funcs-list .funcs-item .funcs-link{
  63. font-size: 12px;
  64. color: #333;
  65. text-align: center;
  66. }
  67. </style>
  68. <div class="funcs-container">
  69. <ul class="funcs-list ">
  70. <li class="funcs-item">
  71. <a href="" class="funcs-link">
  72. <i class="icon icon-calendar"></i>
  73. <p>日历</p>
  74. </a>
  75. </li>
  76. <li class="funcs-item">
  77. <a href="" class="funcs-link">
  78. <i class="icon icon-calendar"></i>
  79. <p>日历</p>
  80. </a>
  81. </li>
  82. <li class="funcs-item">
  83. <a href="" class="funcs-link">
  84. <i class="icon icon-calendar"></i>
  85. <p>日历</p>
  86. </a>
  87. </li>
  88. <li class="funcs-item">
  89. <a href="" class="funcs-link">
  90. <i class="icon icon-calendar"></i>
  91. <p>日历</p>
  92. </a>
  93. </li>
  94. <li class="funcs-item">
  95. <a href="" class="funcs-link">
  96. <i class="icon icon-calendar"></i>
  97. <p>日历</p>
  98. </a>
  99. </li>
  100. <li class="funcs-item">
  101. <a href="" class="funcs-link">
  102. <i class="icon icon-calendar"></i>
  103. <p>日历</p>
  104. </a>
  105. </li>
  106. <li class="funcs-item">
  107. <a href="" class="funcs-link">
  108. <i class="icon icon-calendar"></i>
  109. <p>日历</p>
  110. </a>
  111. </li>
  112. <li class="funcs-item">
  113. <a href="" class="funcs-link">
  114. <i class="icon icon-calendar"></i>
  115. <p>日历</p>
  116. </a>
  117. </li>
  118. <li class="funcs-item">
  119. <a href="" class="funcs-link">
  120. <i class="icon icon-calendar"></i>
  121. <p>日历</p>
  122. </a>
  123. </li>
  124. <li class="funcs-item">
  125. <a href="" class="funcs-link">
  126. <i class="icon icon-calendar"></i>
  127. <p>日历</p>
  128. </a>
  129. </li>
  130. <li class="funcs-item">
  131. <a href="" class="funcs-link">
  132. <i class="icon icon-calendar"></i>
  133. <p>日历</p>
  134. </a>
  135. </li>
  136. <li class="funcs-item">
  137. <a href="" class="funcs-link">
  138. <i class="icon icon-calendar"></i>
  139. <p>日历</p>
  140. </a>
  141. </li>
  142. </ul>
  143. </div>
  144. </body>
  145. </html>
  1. /*.icon {*/
  2. /* display: block;*/
  3. /* width: 32px;*/
  4. /* height: 32px;*/
  5. /* background-repeat: no-repeat;*/
  6. /* background-size: 100% 100%;*/
  7. /* margin:10px auto 0;*/
  8. /*}*/
  9. .icon {
  10. display: block;
  11. width: 24px;
  12. height: 24px;
  13. margin: 11px auto 0;
  14. background-repeat: no-repeat;
  15. background-size: 100% 100%;
  16. vertical-align: middle;
  17. /*margin:10px auto 0;*/
  18. }
  19. .icon-calendar {
  20. background-image: url("../icons/calendar.png");
  21. }
  22. /*.icon-goods {*/
  23. /* background-image: url("../icons/goods.png");*/
  24. /*}*/
  25. /*.icon-files {*/
  26. /* background-image: url("../icons/files.png");*/
  27. /*}*/
  28. /*.icon-identity {*/
  29. /* background-image: url("../icons/identity.png");*/
  30. /*}*/
  31. /*.icon-income {*/
  32. /* background-image: url("../icons/income.png");*/
  33. /*}*/
  34. /*.icon-job {*/
  35. /* background-image: url("../icons/job.png");*/
  36. /*}*/

li中因为可以点击跳转所以用a,包裹图标与文字
image.png

课程列表

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>腾讯课堂课程列表</title>
  6. <link rel="stylesheet" href="./css/font-awesome.min.css">
  7. <link rel="stylesheet" href="./css/icon.css">
  8. </head>
  9. <body>
  10. <style>
  11. ul{
  12. padding: 0;
  13. margin: 0;
  14. list-style: none;
  15. }
  16. ul,li,div{
  17. box-sizing: border-box;
  18. }
  19. .clearfix::after{
  20. content: '';
  21. display: table;
  22. clear: both;
  23. }
  24. .courses-container{
  25. width: 1230px;
  26. margin: 100px auto;
  27. border: 1px solid red;
  28. }
  29. .courses-container .courses-list{
  30. width: 1500px;
  31. margin-left:-18px ;
  32. /*border: 1px solid orange;*/
  33. }
  34. .courses-container .courses-list .course-item{
  35. float: left;
  36. width: 236px;
  37. height: 221px;
  38. margin-left: 9px;
  39. border: 1px solid #000000;
  40. }
  41. </style>
  42. <div class="courses-container">
  43. <ul class="courses-list clearfix">
  44. <li class="course-item">
  45. </li>
  46. <li class="course-item">
  47. </li>
  48. <li class="course-item">
  49. </li>
  50. <li class="course-item">
  51. </li>
  52. <li class="course-item">
  53. </li>
  54. </ul>
  55. </div>
  56. </body>
  57. </html>

image.png

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>腾讯课堂课程列表</title>
  6. <link rel="stylesheet" href="./css/font-awesome.min.css">
  7. <link rel="stylesheet" href="./css/icon.css">
  8. </head>
  9. <body>
  10. <style>
  11. ul{
  12. padding: 0;
  13. margin: 0;
  14. list-style: none;
  15. }
  16. ul,li,div{
  17. box-sizing: border-box;
  18. }
  19. i{
  20. font-style: normal;
  21. }
  22. .clearfix::after{
  23. content: '';
  24. display: table;
  25. clear: both;
  26. }
  27. .courses-container{
  28. width: 1230px;
  29. margin: 100px auto;
  30. /*border: 1px solid red;*/
  31. }
  32. .courses-container .courses-list{
  33. width: 1500px;
  34. margin-left:-18px ;
  35. /*border: 1px solid orange;*/
  36. }
  37. .courses-container .courses-list .course-item{
  38. float: left;
  39. position: relative;
  40. width: 236px;
  41. height: 221px;
  42. margin-left: 9px;
  43. /*border: 1px solid #000000;*/
  44. padding: 7px 7px 10px;
  45. /*padding: 7px 20px 10px;*/
  46. border: 1px solid transparent;
  47. }
  48. .courses-container .courses-list .course-item .course-tip{
  49. position: absolute;
  50. left: 7px;
  51. width: 220px;
  52. /*top: 131px;*/
  53. /*top: 100px;*/
  54. /*top: 80px;*/
  55. /*top: 85px;*/
  56. top: 105px;
  57. height: 24px;
  58. }
  59. .courses-container .courses-list .course-item .course-tip2{
  60. position: absolute;
  61. left: 7px;
  62. width: 220px;
  63. /*top: 131px;*/
  64. /*top: 100px;*/
  65. /*top: 80px;*/
  66. /*top: 85px;*/
  67. top: 105px;
  68. height: 24px;
  69. line-height: 24px;
  70. background-color: rgba(0,0,0,.6);
  71. color: #ffffff;
  72. font-size: 12px;
  73. padding: 0 2px;
  74. }
  75. .courses-container .courses-list .course-item .opacity-block{
  76. height: 100%;
  77. background-color: #000000;
  78. opacity: .6;
  79. filter: alpha(opacity=60);
  80. }
  81. .courses-container .courses-list .course-item .course-tip .content-block {
  82. position: absolute;
  83. top: 0;
  84. left: 0;
  85. z-index: 1;
  86. color: #ffffff;
  87. width: 100%;
  88. height: 100%;
  89. line-height: 24px;
  90. font-size: 12px;
  91. padding:0 2px;
  92. }
  93. .courses-container .courses-list .course-item:hover{
  94. /*border: 1px solid #dddddd;*/
  95. border-color: #dddddd;
  96. box-shadow: 0 0 5px #dddddd;
  97. }
  98. .courses-container .courses-list .course-item .course-link{
  99. display: block;
  100. width: 220px;
  101. height: 124px;
  102. margin-bottom: 5px;
  103. /*margin: 0 auto;*/
  104. }
  105. .courses-container .courses-list .course-item .course-link img{
  106. width: 100%;
  107. }
  108. h4{
  109. margin: 0;
  110. font-weight: normal;
  111. }
  112. .courses-container .courses-list .course-item .course-title{
  113. height: 40px;
  114. margin-bottom: 8px;
  115. /*line-height: 40px;*/
  116. font-size: 14px;
  117. color: #333;
  118. }
  119. .courses-container .courses-list .course-item .course-title a{
  120. color: #333;
  121. }
  122. .courses-container .courses-list .course-item .course-title a:hover{
  123. color: #13d0a1;
  124. }
  125. a{
  126. text-decoration: none;
  127. }
  128. .courses-container .courses-list .course-item .course-info{
  129. height: 24px;
  130. line-height: 24px;
  131. }
  132. .courses-container .courses-list .course-item .course-info .info-free{
  133. font-size: 14px;
  134. color: #5fb41b;
  135. }
  136. .courses-container .courses-list .course-item .course-info .info-users{
  137. float: right;
  138. color: #999999;
  139. font-size: 12px;
  140. }
  141. .courses-container .courses-list .course-item .course-info .info-price {
  142. /*font-size: 14px;*/
  143. color: #e85308;
  144. }
  145. .courses-container .courses-list .course-item .course-info .tip-badge{
  146. display: inline-block;
  147. height: 16px;
  148. line-height: 16px;
  149. padding: 0 2px;
  150. border: 1px solid #e85308;
  151. font-size: 12px;
  152. color:#e85308 ;
  153. /*vertical-align: middle;*/
  154. vertical-align: -3px;
  155. vertical-align: 5px;
  156. vertical-align: 2px;
  157. }
  158. </style>
  159. <div class="courses-container">
  160. <ul class="courses-list clearfix">
  161. <li class="course-item">
  162. <div class="course-tip">
  163. <div class="content-block">随到随学(共7节)</div>
  164. <div class="opacity-block"></div>
  165. </div>
  166. <a href="" class="course-link">
  167. <img src="./img/1.png" alt="">
  168. </a>
  169. <h4 class="course-title">
  170. <a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
  171. </h4>
  172. <div class="course-info">
  173. <span class="info-free">免费</span>
  174. <span class="info-users">2750人 最近报名</span>
  175. </div>
  176. </li>
  177. <li class="course-item">
  178. <div class="course-tip2">
  179. <!-- <div class="content-block">随到随学(共7节)</div>-->
  180. <span class="tip-text">随到随学(共7节)</span>
  181. <!-- <div class="opacity-block"></div>-->
  182. </div>
  183. <a href="" class="course-link">
  184. <img src="./img/1.png" alt="">
  185. </a>
  186. <h4 class="course-title">
  187. <a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
  188. </h4>
  189. <div class="course-info">
  190. <span class="info-free">免费</span>
  191. <span class="info-users">2750人 最近报名</span>
  192. </div>
  193. </li>
  194. <li class="course-item">
  195. <a href="" class="course-link">
  196. <img src="./img/1.png" alt="">
  197. </a>
  198. <h4 class="course-title">
  199. <a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
  200. </h4>
  201. <div class="course-info">
  202. <span class="info-free">免费</span>
  203. <span class="info-users">2750人 最近报名</span>
  204. </div>
  205. </li>
  206. <li class="course-item">
  207. <a href="" class="course-link">
  208. <img src="./img/1.png" alt="">
  209. </a>
  210. <h4 class="course-title">
  211. <a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
  212. </h4>
  213. <div class="course-info">
  214. <span class="info-price">¥999.00</span>
  215. <i class="tip-badge">可试学</i>
  216. <span class="info-users">2750人 最近报名</span>
  217. </div>
  218. </li>
  219. <li class="course-item">
  220. <a href="" class="course-link">
  221. <img src="./img/1.png" alt="">
  222. </a>
  223. <h4 class="course-title">
  224. <a href="">【罗翔】4500买的吊坠价值20万?张女士赚了个10年有期徒刑?</a>
  225. </h4>
  226. <div class="course-info">
  227. <span class="info-free">免费</span>
  228. <span class="info-users">2750人 最近报名</span>
  229. </div>
  230. </li>
  231. <!-- <li class="course-item">-->
  232. <!-- <a href="" class="course-link">-->
  233. <!-- <img src="./img/1.png" alt="">-->
  234. <!-- </a>-->
  235. <!-- <h4>111111</h4>-->
  236. <!-- </li>-->
  237. <!-- <li class="course-item">-->
  238. <!-- </li>-->
  239. <!-- <li class="course-item">-->
  240. <!-- </li>-->
  241. <!-- <li class="course-item">-->
  242. <!-- </li>-->
  243. </ul>
  244. </div>
  245. </body>
  246. </html>

image.png

总结

image.png
当多个元素在内部,左对齐,左边有边距时可以用padding
其实也可以,再套用一个div,div>div,再拿子div放这些元素,设置padding相当于在div中加了个盒子div,相当于套了个盒子

image.png
与文档流不一致时,多用float,因为可以自动排列,按照一定顺序,从左到右,从上到下。从左到右也遵循着流。
决定定位也可以脱离文档流,需要在父级元素精确定位时用