Blogger Information
Blog 12
fans 0
comment 0
visits 7919
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CSS_(12.20)作业_全站首页导航与轮播图
ys899
Original
907 people have browsed it

第一种 float+position 布局

CSS样式表

  1. @import "static/css/reset.css";
  2. .index-header {
  3. width: 1200px;
  4. margin: 14px auto 0;
  5. position: relative;
  6. overflow: hidden;
  7. }
  8. .index-header > .content {
  9. width: 1200px;
  10. margin: auto;
  11. }
  12. .log-search{
  13. width: 1200px;
  14. height: 80px;
  15. /*两端对齐*/
  16. justify-content: space-between;
  17. text-align: center;
  18. overflow: auto;
  19. }
  20. .log-search .logo{
  21. float: left;
  22. #background-color:#000000;
  23. }
  24. .search{
  25. width: 450px;
  26. margin-left: 274px;
  27. float: left;
  28. #background-color:#55a555;
  29. position: relative;
  30. top:30px;
  31. }
  32. .search input{
  33. width: 333px;
  34. height: 36px;
  35. border: 1px solid #cccccc;
  36. border-radius: 10px;
  37. /*去掉轮廓线,获取焦点时不会出现蓝色边框*/
  38. outline: none;
  39. padding: 6px;
  40. /*垂直居中*/
  41. align-self: center;
  42. }
  43. .search > input:hover {
  44. box-shadow: 0 0 5px #888888;
  45. }
  46. .search label{
  47. font-size: 28px;
  48. position: relative;
  49. top: 2px;
  50. left: -38px;
  51. /*垂直居中*/
  52. align-self: center;
  53. }
  54. .quick-entry {
  55. width: 300px;
  56. float: left;
  57. #background-color: #0077aa;
  58. /*所有图标二端对齐*/
  59. justify-content: space-between;
  60. position: relative;
  61. top:30px;
  62. }
  63. .quick-entry a {
  64. font-size: 33px;
  65. /*图标垂直居中*/
  66. align-self: center;
  67. }
  68. /*用户鼠标划过字体图标时提供一个变色的效果反馈,提升体验*/
  69. .quick-entry a:hover {
  70. color: red;
  71. }
  72. .nav-detail{
  73. width:300px;
  74. float:left;
  75. margin: 20px auto;
  76. }
  77. .main-nav .nav-detail .pic{
  78. float: left;
  79. width: 80px;
  80. #overflow: auto;
  81. }
  82. .main-nav .nav-detail .pic > span{
  83. font-size: 40px;
  84. color: red;
  85. float:left;
  86. }
  87. .main-nav .nav-detail .pic > span > div{
  88. padding-left: 5px;
  89. /*设置表格单元之间的列间隙*/
  90. #grid-column-gap: 10px;
  91. float:right;
  92. }
  93. .main-nav .nav-detail .links{
  94. float: left;
  95. width: 120px;
  96. height: 40px;
  97. padding-left:5px;
  98. border-left: 1px solid #000000;
  99. }
  100. .main-nav .nav-detail .links > a{
  101. #padding-left: 50px;
  102. }
  103. /** 轮播图banner 开始 **/
  104. #banner {
  105. width: 1200px;
  106. margin: 15px auto 0;
  107. overflow: hidden;
  108. }
  109. #banner img:hover{
  110. box-shadow: 0px 0px 10px #666666;
  111. }
  112. /** 轮播图banner 结束 **/
  113. ##效果图
  114. ![](https://img.php.cn/upload/image/208/903/401/1577101530436311.png)
  115. ##第二种:Flex布局
  116. ###CSS样式表
  117. ```CSS reset.css
  118. * {
  119. padding: 0;
  120. margin: 0;
  121. /*outline: 1px dashed red;*/
  122. }
  123. body :not(header, footer){
  124. font-size: 13px;
  125. }
  126. a {
  127. color: black;
  128. text-decoration: none;
  129. font-size: 13px;
  130. }
  131. li {
  132. list-style: none;
  133. }
  134. ``` index_head.css
  135. @import "static/css/reset.css";
  136. /*首页导航+轮播图*/
  137. .index-header {
  138. background-color: #fff;
  139. padding: 30px 0 40px;
  140. display: flex;
  141. flex-direction: column;
  142. }
  143. .index-header > .content {
  144. width: 1200px;
  145. margin: auto;
  146. }
  147. /********** 1. 顶部logo,搜索框与快速入口 **********/
  148. .index-header > .content > .log-search {
  149. display: flex;
  150. /*两端对齐*/
  151. justify-content: space-between;
  152. }
  153. .index-header > .content > .log-search {
  154. display: flex;
  155. }
  156. /*头部搜索框样式*/
  157. .index-header > .content > .log-search > .search {
  158. width: 430px;
  159. /*转为flex,可以更精准的控制搜索框与放大镜图标的样式*/
  160. display: flex;
  161. /*居中对齐,实际上会看到并到对正,因为那个label相对定位走了*/
  162. justify-content: flex-end;
  163. /*可以看出,搜索框应该更靠右会更好看一些,使用相对定精确移动*/
  164. position: relative;
  165. left: 140px;
  166. }
  167. .index-header > .content > .log-search > .search > input {
  168. width: 333px;
  169. height: 36px;
  170. border: 1px solid #cccccc;
  171. border-radius: 10px;
  172. /*去掉轮廓线,获取焦点时不会出现蓝色边框*/
  173. outline: none;
  174. padding: 6px;
  175. /*垂直居中*/
  176. align-self: center;
  177. }
  178. .index-header > .content > .log-search > .search > input:hover {
  179. box-shadow: 0 0 5px #888888;
  180. }
  181. .index-header > .content > .log-search > .search > label {
  182. font-size: 28px;
  183. position: relative;
  184. top: 2px;
  185. left: -38px;
  186. /*垂直居中*/
  187. align-self: center;
  188. }
  189. /*快速入口*/
  190. .index-header > .content > .log-search > .quick-entry {
  191. /*必须设置宽度,否则无法产生剩余空间可供分配*/
  192. width: 300px;
  193. display: flex;
  194. /*所有图标二端对齐*/
  195. justify-content: space-between;
  196. }
  197. /*快速入口的图标设置*/
  198. .index-header > .content > .log-search > .quick-entry a {
  199. font-size: 33px;
  200. /*图标垂直居中*/
  201. align-self: center;
  202. }
  203. /*用户鼠标划过字体图标时提供一个变色的效果反馈,提升体验*/
  204. .index-header > .content > .log-search > .quick-entry a:hover {
  205. color: red;
  206. }
  207. /********** 2. 中部的主导航区 **********/
  208. .index-header > .content > .main-nav {
  209. margin: 20px auto;
  210. /*导航非常规范,网格更加快速*/
  211. display: grid;
  212. grid-template-columns: repeat(4, 300px);
  213. }
  214. /*每组导航区转为flex,水平排列*/
  215. .index-header > .content > .main-nav .nav-detail {
  216. display: flex;
  217. }
  218. /*最左边的图标与标签比较特殊*/
  219. .index-header > .content > .main-nav .nav-detail .pic {
  220. /*添加右边竖线*/
  221. padding-right: 10px;
  222. border-right: 1px solid #cccccc;
  223. /*转为flex*/
  224. display: flex;
  225. }
  226. /*设置图标样式,大小与前景色*/
  227. .index-header > .content > .main-nav .nav-detail .pic > span {
  228. font-size: 40px;
  229. color: red;
  230. }
  231. /*设置图标右边上下排列的描述文本样式*/
  232. .index-header > .content > .main-nav .nav-detail .pic > div {
  233. padding-left: 5px;
  234. /*转为flex,且为垂直排列*/
  235. display: flex;
  236. flex-direction: column;
  237. /*分散对齐*/
  238. justify-content: space-around;
  239. }
  240. /*设置主导航的链接样式*/
  241. .index-header > .content > .main-nav .nav-detail .links {
  242. padding-left: 10px;
  243. /*链接非常规范,且默认为二行显示,非常适合网格快速实现*/
  244. display: grid;
  245. /*minmax(最小值,最大值)*/
  246. grid-template-columns: repeat(4, minmax(30px, auto));
  247. /*设置表格单元之间的列间隙*/
  248. grid-column-gap: 10px;
  249. }
  250. /********** 3. 轮播图 **********/
  251. .index-header > .content > .slider {
  252. /*用网格布局快速实现*/
  253. display: grid;
  254. grid-template-columns: 900px 295px;
  255. /*列间距*/
  256. grid-column-gap: 5px;
  257. }
  258. .index-header > .content > .slider img:last-of-type:hover {
  259. box-shadow: 0 0 8px #888888;
  260. }

```HTML5 首页内容
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="static/font/iconfont.css">
<link rel="stylesheet" href="index_header.css">
<title>全站首页导航与轮播图</title>
</head>

<body>

<div class="index-header">
<div class="content">
<!--logo与搜索框,快速入口-->
<div class="log-search">
<a href="" class="logo"><img src="static/images/logo.png" alt=""></a>
<div class="search">
<input type="search" name="search" id="search">
<label for="search" class="iconfont icon-jinduchaxun"></label>
</div>
<div class="quick-entry">
<a href="" class="iconfont icon-huiyuan1"></a>
<a href="" class="iconfont icon-danmu1"></a>
<a href="" class="iconfont icon-fabu"></a>
<a href="" class="iconfont icon-fangda"></a>
<a href="" class="iconfont icon-huiyuan2"></a>
<a href="" class="iconfont icon-dianzan"></a>
</div>
</div>

  1. <!--主导航-->
  2. <div class="main-nav">
  3. <!--导航详情1-->
  4. <div class="nav-detail">
  5. <!--左侧图标与描述-->
  6. <div class="pic">
  7. <span class="iconfont icon-gongdan"></span>
  8. <div>
  9. <span>资讯</span>
  10. <span>学习</span>
  11. </div>
  12. </div>
  13. <!--右侧导航链接-->
  14. <div class="links">
  15. <a href="">器材</a>
  16. <a href="">大师</a>
  17. <a href="">学院</a>
  18. <a href="">实战</a>
  19. <a href="">大赛</a>
  20. <a href="">裤子</a>
  21. <a href="">影视</a>
  22. <a href="">其它</a>
  23. </div>
  24. </div>
  25. <!--导航详情2-->
  26. <div class="nav-detail">
  27. <!--左侧图标与描述-->
  28. <div class="pic">
  29. <span class="iconfont icon-renwujincheng"></span>
  30. <div>
  31. <span>爱好</span>
  32. <span>姐妹</span>
  33. </div>
  34. </div>
  35. <!--右侧导航链接-->
  36. <div class="links">
  37. <a href="">有品</a>
  38. <a href="">图片</a>
  39. <a href="">喝水</a>
  40. <a href="">飞机</a>
  41. <a href="">坦克</a>
  42. <a href="">气球</a>
  43. <a href="">毛线</a>
  44. <a href="">其它</a>
  45. </div>
  46. </div>
  47. <!--导航详情3-->
  48. <div class="nav-detail">
  49. <!--左侧图标与描述-->
  50. <div class="pic">
  51. <span class="iconfont icon-gongdan"></span>
  52. <div>
  53. <span>软件</span>
  54. <span>技能</span>
  55. </div>
  56. </div>
  57. <!--右侧导航链接-->
  58. <div class="links">
  59. <a href="">学习</a>
  60. <a href="">爱国</a>
  61. <a href="">敬业</a>
  62. <a href="">友善</a>
  63. <a href="">富强</a>
  64. <a href="">互助</a>
  65. <a href="">仁义</a>
  66. <a href="">其它</a>
  67. </div>
  68. </div>
  69. <!--导航详情4-->
  70. <div class="nav-detail">
  71. <!--左侧图标与描述-->
  72. <div class="pic">
  73. <span class="iconfont icon-DOC"></span>
  74. <div>
  75. <span>编程</span>
  76. <span>美女</span>
  77. </div>
  78. </div>
  79. <!--右侧导航链接-->
  80. <div class="links">
  81. <a href="">吃饭</a>
  82. <a href="">周易</a>
  83. <a href="">黄山</a>
  84. <a href="">合肥</a>
  85. <a href="">上海</a>
  86. <a href="">杭州</a>
  87. <a href="">北京</a>
  88. <a href="">其它</a>
  89. </div>
  90. </div>
  91. </div>
  92. <!--轮播图-->
  93. <div class="slider">
  94. <a href=""><img src="static/images/2.jpg" alt=""></a>
  95. <a href=""><img src="static/images/banner-right.jpg" alt=""></a>
  96. </div>
  97. </div>

</div>
</body>
</html>
```

效果图

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:这个页面基本并不好写的, 即使一个老前端, 拿到这个案例, 也要好好琢磨一会的, 恭喜你,不错
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post