Blogger Information
Blog 5
fans 0
comment 0
visits 2753
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1月10-12日作业写了一个汽车宣传站的移动端并进行了PHP站点模块化
阿喜
Original
588 people have browsed it

1月10-12日作业写个汽车产品移动端站并进行了PHP站点模块化

写了这一个移动端有很多坑,有一些解决了,有一些还没有解决。
如:vh这个单位在不同的浏览器上面就会出错。后面又换成了PX单位。
站点分上中下三部分:header ,main, footer三部分。如将中间main自动flex为1可上下不固定。期待老师解决。还有字体在电脑端还行,在移动端看是没有办法看。
先上一下布局的效果图:

上一下首页index.html部分的布局代码。列表页与首页一样,产品详情页我就偷了一个懒。就是将首页的CSS代码部分,div标签将:“images-goods” 改为“images-details” ,然后增加一个images-details的样式。觉得用flex布局太方便了。几行代码就出来了一个产品详情页。

首页布局index.html代码如下:

  1. <!--主体-->
  2. <main>
  3. <div class="main-part">
  4. <section>
  5. <h3><span>促销区</span></h3>
  6. <article>
  7. <div class="images-goods">
  8. <div>
  9. <a href=""><img height="120" src="images/SUV/01.jpg"></a>
  10. <span><i>¥:</i><i>210000.00元</i></span>
  11. <span><i>型号:</i><i>7300LI</i></span>
  12. <span>女图片介绍一下美女美绍</span>
  13. </div>
  14. </div>
  15. <div class="images-goods">
  16. <div>
  17. <a href=""><img height="120" src="images/SUV/02.jpg" ></a>
  18. <span><i>¥:</i><i>210000.00元</i></span>
  19. <span><i>型号:</i><i>7300LI</i></span>
  20. <span>女图片介绍一下美女美绍</span>
  21. </div>
  22. </div>
  23. <div class="images-goods">
  24. <div>
  25. <a href=""><img height="120" src="images/SUV/04.jpg"></a>
  26. <span><i>¥:</i><i>210000.00元</i></span>
  27. <span><i>型号:</i><i>7300LI</i></span>
  28. <span>女图片介绍一下美女美绍</span>
  29. </div>
  30. </div>
  31. <div class="images-goods">
  32. <div>
  33. <a href=""><img height="120" src="images/SUV/05.jpg" ></a>
  34. <span><i>¥:</i><i>210000.00元</i></span>
  35. <span><i>型号:</i><i>7300LI</i></span>
  36. <span>女图片介绍一下美女美绍</span>
  37. </div>
  38. </div>
  39. <div class="images-goods">
  40. <div>
  41. <a href=""><img height="120" src="images/SUV/06.jpg" ></a>
  42. <span><i>¥:</i><i>210000.00元</i></span>
  43. <span><i>型号:</i><i>7300LI</i></span>
  44. <span>女图片介绍一下美女美绍</span>
  45. </div>
  46. </div>
  47. <div class="images-goods">
  48. <div>
  49. <a href=""><img height="120" src="images/SUV/01.jpg" ></a>
  50. <span><i>¥:</i><i>210000.00元</i></span>
  51. <span><i>型号:</i><i>7300LI</i></span>
  52. <span>女图片介绍一下美女美绍</span>
  53. </div>
  54. </div>
  55. </article>
  56. </section>
  57. <section>
  58. <h3><span>SUV专区</span></h3>
  59. <article>
  60. <div class="images-goods">
  61. <div>
  62. <a href=""><img height="120" src="images/SUV/01.jpg"></a>
  63. <span><i>¥:</i><i>210000.00元</i></span>
  64. <span><i>型号:</i><i>7300LI</i></span>
  65. <span>女图片介绍一下美女美绍</span>
  66. </div>
  67. </div>
  68. <div class="images-goods">
  69. <div>
  70. <a href=""><img height="120" src="images/SUV/02.jpg" ></a>
  71. <span><i>¥:</i><i>210000.00元</i></span>
  72. <span><i>型号:</i><i>7300LI</i></span>
  73. <span>女图片介绍一下美女美绍</span>
  74. </div>
  75. </div>
  76. <div class="images-goods">
  77. <div>
  78. <a href=""><img height="120" src="images/SUV/04.jpg"></a>
  79. <span><i>¥:</i><i>210000.00元</i></span>
  80. <span><i>型号:</i><i>7300LI</i></span>
  81. <span>女图片介绍一下美女美绍</span>
  82. </div>
  83. </div>
  84. <div class="images-goods">
  85. <div>
  86. <a href=""><img height="120" src="images/SUV/05.jpg" ></a>
  87. <span><i>¥:</i><i>210000.00元</i></span>
  88. <span><i>型号:</i><i>7300LI</i></span>
  89. <span>女图片介绍一下美女美绍</span>
  90. </div>
  91. </div>
  92. <div class="images-goods">
  93. <div>
  94. <a href=""><img height="120" src="images/SUV/06.jpg" ></a>
  95. <span><i>¥:</i><i>210000.00元</i></span>
  96. <span><i>型号:</i><i>7300LI</i></span>
  97. <span>女图片介绍一下美女美绍</span>
  98. </div>
  99. </div>
  100. <div class="images-goods">
  101. <div>
  102. <a href=""><img height="120" src="images/SUV/01.jpg" ></a>
  103. <span><i>¥:</i><i>210000.00元</i></span>
  104. <span><i>型号:</i><i>7300LI</i></span>
  105. <span>女图片介绍一下美女美绍</span>
  106. </div>
  107. </div>
  108. </article>
  109. </section>
  110. <section>
  111. <h3><span>轿车专区</span></h3>
  112. <article>
  113. <div class="images-goods">
  114. <div>
  115. <a href=""><img height="120" src="images/car/01.jpg" ></a>
  116. <span><i>¥:</i><i>210000.00元</i></span>
  117. <span><i>型号:</i><i>7300LI</i></span>
  118. <span>女图片介绍一下美女美绍</span>
  119. </div>
  120. </div>
  121. <div class="images-goods">
  122. <div>
  123. <a href=""><img height="120" src="images/car/02.jpg"></a>
  124. <span><i>¥:</i><i>210000.00元</i></span>
  125. <span><i>型号:</i><i>7300LI</i></span>
  126. <span>女图片介绍一下美女美绍</span>
  127. </div>
  128. </div>
  129. <div class="images-goods">
  130. <div>
  131. <a href=""><img height="120" src="images/car/03.jpg" ></a>
  132. <span><i>¥:</i><i>210000.00元</i></span>
  133. <span><i>型号:</i><i>7300LI</i></span>
  134. <span>女图片介绍一下美女美绍</span>
  135. </div>
  136. </div>
  137. <div class="images-goods">
  138. <div>
  139. <a href=""><img height="120" src="images/car/04.jpg" ></a>
  140. <span><i>¥:</i><i>210000.00元</i></span>
  141. <span><i>型号:</i><i>7300LI</i></span>
  142. <span>女图片介绍一下美女美绍</span>
  143. </div>
  144. </div>
  145. <div class="images-goods">
  146. <div>
  147. <a href=""><img height="120" src="images/car/05.jpg" ></a>
  148. <span><i>¥:</i><i>210000.00元</i></span>
  149. <span><i>型号:</i><i>7300LI</i></span>
  150. <span>女图片介绍一下美女美绍</span>
  151. </div>
  152. </div>
  153. <div class="images-goods">
  154. <div>
  155. <a href=""><img height="120" src="images/car/06.jpg" ></a>
  156. <span><i>¥:</i><i>210000.00元</i></span>
  157. <span><i>型号:</i><i>7300LI</i></span>
  158. <span>女图片介绍一下美女美绍</span>
  159. </div>
  160. </div>
  161. </article>
  162. </section>
  163. <section>
  164. <h3><span>轿车专区</span></h3>
  165. <article>
  166. <div class="images-goods">
  167. <div>
  168. <a href=""><img height="120" src="images/car/01.jpg" ></a>
  169. <span><i>¥:</i><i>210000.00元</i></span>
  170. <span><i>型号:</i><i>7300LI</i></span>
  171. <span>女图片介绍一下美女美绍</span>
  172. </div>
  173. </div>
  174. <div class="images-goods">
  175. <div>
  176. <a href=""><img height="120" src="images/car/02.jpg"></a>
  177. <span><i>¥:</i><i>210000.00元</i></span>
  178. <span><i>型号:</i><i>7300LI</i></span>
  179. <span>女图片介绍一下美女美绍</span>
  180. </div>
  181. </div>
  182. <div class="images-goods">
  183. <div>
  184. <a href=""><img height="120" src="images/car/03.jpg" ></a>
  185. <span><i>¥:</i><i>210000.00元</i></span>
  186. <span><i>型号:</i><i>7300LI</i></span>
  187. <span>女图片介绍一下美女美绍</span>
  188. </div>
  189. </div>
  190. <div class="images-goods">
  191. <div>
  192. <a href=""><img height="120" src="images/car/04.jpg" ></a>
  193. <span><i>¥:</i><i>210000.00元</i></span>
  194. <span><i>型号:</i><i>7300LI</i></span>
  195. <span>女图片介绍一下美女美绍</span>
  196. </div>
  197. </div>
  198. <div class="images-goods">
  199. <div>
  200. <a href=""><img height="120" src="images/car/05.jpg" ></a>
  201. <span><i>¥:</i><i>210000.00元</i></span>
  202. <span><i>型号:</i><i>7300LI</i></span>
  203. <span>女图片介绍一下美女美绍</span>
  204. </div>
  205. </div>
  206. <div class="images-goods">
  207. <div>
  208. <a href=""><img height="120" src="images/car/06.jpg" ></a>
  209. <span><i>¥:</i><i>210000.00元</i></span>
  210. <span><i>型号:</i><i>7300LI</i></span>
  211. <span>女图片介绍一下美女美绍</span>
  212. </div>
  213. </div>
  214. </article>
  215. </section>
  216. </div>
  217. </main>
  218. <?php inc
  219. </body>
  220. </html>

