博客列表 >2019-12-27 m.php.cn网站的首页布局(Flex实现)-PHP培训十期

2019-12-27 m.php.cn网站的首页布局(Flex实现)-PHP培训十期

ys899
ys899原创
2019年12月29日 16:38:32742浏览

```HTML Code DOM结构 素材库已备齐
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<title>php中文网移动端首页</title>
<link rel="stylesheet" href="static/css/style.css">
</head>

<body>

<!--顶部固定定位-->

<header>
<img src="static/images/user-pic.jpeg" alt="">
<img src="static/images/logo.png" alt="">
<img src="static/images/user-nav.jpg" alt="">
</header>

<!--banner轮播图, 这里用图片代替-->

<div class="banner">
<img src="static/images/banner.jpg" alt="">
</div>

<!--导航区-->

<nav>
<ul>
<li>
<a href="">
<img src="static/images/html.png" alt="">
<span>HTML/CSS</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/JavaScript.png" alt="">
<span>JavaScipt</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/code.png" alt="">
<span>服务器端</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/sql.png" alt="">
<span>数据库</span>
</a>
</li>
</ul>
<ul>
<li>
<a href="">
<img src="static/images/app.png" alt="">
<span>移动端</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/manual.png" alt="">
<span>手册</span>
</a>
</li>
<li>
<a href=""><img src="static/images/tool2.png" alt="">
<span>工具</span>
</a>
</li>
<li>
<a href="">
<img src="static/images/live.png" alt="">
<span>直播</span>
</a>
</li>
</ul>
</nav>

<!--课程区-->

<main>
<!--推荐课程-->
<article class="recommend">
<h3>推荐课程</h3>
<section>
<a href=""><img src="static/images/tjkc1.jpg" alt=""></a>
<a href=""><img src="static/images/tjkc2.jpg" alt=""></a>
</section>

<section>
<div>
<a href=""><img src="static/images/tjkc3.jpg" alt=""></a>
<span>
<a href="">CI框架30分钟极速入门</a>
<span><i>中级</i>55674</span>
</span>
</div>
<div>
<a href=""><img src="static/images/tjkc4.jpg" alt=""></a>
<span>
<a href="">2019前端入门_HTML5</a>
<span><i>初级</i>257292</span>
</span>
</div>
</section>
</article>
</main>

</body>
</html>

  1. ```CSS Code Flex布局
  2. @import "reset.css";
  3. /*头部样式*/
  4. header {
  5. /*固定定位*/
  6. position: fixed;
  7. top:0;
  8. width: 100%;
  9. height: 42px;
  10. background-color: #555;
  11. color: #ffffff;
  12. /*转为Flex*/
  13. display: flex;
  14. flex-direction: row;
  15. justify-content: space-between;
  16. align-items: center;
  17. }
  18. header > img:first-of-type,
  19. header > img:last-of-type {
  20. width: 26px;
  21. height: 26px;
  22. margin: 5px;
  23. }
  24. header > img:first-of-type {
  25. border-radius: 50%;
  26. }
  27. header > img {
  28. width: 94px;
  29. }
  30. /*轮播图*/
  31. .banner {
  32. display: flex;
  33. height: 200px;
  34. }
  35. /*导航区*/
  36. nav {
  37. background-color: #fff;
  38. display: flex;
  39. /*主轴为垂直方向, 禁止换行*/
  40. flex-flow: column nowrap;
  41. }
  42. nav img {
  43. width: 45px;
  44. height: 49px;
  45. }
  46. nav > ul {
  47. display: flex;
  48. }
  49. nav ul li {
  50. flex: 1;
  51. }
  52. /*图片与文本做为一个整体/组件, 统一设置*/
  53. nav ul li a {
  54. display: flex;
  55. flex-flow: column wrap;
  56. align-items: center;
  57. margin: 10px;
  58. }
  59. nav ul li a span {
  60. margin-top: 5px;
  61. }
  62. /*主体内容区*/
  63. main {
  64. display: flex;
  65. flex-direction: column;
  66. }
  67. main > .recommend > section:first-of-type {
  68. display: flex;
  69. }
  70. main > .recommend > section:first-of-type > a {
  71. margin: 5px;
  72. flex: 1;
  73. }
  74. main > .recommend > section:first-of-type > a > img {
  75. height: 90px;
  76. }
  77. /*设置垂直排列的推荐课程*/
  78. main > .recommend > section:last-of-type {
  79. display: flex;
  80. flex-direction: column;
  81. }
  82. main > .recommend > section:last-of-type > div {
  83. background-color: #fff;
  84. margin: 5px;
  85. display: flex;
  86. }
  87. main > .recommend > section:last-of-type > div img {
  88. width: 350px;
  89. height: 90px;
  90. }
  91. main > .recommend > section:last-of-type > div > span {
  92. flex: 1;
  93. display: flex;
  94. flex-direction: column;
  95. margin-top: 5px;
  96. padding-left: 10px;
  97. }
  98. main > .recommend > section:last-of-type > div > span i {
  99. font-style: normal;
  100. background-color: #333333;
  101. color: white;
  102. border-radius: 3px;
  103. padding: 0 5px;
  104. font-size: smaller;
  105. }
  106. main > .recommend > section:last-of-type > div > span > span {
  107. margin-top: 40px;
  108. display: flex;
  109. justify-content: space-between;
  110. }
  111. body {
  112. height: 1000px;
  113. }

效果图

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议