博客列表 >html布局与实例

html布局与实例

自由之上
自由之上原创
2020年08月18日 13:46:09652浏览

flex布局与glid布局

flex实现pc端三列布局



  1. <header>
  2. <nav>
  3. <a href="">LOGO</a>
  4. <a href="">导航1</a>
  5. <a href="">导航2</a>
  6. <a href="">导航3</a>
  7. <a href="">导航4</a>
  8. <a href="">导航5</a>
  9. <a href="">导航6</a>
  10. <a href="">登录</a>
  11. </nav>
  12. </header>
  13. <div class="container">
  14. <div class="left">左侧</div>
  15. <main>内容</main>
  16. <div class="right">右侧</div>
  17. </div>
  18. <footer>
  19. <p>欢迎光临,版权号239082308230894</p>
  20. <p>地址:北京上海广州</p>
  21. </footer>
  1. /* 重置样式 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. a {
  8. text-decoration: none;
  9. color: #666;
  10. }
  11. /* 显示内容使用flex布局垂直排列 */
  12. body {
  13. display: flex;
  14. flex-flow: column nowrap;
  15. }
  16. /* 设置页眉与页脚具有相同属性的样式 */
  17. header,
  18. footer {
  19. height: 50px;
  20. background-color: lightcyan;
  21. display: flex;
  22. flex-flow: column nowrap;
  23. justify-content: center;
  24. align-items: stretch;
  25. }
  26. /* 设置导航栏 */
  27. header>nav {
  28. display: flex;
  29. justify-content: center;
  30. align-items: center;
  31. }
  32. header>nav>a {
  33. padding: 0 10px;
  34. }
  35. /* logo标签与登录标签区别对待 */
  36. header>nav>a:first-of-type {
  37. margin-right: 20px;
  38. font-size: 2.0rem;
  39. color: blue;
  40. }
  41. header>nav>a:last-of-type {
  42. margin-left: auto;
  43. margin-right: 50px;
  44. }
  45. header>nav>a:hover:not(:first-of-type) {
  46. color: red;
  47. }
  48. /* 设置主体区样式 */
  49. .container {
  50. min-height: 500px;
  51. margin: 10px;
  52. display: flex;
  53. }
  54. .container>.left,
  55. .container>.right {
  56. background-color: lightgray;
  57. flex: 0 0 200px;
  58. }
  59. .container>main {
  60. margin-left: 10px;
  61. margin-right: 10px;
  62. background-color: lightpink;
  63. flex: 1 1 600px;
  64. }
  65. footer {
  66. align-items: center;
  67. }
  68. /* 使用媒体查询适配终端设备样式 */
  69. @media screen and (max-width:800px) {
  70. .container>.right {
  71. display: none;
  72. }
  73. .container>main {
  74. margin-right: 0;
  75. }
  76. }
  77. @media screen and (max-width:600px) {
  78. .container>.left {
  79. display: none;
  80. }
  81. .container>main {
  82. margin-left: 0;
  83. }
  84. header a:not(:first-of-type):not(:last-of-type) {
  85. display: none;
  86. }
  87. }

说明:

  1. 界面分为页眉、主体、页脚,使用flex布局垂直排列
  2. 页眉与页脚使用flex垂直水平居中对齐,固定高度与背景颜色
  3. 导航区使用flex水平布局,对logo图标与登录分别处理
  4. 左栏、内容区、左栏通过flex的放大因子、缩小因子,基准尺寸设置大小
  5. 使用媒体查询适配终端设备样式

flex实现(m.php.cn)首页

图一 图二 图三