全站CSS代码如下:

  1. /*引进矢量标*/
  2. @import url(../ico-css/iconfont.css);
  3. /*初始化*/
  4. * {
  5. margin: 0 auto;
  6. padding: 0;
  7. /* outline: 1px dashed; */
  8. -webkit-tap-highlight-color: transparent;
  9. }
  10. img {
  11. width: 100%;
  12. }
  13. a {
  14. font-size: 14px;
  15. text-decoration: none;
  16. }
  17. ul li {
  18. margin: 0;
  19. padding: 0;
  20. }
  21. li {
  22. list-style: none;
  23. }
  24. /*头部样式*/
  25. body {
  26. min-width: 320px;
  27. max-width: 768px;
  28. margin: 0 auto;
  29. position: relative;
  30. flex-direction: column;
  31. background-color: #edeff0;
  32. overflow-x: hidden;
  33. font-size: 16px;
  34. color: gray;
  35. width: auto;
  36. height: auto;
  37. display: flex;
  38. box-sizing: border-box;
  39. vertical-align: top;
  40. -webkit-overflow-scrolling: touch;
  41. }
  42. /* 上导航栏 */
  43. header {
  44. vertical-align: top;
  45. height: 45px;
  46. width: 100%;
  47. background-color: #444444;
  48. color: #ffffff;
  49. display: flex;
  50. box-sizing: border-box;
  51. flex-direction: row;
  52. justify-content: space-between;
  53. align-items: center;
  54. }
  55. body header a {
  56. height: 45px;
  57. font-size: 16px;
  58. line-height:45px;
  59. align-content: center;
  60. color: #ffffff;
  61. letter-spacing: 8px
  62. }
  63. body header a:hover {
  64. background: white;
  65. color: black;
  66. }
  67. /* 底部导航栏样式 */
  68. footer {
  69. height: 60px;
  70. width: 100%;
  71. background-color: #444444;
  72. color: #ffffff;
  73. }
  74. footer ul {
  75. height: 60px;
  76. display: flex;
  77. box-sizing: border-box;
  78. flex-flow: row nowrap;
  79. justify-content: space-between;
  80. }
  81. footer ul li {
  82. flex: 1;
  83. }
  84. footer ul li a span {
  85. display: flex;
  86. height: 60px;
  87. flex-flow: column wrap;
  88. width: 50%;
  89. letter-spacing: 5px
  90. }
  91. footer ul li a span i:first-of-type {
  92. color: white;
  93. font-size: 25px;
  94. padding: 5px 0 2px 0;
  95. font-style: normal;
  96. }
  97. footer ul li a span i:last-of-type {
  98. color: white;
  99. font-size: 15px;
  100. font-style: normal;
  101. }
  102. /*首页例表页主体区*/
  103. body>main {
  104. display: flex;
  105. flex: 1;
  106. flex-direction: column;
  107. width: 100%;
  108. overflow-y: scroll;
  109. }
  110. body>main>.main-part {
  111. width: 100%;
  112. margin-top: 5px;
  113. margin-bottom: 20px;
  114. }
  115. body>main>.main-part>section>h3{
  116. margin-bottom: 5px;
  117. text-align: center;
  118. }
  119. body>main>.main-part>section>h3>span {
  120. font-size: 16px;
  121. color: red;
  122. text-align: center;
  123. border-bottom: 2px solid red;
  124. font-weight: bolder;
  125. }
  126. body>main>.main-part>section>article {
  127. display: flex;
  128. flex-flow: row wrap;
  129. margin-top: 5px;
  130. }
  131. body>main>.main-part>section>article>.images-goods{
  132. display: flex;
  133. flex-flow:row wrap;
  134. width: 33.3%;
  135. justify-content: space-evenly;
  136. align-items: center;
  137. }
  138. body>main>.main-part>section>article>.images-goods>div{
  139. display: flex;
  140. flex-flow: column wrap;
  141. justify-content:space-evenly;
  142. align-content: space-between;
  143. width: 90%;
  144. margin: 10px 5px;
  145. border-radius: 5px;
  146. background-color:rgb(245, 245, 245);
  147. }
  148. body>main>.main-part>section>article>.images-goods>div:hover{
  149. box-shadow: 0 0 5px silver;
  150. }
  151. body>main>.main-part>section>article>.images-goods>div img{
  152. border-radius: 5px 5px 0 0;
  153. height: 150px;
  154. }
  155. body>main>.main-part>section>article>.images-goods>div>span{
  156. width: 100%;
  157. height: 25px;
  158. line-height: 25px;
  159. display: flex;
  160. box-sizing: border-box;
  161. padding: 0 10px;
  162. overflow: hidden;
  163. white-space: nowrap;
  164. text-overflow:ellipsis;
  165. }
  166. body>main>.main-part>section>article>.images-goods>div>span>i{
  167. height: 25px;
  168. line-height: 25px;
  169. display: block;
  170. box-sizing: border-box;
  171. overflow: hidden;
  172. text-overflow:ellipsis;
  173. font-style: normal;
  174. }
  175. body>main>.main-part>section>article>.images-goods>div>span>i:first-of-type {
  176. width: 30%;
  177. color: tomato;
  178. height: 25px;
  179. text-align: right;
  180. }
  181. body>main>.main-part>section>article>.images-goods>div>span>i:last-of-type {
  182. width:70%;
  183. text-align:left;
  184. }
  185. /* 产品详情页样式 */
  186. body>main>.main-part>section>article>.images-details{
  187. display: flex;
  188. flex: 1;
  189. width: 100%;
  190. justify-content: space-evenly;
  191. align-items: center;
  192. }
  193. body>main>.main-part>section>article>.images-details>div{
  194. display: flex;
  195. flex: 1;
  196. width: 100%;
  197. flex-flow: column wrap;
  198. justify-content: space-evenly;
  199. align-items:left;
  200. }
  201. body>main>.main-part>section>article>.images-details>div img{
  202. border-radius: 5px 5px 0 0;
  203. height: 300px;
  204. }
  205. body>main>.main-part>section>article>.images-details>div span{
  206. width: 100%;
  207. height: auto;
  208. line-height: 25px;
  209. display: flex;
  210. box-sizing: border-box;
  211. padding: 0 10px;
  212. }
  213. body>main>.main-part>section>article>.images-details>div>span i:first-of-type {
  214. width: 30%;
  215. color: tomato;
  216. height: 25px;
  217. text-align: right;
  218. }
  219. body>main>.main-part>section>article>.images-details>div>span i:last-of-type {
  220. width:70%;
  221. text-align:left;
  222. }
  1. 第二步将站点进行PHP站点模块化练习。
    2.1将公共部分的头部public_header.php与尾部public_footer.php进行分离。
    2.2现在还没有数据库,就将站点的常量以及网站数据做一个数组写在:config.php中。
    先来看一下首页效果图吧:

    再看只改了几行代码的产品详情图:

    现在看一下代码部分吧:
    公共头部public_header.php代码如下:

    1. <!-- 引入网站配置 -->
    2. <?php include 'config.php' ?>
    3. <!DOCTYPE html>
    4. <html lang="en">
    5. <head>
    6. <meta charset="UTF-8">
    7. <title><?php echo $siteTitle?></title>
    8. <meta name="apple一mobile一web一app一capable" content="yes">
    9. <link rel="stylesheet" href="css/index.css">
    10. </head>
    11. <body>
    12. <!--头部-->
    13. <header>
    14. <a href="index.php">首页</a>
    15. <a href="sales.php">促销</a>
    16. <?php foreach ($categories as $category) : ?>
    17. <a href="<?php echo $category['url'] ?>"><?php echo $category['name'] ?></a>
    18. <?php endforeach ?>
    19. </header>

    公共尾部public_footer.php如下:

    1. <!--脚部-->
    2. <footer>
    3. <ul>
    4. <li>
    5. <a href="#"><span> <i class="iconfont icon-cheliangguanli"></i><i>SUV</i></span></a>
    6. </li>
    7. <li>
    8. <a href="#"><span> <i class="iconfont icon-cheliang-"></i><i>轿车</i></span></a>
    9. </li>
    10. <li>
    11. <a href="#"><span> <i class="iconfont icon-shiyongshouce"></i><i>手册</i></span></a>
    12. </li>
    13. <li>
    14. <a href="#"><span> <i class="iconfont icon-huiyuan"></i><i>会员</i></span></a>
    15. </li>
    16. </ul>
    17. </footer>
    18. </body>
    19. </html>

    网站配置config.php如下:

    1. //网站标题命名
    2. $siteTitle='汽车4S店销售网';
    3. //定义图片路径常量
    4. const STATIC_PATH = 'images/';
    5. //定义优惠促销价格
    6. const price2 = '150000';
    7. //顶部导航栏目
    8. $categories= [
    9. ['id'=>1, 'name'=>'SUV','url'=>'list.php?cid=1'],
    10. ['id'=>2, 'name'=>'轿车','url'=>'list.php?cid=2'],
    11. ];
    12. //底部模块栏目
    13. $module = [
    14. ['id'=>1, 'name'=>'SUV','url'=>'module.php?cid=1'],
    15. ['id'=>2, 'name'=>'轿车','url'=>'module.php?cid=2'],
    16. ['id'=>3, 'name'=>'手册','url'=>'module.php?cid=3'],
    17. ['id'=>4, 'name'=>'轿车','url'=>'module.php?cid=4'],
    18. ];
    19. //车辆信息
    20. $goods = [
    21. [
    22. 'id' => 1,
    23. 'name' => '轿车001',
    24. 'pic' => '01.jpg',
    25. 'price' => '150000',
    26. 'model' => 'H9运动版',
    27. 'url' => 'detail.php?id=1',
    28. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    29. 'cid'=>'2',
    30. ],
    31. [
    32. 'id' => 2,
    33. 'name' => '轿车001',
    34. 'pic' => '02.jpg',
    35. 'price' => '210000',
    36. 'model' => 'H10运动版',
    37. 'url' => 'detail.php?id=2',
    38. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    39. 'cid'=>'2',
    40. ],
    41. [
    42. 'id' => 3,
    43. 'name' => '轿车003',
    44. 'pic' => '03.jpg',
    45. 'price' => '140000',
    46. 'model' => 'H10运动版',
    47. 'url' => 'detail.php?id=3',
    48. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    49. 'cid'=>'2',
    50. ],
    51. [
    52. 'id' => 4,
    53. 'name' => '轿车004',
    54. 'pic' => '04.jpg',
    55. 'price' => '138000',
    56. 'model' => 'H12运动版',
    57. 'url' => 'detail.php?id=4',
    58. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    59. 'cid'=>'2',
    60. ],
    61. [
    62. 'id' => 5,
    63. 'name' => '轿车005',
    64. 'pic' => '05.jpg',
    65. 'price' => '260000',
    66. 'model' => 'H13运动版',
    67. 'url' => 'detail.php?id=5',
    68. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    69. 'cid'=>'2',
    70. ],
    71. [
    72. 'id' => 6,
    73. 'name' => '轿车006',
    74. 'pic' => '06.jpg',
    75. 'price' => '210000',
    76. 'model' => 'H9运动版',
    77. 'url' => 'detail.php?id=6',
    78. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    79. 'cid'=>'2',
    80. ],
    81. [
    82. 'id' => 7,
    83. 'name' => 'SUV',
    84. 'pic' => '07.jpg',
    85. 'price' => '210000',
    86. 'model' => 'SUV运动版',
    87. 'url' => 'detail.php?id=7',
    88. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    89. 'cid'=>'1',
    90. ],
    91. [
    92. 'id' => 8,
    93. 'name' => 'SUV',
    94. 'pic' => '08.jpg',
    95. 'price' => '220000',
    96. 'model' => 'SUV运动版02',
    97. 'url' => 'detail.php?id=8',
    98. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    99. 'cid'=>'1',
    100. ],
    101. [
    102. 'id' => 9,
    103. 'name' => 'SUV',
    104. 'pic' => '09.jpg',
    105. 'price' => '220000',
    106. 'model' => 'SUV运动版03',
    107. 'url' => 'detail.php?id=9',
    108. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    109. 'cid'=>'1',
    110. ],
    111. [
    112. 'id' => 10,
    113. 'name' => 'SUV',
    114. 'pic' => '10.jpg',
    115. 'price' => '220000',
    116. 'model' => 'SUV运动版03',
    117. 'url' => 'detail.php?id=10',
    118. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    119. 'cid'=>'1',
    120. ],
    121. [
    122. 'id' => 11,
    123. 'name' => 'SUV',
    124. 'pic' => '11.jpg',
    125. 'price' => '270000',
    126. 'model' => 'SUV运动版08',
    127. 'url' => 'detail.php?id=11',
    128. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    129. 'cid'=>'1',
    130. ],
    131. [
    132. 'id' => 12,
    133. 'name' => 'SUV',
    134. 'pic' => '12.jpg',
    135. 'price' => '220000',
    136. 'model' => 'SUV运动版08',
    137. 'url' => 'detail.php?id=12',
    138. 'details'=>'车辆详细介绍有待小编更新中,敬请期待',
    139. 'cid'=>'1',
    140. ],
    141. ];

    万事准备好了,就等着做首页了。首页优惠促销就是增加了一个if判断。判断价格;其他的两个栏目就是遍历了产品中的数组。
    网站首页index.php如下:

    1. <!-- 引入公共头部 -->
    2. <?php include __DIR__ . '/inc/public_header.php' ?>
    3. <!--主体-->
    4. <main>
    5. <div class="main-part">
    6. <section>
    7. <h3><span>促销专区</span></h3>
    8. <article>
    9. <?php foreach ($goods as $good) : ?>
    10. <!-- 如果产品宣传价格低于规定的优惠促销价格 -->
    11. <?php if ($good['price'] <= price2) : ?>
    12. <div class="images-goods">
    13. <div>
    14. <a href="<?php echo $good['url'] ?>"><img height="120" src="<?php echo STATIC_PATH . $good['pic'] ?>"></a>
    15. <span><i>&yen;:</i><i><?php echo $good['price'] ?></i></span>
    16. <span><i>型号:</i><i><?php echo $good['model'] ?></i></span>
    17. <span><?php echo $good['details'] ?></span>
    18. </div>
    19. </div>
    20. <?php endif ?>
    21. <?php endforeach ?>
    22. </article>
    23. </section>
    24. <?php foreach ($categories as $category) : ?>
    25. <section>
    26. <h3><span><?php echo $category['name'] ?></span></h3>
    27. <article>
    28. <?php foreach ($goods as $good) : ?>
    29. <?php if ((int) $category['id'] === (int) $good['cid']) : ?>
    30. <div class="images-goods">
    31. <div>
    32. <a href="<?php echo $good['url'] ?>"><img height="120" src="<?php echo STATIC_PATH . $good['pic'] ?>"></a>
    33. <span><i>&yen;:</i><i><?php echo $good['price'] ?></i></span>
    34. <span><i>型号:</i><i><?php echo $good['model'] ?></i></span>
    35. <span><?php echo $good['details'] ?></span>
    36. </div>
    37. </div>
    38. <?php endif ?>
    39. <?php endforeach ?>
    40. </article>
    41. </section>
    42. <?php endforeach ?>
    43. </div>
    44. </main>
    45. <!-- 引入公共尾部 -->
    46. <?php include __DIR__ . '/inc/public_footer.php' ?>

    网站列表页list.php如下:

    1. <!-- 引入公共头部 -->
    2. <?php include __DIR__.'/inc/public_header.php' ?>
    3. <!--主体-->
    4. <main>
    5. <div class="main-part">
    6. </section>
    7. <!-- 获取地址栏传过来的栏目ID参数值 -->
    8. <?php $cid = $_GET['cid'];?>
    9. <?php foreach ($categories as $category) : ?>
    10. <!-- 判断地址栏的栏目ID与数组中的ID参数值相等 -->
    11. <?php if ($category['id'] === intval($cid)) :?>
    12. <section>
    13. <h3><span><?php echo $category['name'] ?></span></h3>
    14. <article>
    15. <!-- 获取当前栏目下的商品值 -->
    16. <?php foreach ($goods as $good) : ?>
    17. <?php if ((int) $category['id'] === (int) $good['cid']) : ?>
    18. <div class="images-goods">
    19. <div>
    20. <a href="<?php echo $good['url'] ?>"><img height="120" src="<?php echo STATIC_PATH . $good['pic'] ?>"></a>
    21. <span><i>&yen;:</i><i><?php echo $good['price'] ?></i></span>
    22. <span><i>型号:</i><i><?php echo $good['model'] ?></i></span>
    23. <span><?php echo $good['details'] ?></span>
    24. </div>
    25. </div>
    26. <?php endif ?>
    27. <?php endforeach ?>
    28. </article>
    29. </section>
    30. <?php endif ?>
    31. <?php endforeach ?>
    32. </div>
    33. </main>
    34. <!-- 引入公共尾部 -->
    35. <?php include __DIR__. '/inc/public_footer.php' ?>

    网站详细页detail.php如下:

    1. <!-- 引入公共头部 -->
    2. <?php include __DIR__ . '/inc/public_header.php' ?>
    3. <!--主体-->
    4. <main>
    5. <div class="main-part">
    6. <section>
    7. <!-- 获取地址栏传过来的产品ID参数值 -->
    8. <?php $id = $_GET['id']; ?>
    9. <?php foreach ($goods as $good) : ?>
    10. <?php if ($good['id'] == $id) : ?>
    11. <h3><span><?php echo $good['model'] ?></span></h3>
    12. <article>
    13. <div class="images-details">
    14. <div>
    15. <a href="<?php echo $good['url'] ?>"><img height="120" src="<?php echo STATIC_PATH . $good['pic'] ?>"></a>
    16. <span><i>&yen;:</i><i><?php echo $good['price'] ?></i></span>
    17. <span><i>型号:</i><i><?php echo $good['model'] ?></i></span>
    18. <span><?php echo $good['details'] ?></span>
    19. </div>
    20. </div>
    21. <?php endif ?>
    22. <?php endforeach ?>
    23. </article>
    24. </section>
    25. </div>
    26. </main>
    27. <!-- 引入公共尾部 -->
    28. <?php include __DIR__ . '/inc/public_footer.php' ?>

    总结:
    网页布局在电脑端还是比较容易写,就是在手机端兼容性有困难,全站完成没有难度。还是得多写。

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:vh, vw不会产生错位的, 应该你是用错了元素, 用在html上试试看, 因为这个单与设备相关
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