参考:
解决img在a标签中存在下间距问题

  1. <header>
  2. <!-- 导航栏 -->
  3. <a href=""><span class="user"><img id="user_avater" src="image/user_avatar.jpg"></span></a>
  4. <a href=""><span class="logo"><img id="logo" src="image/logo.png"></span></a>
  5. <a href=""><span class="iconfont more">&#xe655;</span></a>
  6. </header>
  7. <!-- 轮播图 -->
  8. <a href=""><img class="banner" src="image/lunbotu.png" alt=""></a>
  9. <!-- 菜单栏 -->
  10. <div class="menu">
  11. <div class="item"><a href=""><img src="image/html.png" alt=""></a><a href="">HTML/CSS</a></div>
  12. <div class="item"><a href=""><img src="image/JavaScript.png" alt=""></a><a href="">JavaScript</a></div>
  13. <div class="item"><a href=""><img src="image/code.png" alt=""></a><a href="">服务端</a></div>
  14. <div class="item"><a href=""><img src="image/sql.png" alt=""></a><a href="">数据库</a></div>
  15. <div class="item"><a href=""><img src="image/app.png" alt=""></a><a href="">移动端</a></div>
  16. <div class="item"><a href=""><img src="image/manual.png" alt=""></a><a href="">手册</a></div>
  17. <div class="item"><a href=""><img src="image/tool2.png" alt=""></a><a href="">工具</a></div>
  18. <div class="item"><a href=""><img src="image/live.png" alt=""></a><a href="">直播</a></div>
  19. </div>
  20. <!-- 推荐课程 -->
  21. <h2 class="title">推荐课程</h2>
  22. <div class="recommend">
  23. <div class="head">
  24. <a href=""><img src="image/recommed1.jpg" alt=""></a>
  25. <a href=""><img src="image/recommed2.jpg" alt=""></a>
  26. </div>
  27. <div class="body">
  28. <a href="">
  29. <img src="image/recommed4.jpg" alt="">
  30. <dl>
  31. <dt>CI框架30分钟极速入门</dt>
  32. <dd>
  33. <span class="tip">中级</span>3232次播放
  34. </dd>
  35. </dl>
  36. </a>
  37. <a href="">
  38. <img src="image/recommed3.jpg" alt="">
  39. <dl>
  40. <dt>CI框架30分钟极速入门</dt>
  41. <dd>
  42. <span class="tip">中级</span>3232次播放
  43. </dd>
  44. </dl>
  45. </a>
  46. </div>
  47. </div>
  48. <!-- 最近更新 -->
  49. <h2 class="title">最近更新</h2>
  50. <div class="new">
  51. <a href="">
  52. <img src="image/new1.png" alt="">
  53. <dl>
  54. <dt>我的十年撸码生涯啦啦啦啦出港年费2天</dt>
  55. <dd>主题:2天速成vuejs出港年费2天速成vuejs出港年费</dd>
  56. <dd><span class="tip">初级</span><span>1234次播放</span></dd>
  57. </dl>
  58. </a>
  59. <a href="">
  60. <img src="image/new2.png" alt="">
  61. <dl>
  62. <dt>我的十年撸码生涯啦啦啦啦出港年费2天</dt>
  63. <dd>主题:2天速成vuejs出港年费2天速成vuejs出港年费</dd>
  64. <dd><span class="tip">初级</span><span>1234次播放</span></dd>
  65. </dl>
  66. </a>
  67. <a href="">
  68. <img src="image/new3.png" alt="">
  69. <dl>
  70. <dt>我的十年撸码生涯啦啦啦啦出港年费2天</dt>
  71. <dd>主题:2天速成vuejs出港年费2天速成vuejs出港年费</dd>
  72. <dd><span class="tip">初级</span><span>1234次播放</span></dd>
  73. </dl>
  74. </a>
  75. </div>
  76. <!-- 最新文章 -->
  77. <h2 class="title">最新文章</h2>
  78. <div class="article">
  79. <a href="">
  80. <dl>
  81. <dt>centos7的网卡如何重启</dt>
  82. <dd>发布时间:2020-08-12</dd>
  83. </dl>
  84. <img src="image/article1.jpg" alt="">
  85. </a>
  86. <a href="">
  87. <dl>
  88. <dt>centos7的网卡如何重启</dt>
  89. <dd>发布时间:2020-08-12</dd>
  90. </dl>
  91. <img src="image/article2.jpg" alt="">
  92. </a>
  93. <a href="">
  94. <dl>
  95. <dt>centos7的网卡如何重启</dt>
  96. <dd>发布时间:2020-08-12</dd>
  97. </dl>
  98. <img src="image/article3.jpg" alt="">
  99. </a>
  100. <a href="">
  101. <span>更多内容</span>
  102. </a>
  103. </div>
  104. <!-- 最新博文 -->
  105. <h2 class="title">最新博文</h2>
  106. <div class="blog">
  107. <a href="">
  108. <dl>
  109. <dt>火狐浏览器如何设置爬虫代理</dt>
  110. <dd>2020-08-12</dd>
  111. </dl>
  112. </a>
  113. <a href="">
  114. <dl>
  115. <dt>火狐浏览器如何设置爬虫代理</dt>
  116. <dd>2020-08-12</dd>
  117. </dl>
  118. </a>
  119. <a href="">
  120. <dl>
  121. <dt>火狐浏览器如何设置爬虫代理</dt>
  122. <dd>2020-08-12</dd>
  123. </dl>
  124. </a>
  125. <a href="">
  126. <dl>
  127. <dt>火狐浏览器如何设置爬虫代理</dt>
  128. <dd>2020-08-12</dd>
  129. </dl>
  130. </a>
  131. <a href="">
  132. <dl>
  133. <dt>火狐浏览器如何设置爬虫代理</dt>
  134. <dd>2020-08-12</dd>
  135. </dl>
  136. </a>
  137. <a href="">
  138. <span>更多内容</span>
  139. </a>
  140. </div>
  141. <!-- 页脚 -->
  142. <footer>
  143. <a href=""><span class="iconfont tab">&#xe61f;</span><span>首页</span></a>
  144. <a href=""><span class="iconfont tab">&#xe61e;</span><span>视频</span></a>
  145. <a href=""><span class="iconfont tab">&#xe64f;</span><span>发现</span></a>
  146. <a href=""><span class="iconfont tab">&#xe62f;</span><span>我的</span></a>
  147. </footer>
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. a {
  7. text-decoration: none;
  8. color: #666;
  9. }
  10. html {
  11. font-size: 16px;
  12. }
  13. body {
  14. min-width: 360px;
  15. display: flex;
  16. flex-flow: column nowrap;
  17. background-color: #efefef;
  18. }
  19. /* 头部导航栏 */
  20. header {
  21. width: 100vw;
  22. height: 42px;
  23. background-color: black;
  24. position: fixed;
  25. display: flex;
  26. justify-content: space-between;
  27. align-items: center;
  28. }
  29. header>a {
  30. padding: 0 10px;
  31. }
  32. #user_avater {
  33. width: 25px;
  34. height: 25px;
  35. border-radius: 25px;
  36. }
  37. #logo {
  38. height: 45px;
  39. }
  40. .iconfont.more {
  41. font-size: 1.5rem;
  42. color: white;
  43. font-weight: bold;
  44. }
  45. /* 轮播图 */
  46. .banner {
  47. width: 100%;
  48. height: 150px;
  49. margin-top: 42px;
  50. }
  51. /* 菜单栏 */
  52. .menu {
  53. display: flex;
  54. flex-flow: row wrap;
  55. background-color: white;
  56. }
  57. .menu>.item {
  58. width: 25vw;
  59. text-align: center;
  60. padding: 10px;
  61. display: flex;
  62. flex-flow: column;
  63. align-items: center;
  64. }
  65. .menu img {
  66. width: 50%;
  67. }
  68. .menu>.item>a {
  69. font-size: 0.8rem;
  70. }
  71. /* 推荐课程 */
  72. .title {
  73. padding: 20px 10px 0;
  74. color: #666;
  75. font-weight: 500;
  76. font-size: 1.3rem;
  77. }
  78. .recommend {
  79. padding: 10px;
  80. display: flex;
  81. flex-flow: column;
  82. }
  83. .recommend>.head {
  84. display: flex;
  85. justify-content: center;
  86. align-items: center;
  87. }
  88. .recommend>.head>a {
  89. font-size: 0;
  90. }
  91. .recommend>.head>a:last-of-type {
  92. margin-left: 10px;
  93. }
  94. .recommend>.head img {
  95. width: 100%;
  96. }
  97. .recommend>.body {
  98. display: flex;
  99. flex-flow: column;
  100. }
  101. .recommend>.body a {
  102. height: 98px;
  103. margin-top: 20px;
  104. padding: 10px;
  105. background-color: white;
  106. display: flex;
  107. }
  108. .recommend>.body img {
  109. width: 40%;
  110. }
  111. .recommend>.body dl {
  112. margin-left: 10px;
  113. }
  114. .recommend>.body dl>dt {
  115. color: #999;
  116. }
  117. .tip {
  118. padding: 3px 5px;
  119. color: white;
  120. margin-right: 5px;
  121. background-color: #000000;
  122. border-radius: 10px;
  123. font-size: 0.7rem;
  124. font-weight: 800;
  125. }
  126. .recommend>.body dl>dd {
  127. color: #999;
  128. font-size: 0.7rem;
  129. margin-top: 15px;
  130. }
  131. /* 最近更新 */
  132. .new {
  133. padding: 10px;
  134. display: flex;
  135. flex-flow: column;
  136. }
  137. .new a {
  138. height: 98px;
  139. margin-top: 20px;
  140. padding: 10px;
  141. background-color: white;
  142. display: flex;
  143. }
  144. .new a:first-of-type {
  145. margin-top: 0px;
  146. }
  147. .new img {
  148. width: 40%;
  149. }
  150. .new dl {
  151. width: 56%;
  152. margin-left: 10px;
  153. display: flex;
  154. flex-flow: column;
  155. justify-content: space-around;
  156. }
  157. .new dt,
  158. .new dd {
  159. color: #999;
  160. overflow: hidden;
  161. text-overflow: ellipsis;
  162. white-space: nowrap;
  163. }
  164. .new dd {
  165. font-size: 0.7rem;
  166. }
  167. .new dd:last-of-type {
  168. display: flex;
  169. justify-content: space-between;
  170. align-items: center;
  171. }
  172. /* 最新文章 */
  173. .article {
  174. padding: 10px;
  175. display: flex;
  176. flex-flow: column;
  177. }
  178. .article>a {
  179. height: 84px;
  180. margin-top: 10px;
  181. padding: 10px;
  182. background-color: white;
  183. display: flex;
  184. flex-flow: row nowrap;
  185. justify-content: space-between;
  186. }
  187. .article>a:first-of-type {
  188. margin-top: 0;
  189. }
  190. .article img {
  191. width: 30%;
  192. }
  193. .article dt {
  194. font-size: 0.9rem;
  195. font-weight: bold;
  196. color: #999;
  197. }
  198. .article dd {
  199. margin-top: 10px;
  200. font-size: 0.7rem;
  201. color: #999;
  202. }
  203. .article>a:last-of-type {
  204. height: 30px;
  205. width: 100%;
  206. padding: 0;
  207. font-size: 0.9rem;
  208. color: #999;
  209. text-align: center;
  210. line-height: 30px;
  211. display: initial;
  212. }
  213. /* 最新博文 */
  214. .blog {
  215. padding: 10px;
  216. margin-bottom: 50px;
  217. display: flex;
  218. flex-flow: column;
  219. }
  220. .blog>a {
  221. padding: 10px;
  222. margin-top: 10px;
  223. background-color: white;
  224. }
  225. .blog a:first-of-type {
  226. margin-top: 0;
  227. }
  228. .blog dl {
  229. display: flex;
  230. flex-flow: row nowrap;
  231. justify-content: space-between;
  232. align-items: center;
  233. }
  234. .blog dt {
  235. font-size: 0.8rem;
  236. color: #999;
  237. font-weight: bold;
  238. }
  239. .blog dd {
  240. font-size: 0.6rem;
  241. color: #999;
  242. }
  243. .blog>a:last-of-type {
  244. height: 30px;
  245. width: 100%;
  246. padding: 0;
  247. font-size: 0.9rem;
  248. color: #999;
  249. text-align: center;
  250. line-height: 30px;
  251. display: initial;
  252. }
  253. /* 页脚 */
  254. footer{
  255. height:50px;
  256. background-color: #efefef;
  257. border-top:1px solid #ccc;
  258. position:fixed;
  259. bottom:0;
  260. left: 0;
  261. right:0;
  262. display: flex;
  263. flex-flow:row nowrap;
  264. justify-content: space-around;
  265. align-items: center;
  266. }
  267. footer>a{
  268. display:flex;
  269. flex-flow:column nowrap;
  270. align-items:center;
  271. }
  272. footer>a:first-of-type{
  273. color:red;
  274. }
  275. footer .tab{
  276. font-size: 1.2rem;
  277. }
  278. footer span:last-of-type{
  279. font-size: 0.8rem;
  280. }

说明

  1. 准备素材 网站右键另存内将素材保存到本地
  2. 准备字体图标 iconfont网站查找素材添加到项目,下载到本地
  3. 分块处理 头部导航栏/轮播图/菜单栏/推荐课程/最近更新/最新文章/最新博文/底部选项卡
  4. 头部导航栏 flex水平排列,两端对齐,整体加一个左右边距,使用固定定位,不随滚动条的上下滚动而滚动
  5. 轮播图 宽度占满,高度固定
  6. 菜单栏 flex水平排列允许换行显示,项目宽度为设备宽度4/1(25vw)项目内部再使用flex垂直排列交叉轴方向居中显示
  7. 推荐/最近/最新博文 标题栏可统一设置样式,整体模块采用flex垂直排列,项目内再使用flex水平与垂直排列相互嵌套完成大致布局
  8. 底部选项卡 flex水平排列两端对齐,项目内使用flex垂直排列居中对齐,使用固定定位将该模块定位在页面底部

某企业站首页:星巴克

参考链接:星巴克官网: 用每一杯咖啡传递星巴克独特的咖啡体验

  • 媒体查询规则:
  • 设备屏幕最大为1024像素时:关闭侧边栏
图一 图二 图三
  1. <!-- 左侧导航 -->
  2. <nav>
  3. <header>
  4. <a href="" class="logo"><img src="image2/logo.svg" alt=""></a>
  5. <a href="">门店</a>
  6. <a href="">我的账户</a>
  7. <a href="">菜单</a>
  8. <a href="">
  9. <img src="image2/icon-hamburger.svg" alt="">
  10. </a>
  11. </header>
  12. <div class="body">
  13. <div class="con">
  14. <div class="content">
  15. <span>心情惬意,来杯咖啡吧 ☕</span>
  16. </div>
  17. <footer>
  18. <a href="">
  19. <img src="" alt=""><span>登录</span>
  20. </a>
  21. <a href=""><span>注册</span></a>
  22. </footer>
  23. </div>
  24. </div>
  25. </nav>
  26. <!-- 内容区 -->
  27. <section class="container">
  28. <section class="row">
  29. <div class="col-12 bigimg ">
  30. <span class="tag_ad">广告</span>
  31. <div class="hero"><img src="image2/banner.jpg" alt=""></div>
  32. </div>
  33. </section>
  34. <section class="row small_img">
  35. <div class="col-4"><img src="image2/tmall-2020-06-29-zh.jpg" alt=""></div>
  36. <div class="col-4"><img src="image2/starbucks-design-studio-web-china.jpg" alt=""></div>
  37. <div class="col-4"><img src="image2/homepage-career-cn.jpg" alt=""></div>
  38. </section>
  39. <!-- 第三部分 -->
  40. <section class="row msg">
  41. <div class="col-6 small_msg">
  42. <h2>星享俱乐部</h2>
  43. <p>开启您的星享之旅,星星越多、会员等级越高、<br>好礼越丰富。
  44. <a href="">了解更多 ›</a>
  45. </p>
  46. <p class="account"><a href="">注册</a><a href="">登录</a></p>
  47. </div>
  48. <div class="col-6 small_logo"><img src="image2/logo-msr-new.svg" alt=""></div>
  49. </section>
  50. <section class="row goods">
  51. <div class="col-12">
  52. <h2>星巴克精选</h2>
  53. <p>在星巴克天猫旗舰店发现更多咖啡心意</p>
  54. <div class="card">
  55. <a href="">
  56. <img src="image2/tmall-card-01.png" alt="">
  57. <span class="content">
  58. <h2>会员星礼包</h2>
  59. <p>星享卡新升级<br>更多心意好礼</p>
  60. <p>了解更多 ›</p>
  61. </span>
  62. </a>
  63. <a href="">
  64. <img src="image2/tmall-card-02.png" alt="">
  65. <span class="content">
  66. <h2>会员星礼包</h2>
  67. <p>星享卡新升级<br>更多心意好礼</p>
  68. <p>了解更多 ›</p>
  69. </span>
  70. </a>
  71. <a href="">
  72. <img src="image2/tmall-eticket.png" alt="">
  73. <span class="content">
  74. <h2>会员星礼包</h2>
  75. <p>星享卡新升级<br>更多心意好礼</p>
  76. <p>了解更多 ›</p>
  77. </span>
  78. </a>
  79. <a href="">
  80. <img src="image2/tmall-reserve.png" alt="">
  81. <span class="content">
  82. <h2>会员星礼包</h2>
  83. <p>星享卡新升级<br>更多心意好礼</p>
  84. <p>了解更多 ›</p>
  85. </span>
  86. </a>
  87. </div>
  88. </div>
  89. </section>
  90. <section class="row forum">
  91. <div class="col-12">
  92. <h2 class="title1">1912 派克街 | 咖啡星讲堂</h2>
  93. <p class="title2">了解更多星巴克咖啡文化</p>
  94. <div class="content">
  95. <a href="">
  96. <img src="image2/coffeehouse-coffee-cultivation-kv.jpg" alt="">
  97. <span class="tag_type"></span>
  98. <strong>咖啡的起源与培植</strong>
  99. </a>
  100. <a href="">
  101. <img src="image2/coffeehouse-4-fundamentals-kv.jpg" alt="">
  102. <span class="tag_type"></span>
  103. <strong>咖啡的起源与培植</strong>
  104. </a>
  105. <a href="">
  106. <img src="image2/coffeehouse-roast-story-kv.jpg" alt="">
  107. <span class="tag_type"></span>
  108. <strong>咖啡的起源与培植</strong>
  109. </a>
  110. <a href="">
  111. <img src="image2/coffeehouse-pour-over-kv.jpg" alt="">
  112. <span class="tag_type"></span>
  113. <strong>咖啡的起源与培植</strong>
  114. </a>
  115. <a href="">
  116. <img src="image2/coffeehouse-coffee-cultivation-kv.jpg" alt="">
  117. <span class="tag_type"></span>
  118. <strong>咖啡的起源与培植</strong>
  119. </a>
  120. <a href="">
  121. <img src="image2/coffeehouse-4-fundamentals-kv.jpg" alt="">
  122. <span class="tag_type"></span>
  123. <strong>咖啡的起源与培植</strong>
  124. </a>
  125. <a href="">
  126. <img src="image2/coffeehouse-roast-story-kv.jpg" alt="">
  127. <span class="tag_type"></span>
  128. <strong>咖啡的起源与培植</strong>
  129. </a>
  130. <a href="">
  131. <img src="image2/coffeehouse-pour-over-kv.jpg" alt="">
  132. <span class="tag_type"></span>
  133. <strong>咖啡的起源与培植</strong>
  134. </a>
  135. <a href="">
  136. <img src="image2/coffeehouse-coffee-cultivation-kv.jpg" alt="">
  137. <span class="tag_type"></span>
  138. <strong>咖啡的起源与培植</strong>
  139. </a>
  140. <a href="">
  141. <img src="image2/coffeehouse-4-fundamentals-kv.jpg" alt="">
  142. <span class="tag_type"></span>
  143. <strong>咖啡的起源与培植</strong>
  144. </a>
  145. <a href="">
  146. <img src="image2/coffeehouse-roast-story-kv.jpg" alt="">
  147. <span class="tag_type"></span>
  148. <strong>咖啡的起源与培植</strong>
  149. </a>
  150. <a href="">
  151. <img src="image2/coffeehouse-pour-over-kv.jpg" alt="">
  152. <span class="tag_type"></span>
  153. <strong>咖啡的起源与培植</strong>
  154. </a>
  155. </div>
  156. </div>
  157. </section>
  158. <section class="row">
  159. <footer class="col-12">
  160. <a href=""><img src="image2/icpicon.png" alt="">沪公网安备 ************号</a>
  161. <a href="">沪ICP备*****号</a>
  162. </footer>
  163. </section>
  164. </section>
  1. <style type="text/css">
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. a {
  8. text-decoration: none;
  9. }
  10. html {
  11. font-size: 10px;
  12. }
  13. /* 左侧导航 */
  14. nav {
  15. width: 30%;
  16. height: 100vh;
  17. background-color: white;
  18. display: flex;
  19. flex-flow: column nowrap;
  20. position: fixed;
  21. }
  22. nav>header {
  23. padding: 0 10px;
  24. height: 96px;
  25. background-color: lightcyan;
  26. display: flex;
  27. flex-flow: row nowrap;
  28. align-items: center;
  29. }
  30. nav>header>a {
  31. margin: 0 10px;
  32. color: inherit;
  33. font-weight: bold;
  34. font-size: 1.6rem;
  35. }
  36. nav>header>a:last-of-type {
  37. margin-left: auto;
  38. }
  39. nav>header>a:first-of-type>img {
  40. width: 36px;
  41. }
  42. nav>header>a:last-of-type>img {
  43. width: 24px;
  44. }
  45. nav>.body {
  46. width: 100%;
  47. height: 80vh;
  48. display: flex;
  49. flex-flow: column;
  50. justify-content: center;
  51. align-items: end;
  52. }
  53. nav>.body>.con {
  54. width: 70%;
  55. height: 100px;
  56. margin-right: 30px;
  57. }
  58. nav>.body .content>span {
  59. font-size: 2.5rem;
  60. font-weight: bold;
  61. }
  62. nav footer {
  63. margin-top: 30px;
  64. }
  65. nav>.body footer span {
  66. margin: 0 10px;
  67. padding: 2px 10px;
  68. color: #55A532;
  69. font-size: 1.7rem;
  70. border: 1px solid #55A532;
  71. border-radius: 10px;
  72. ;
  73. }
  74. /* 内容区 */
  75. .title1 {
  76. font-size: 2.2rem;
  77. font-weight: 400;
  78. margin-bottom: 18px;
  79. text-align: center;
  80. }
  81. .title2 {
  82. font-size: 1.6rem;
  83. text-align: center;
  84. color: rgba(0, 0, 0, 0.56);
  85. }
  86. .container {
  87. width: 70%;
  88. margin-left: 30%;
  89. border-left: 1px solid #D3D3D3;
  90. float: left;
  91. }
  92. .bigimg {
  93. position: relative;
  94. }
  95. .bigimg .tag_ad {
  96. padding: 3px 6px;
  97. font-size: 1.2rem;
  98. border-radius: 5px;
  99. color: #bbb;
  100. background-color: #555555;
  101. position: absolute;
  102. right: 10px;
  103. top: 10px;
  104. }
  105. .bigimg img {
  106. width: 100%;
  107. display: block;
  108. }
  109. /* 第二部分 */
  110. .small_img {
  111. padding: 0 10px;
  112. background-color: #F7F7F7;
  113. box-shadow: 0 0 2px #eee;
  114. }
  115. .small_img img {
  116. padding: 20px 10px;
  117. width: 100%;
  118. border-radius: 21px;
  119. }
  120. /* 第三部分 */
  121. .msg {
  122. height: 250px;
  123. }
  124. .msg .small_msg {
  125. margin-left: auto;
  126. display: flex;
  127. flex-flow: column;
  128. justify-content: center;
  129. }
  130. .msg h2 {
  131. font-size: 2.2rem;
  132. font-weight: 400;
  133. }
  134. .msg p {
  135. margin-top: 20px;
  136. font-size: 1.6rem;
  137. font-weight: 200;
  138. color: rgba(0, 0, 0, 0.56);
  139. line-height: 30px;
  140. }
  141. .msg a {
  142. color: #C2A661;
  143. }
  144. .msg .account a {
  145. color: #00A862;
  146. padding: 5px 15px;
  147. margin-top: 30px;
  148. border: 1px solid #00A862;
  149. border-radius: 20px;
  150. }
  151. .msg .account a:last-of-type {
  152. margin-left: 5px;
  153. }
  154. .msg img {
  155. width: 236px;
  156. }
  157. .msg .small_logo {
  158. display: flex;
  159. justify-content: center;
  160. align-items: center;
  161. }
  162. /* 第四部分 */
  163. .goods {
  164. height: 416px;
  165. background-color: #F7F7F7;
  166. display: flex;
  167. flex-flow: column;
  168. align-items: center;
  169. justify-content: center;
  170. }
  171. .goods h2 {
  172. font-size: 2.2rem;
  173. font-weight: 400;
  174. margin-bottom: 18px;
  175. text-align: center;
  176. }
  177. .goods p {
  178. font-size: 1.6rem;
  179. text-align: center;
  180. color: rgba(0, 0, 0, 0.56);
  181. }
  182. .goods .card {
  183. margin: 60px auto 0;
  184. max-width: 786px;
  185. display: flex;
  186. align-items: center;
  187. }
  188. .goods .card a {
  189. width: 25%;
  190. height: 197px;
  191. margin: 0 10px;
  192. background-color: white;
  193. display: flex;
  194. flex-flow: column;
  195. justify-content: center;
  196. border-right: 1px solid #EEEEEE;
  197. border-bottom: 1px solid #EEEEEE;
  198. border-left: 1px solid #EEEEEE;
  199. position: relative;
  200. }
  201. .goods .card a:hover {
  202. top: -8px;
  203. box-shadow: 0 1px 3px 2px rgba(0, 0, 0, 0.12);
  204. }
  205. .goods .card img {
  206. width: 101.4px;
  207. height: 72px;
  208. position: absolute;
  209. top: -30px;
  210. left: 0;
  211. right: 0;
  212. margin: 0 auto;
  213. }
  214. .goods .card h2 {
  215. margin-top: 20px;
  216. font-size: 1.6rem;
  217. color: rgba(0, 0, 0, 0.87);
  218. }
  219. .goods .card p {
  220. margin-top: 10px;
  221. color: rgba(0, 0, 0, 0.56);
  222. line-height: 30px;
  223. }
  224. .goods .card p:last-of-type {
  225. color: #887035;
  226. font-size: 1.2rem;
  227. }
  228. /* 第五部分 */
  229. .forum {
  230. }
  231. .forum h2{
  232. margin-top: 40px;
  233. }
  234. .forum a {
  235. width: 290px;
  236. background-color: white;
  237. border: 1px solid #CCCCCC;
  238. border-radius: 5px;
  239. overflow: hidden;
  240. display: inline-block;
  241. position: relative;
  242. }
  243. .forum a:hover{
  244. top:-5px;
  245. box-shadow: 2px 2px 2px #D3D3D3;
  246. }
  247. .forum img {
  248. width: 100%;
  249. height:168px;
  250. }
  251. .forum .content{
  252. margin-top: 40px;
  253. display: grid;
  254. grid-template-columns: repeat(auto-fill,290px);
  255. grid-template-rows: repeat(auto-fill,225px);
  256. place-content: space-evenly;
  257. gap:25px;
  258. }
  259. .forum strong{
  260. font-size: 1.6rem;
  261. font-weight: 400;
  262. padding: 0 20px;
  263. color:rgba(0, 0, 0, 0.87);
  264. line-height: 50px;
  265. }
  266. /* 结尾部分 */
  267. footer{
  268. margin-top: 30px;
  269. height:50px;
  270. text-align: center;
  271. }
  272. footer a{
  273. line-height: 50px;
  274. font-size: 1.4rem;
  275. color:rgb(51, 51, 51);
  276. }
  277. /* 设备屏幕最大为1024像素时使用该媒体查询 */
  278. @media screen and (max-width:1024px){
  279. nav{
  280. display: none;
  281. }
  282. .container {
  283. width: 100%;
  284. margin-left: 0;
  285. }
  286. }
  287. </style>

说明

  • 左侧菜单使用固定定位,不随屏幕的滚动而滚动,宽度为30%
  • 右侧内容区使用据左边距为30%来防止覆盖左侧菜单
  • a标签包含img元素,设置圆角时图片部分不响应,可对a标签设置overflow:hidden来解决
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议