Blogger Information
Blog 11
fans 0
comment 0
visits 5887
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
移动布局/grid布局
becauses
Original
778 people have browsed it

移动布局

  • 布局视图:网页的宽度
  • 视觉视图:移动设备看到的宽度
  • width=device-width[width:页面布局的宽度|device-width:视觉视图的宽度,设备宽度]
  • initial-scale=1.0[1:1还原视觉视图的布局]
  • 设计稿750px,DPR=2 device-width = 750px/DPR = 750/2 = 375px 以375布局
  • 下面计算rem
    1. html{
    2. font-size:calc(100vw / 3.75);
    3. }
    4. body {
    5. /* 还原浏览器字号 */
    6. font-size: 0.16rem;
    7. }

grid容器(网格布局)

父级设置

设置grid元素

  • display:grid;

    设置列数

  • grid-template-columns:10em 10em 10em;
  • grid-template-columns:repeat(3,1fr);<!-- repeat重复 fr 比例 -->

    设置行数

  • grid-template-rows:10em 10em 10em;

    设置间距

  • gap:行间距 列间距

    对齐(整个容器居中)

  • place-content:垂直方向 水平方向;

    单元格对齐

  • place-items:垂直方向 水平方向;

    隐式网格:超出网格的项目

    设置隐式网格排列方式[row横排列|column纵排列]

  • grid-auto-flow:column|row;

    设置隐式网格纵排列大小

  • grid-auto-columns:10em;

    设置隐式网格横排列大小

  • grid-auto-rows:10em;

子级设置

网格区域(span 跨越几行)

  • grid-row:起始行/结束行;
  • grid-row:1/2;
  • grid-row:1 / span 2;//跨越两行
  • grid-column:起始列/结束列;
  • grid-column:1/2;
  • grid-column:1 / span 3;//跨越三列
    简写
  • grid-area:行开始/列开始/行结束/列结束;
  • grid-area:3 / 1 / 4 / 4 ;
  • grid-area:3 / 1 / span 1 / span 3 ;

    单独设置对齐模式

  • place-self:垂直方向 水平方向;

案例

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. :root{
  10. --color1:#9d9d9d;
  11. --color2:#ffffff;
  12. }
  13. * {
  14. padding:0;
  15. margin:0;
  16. box-sizing:border-box;
  17. }
  18. html{
  19. font-size:100px;
  20. }
  21. body{
  22. font-size:0.16rem;
  23. display:grid;
  24. grid-template-columns:1fr;
  25. grid-template-rows:minmax(calc(100vh - 0.4em - 2.5em),1fr) 2.5rem;
  26. place-content:center;
  27. }
  28. a{
  29. color: unset;
  30. text-decoration: none;
  31. }
  32. li{
  33. list-style: none;
  34. }
  35. .container{
  36. width:100%;
  37. max-width:1200px;
  38. margin:0 auto;
  39. }
  40. header{
  41. background-color: #222;
  42. border-color: #080808;
  43. position: fixed;
  44. width: 100vw;
  45. }
  46. /* 导航 */
  47. nav{
  48. display: flex;
  49. place-content: space-between;
  50. line-height: 0.4rem;
  51. }
  52. nav ul li{
  53. color:var(--color1);
  54. font-size:0.14rem;
  55. padding: 0 0.1rem;
  56. }
  57. nav ul:nth-of-type(1){
  58. display: flex;
  59. }
  60. nav ul:nth-of-type(1) li:nth-of-type(1){
  61. font-size:0.16rem;
  62. }
  63. .navbar{
  64. display: none;
  65. }
  66. /* 广告 */
  67. .banner{
  68. margin-top: 0.35rem;
  69. background: linear-gradient(45deg,#020031,#6d3353);
  70. padding: 1rem;
  71. text-align: center;
  72. }
  73. .banner div h1{
  74. color:var(--color2);
  75. font-size:1rem;
  76. }
  77. .banner div h2{
  78. color:var(--color2);
  79. font-size:0.3rem;
  80. font-weight: normal;
  81. }
  82. .banner div button{
  83. color:var(--color2);
  84. font-size:0.18rem;
  85. font-weight: normal;
  86. border-radius: 6px;
  87. border: 0;
  88. background-color: #337ab7;
  89. box-shadow: inset 0 -4px 0 #23527c;
  90. padding: 0.1rem 0.3rem 0.15rem;
  91. }
  92. .banner p{
  93. color:var(--color1);
  94. font-size:0.14rem;
  95. }
  96. .banner div :nth-last-child(n+2){
  97. margin:0.2rem 0 0.1rem 0;
  98. }
  99. /* 标题 */
  100. .section_title{
  101. display: grid;
  102. height: 1.1rem;
  103. grid-template-rows: repeat(2,1fr);
  104. grid-template-columns: 0.5fr repeat(2,1.5fr) 0.5fr;
  105. place-items: center;
  106. }
  107. .section_title h1{
  108. grid-row: 1;
  109. grid-column: 2 / span 2;
  110. font-size: 0.42rem;
  111. font-weight: normal;
  112. }
  113. .section_title h2{
  114. grid-row: 2;
  115. grid-column: 2 / span 2;
  116. font-size: 0.14rem;
  117. font-weight: normal;
  118. margin: 0.2rem 0 0.1rem;
  119. color:var(--color1);
  120. text-align:center;
  121. }
  122. .section_title hr{
  123. grid-row: 3;
  124. grid-column: 2 / span 2;
  125. width: 100%;
  126. border: 1px solid #eee;
  127. }
  128. .box{
  129. margin:0.5rem 0;
  130. }
  131. /* 内容 */
  132. .boxcontent{
  133. margin-top:0.2rem;
  134. }
  135. .boxcontent ul{
  136. display: grid;
  137. grid-template-columns: repeat(4,1fr);
  138. grid-template-rows: repeat(2,1fr);
  139. grid-auto-flow: row;
  140. gap: 0.3rem;
  141. }
  142. .boxcontent ul li{
  143. border: 1px solid #ddd;
  144. }
  145. .boxcontent ul li div:nth-of-type(1){
  146. height: 1.5rem;
  147. overflow: hidden;
  148. }
  149. .boxcontent ul li div:nth-of-type(1) img{
  150. width: 100%;
  151. height: auto;
  152. object-fit: cover;
  153. }
  154. .boxcontent ul li div:nth-of-type(2){
  155. text-align:center;
  156. display: grid;
  157. grid-template-rows: repeat(2,1fr);
  158. place-items:center;
  159. padding: 0.15rem;
  160. }
  161. .boxcontent ul li div:nth-of-type(2) h1{
  162. color:#337ab7;
  163. font-size:0.24rem;
  164. }
  165. .boxcontent ul li div:nth-of-type(2) p{
  166. color:var(--color1);
  167. font-size:0.14rem;
  168. }
  169. /* 底部 */
  170. footer{
  171. border-top:1px solid #ddd;
  172. }
  173. .foot{
  174. display: grid;
  175. grid-template-rows:2rem 0.5rem;
  176. }
  177. .foot .foot_box{
  178. border-bottom: 1px solid #ddd;
  179. padding: 0.3rem 0;
  180. display: grid;
  181. grid-template-columns: repeat(2,1fr);
  182. }
  183. .foot .foot_box .foot_logo img{
  184. height: 0.5rem;
  185. margin: 0.1rem 0;
  186. }
  187. .foot .foot_box .foot_logo p{
  188. color:var(--color1);
  189. font-size: 0.14rem;
  190. }
  191. .foot .foot_box .foot_nav{
  192. display: grid;
  193. grid-template-columns: repeat(4,1fr);
  194. }
  195. .foot .foot_box .foot_nav dl dt{
  196. margin: 0.1rem 0;
  197. }
  198. .foot .foot_box .foot_nav dl dd{
  199. color:var(--color1);
  200. font-size:0.14rem;
  201. }
  202. .foot .foot_copy{
  203. place-self: center;
  204. font-size: 0.14rem;
  205. color:var(--color1);
  206. }
  207. @media only screen and (max-width: 1200px) {
  208. section,footer{
  209. padding-left:0.15rem;
  210. padding-right:0.15rem;
  211. }
  212. }
  213. @media only screen and (max-width: 992px) {
  214. html{
  215. font-size:calc(100vw / 10);
  216. }
  217. nav{
  218. place-content: center;
  219. }
  220. nav ul:nth-of-type(2){
  221. display:none;
  222. }
  223. }
  224. @media only screen and (max-width: 768px) {
  225. html{
  226. font-size:calc(100vw / 8);
  227. }
  228. nav{
  229. display: block;
  230. line-height: 0.5rem;
  231. }
  232. nav ul:nth-of-type(1){
  233. display:none;
  234. }
  235. .navbar{
  236. display: flex;
  237. place-content: space-between;
  238. color:#9d9d9d;
  239. font-size:0.16rem;
  240. padding: 0 0.2rem;
  241. }
  242. .section_title{
  243. height:2rem;
  244. }
  245. .boxcontent ul li div:nth-of-type(2) h1{
  246. font-size:0.3rem;
  247. }
  248. .boxcontent ul {
  249. grid-template-columns: repeat(2,1fr);
  250. gap: 0.15rem;
  251. }
  252. .foot {
  253. grid-template-rows: 4rem 0.5rem;
  254. }
  255. .foot .foot_box .foot_logo{
  256. text-align: center;
  257. }
  258. .foot .foot_box{
  259. grid-template-columns: repeat(1,1fr);
  260. }
  261. .foot .foot_box .foot_nav {
  262. place-items: center;
  263. text-align: center;
  264. }
  265. }
  266. </style>
  267. </head>
  268. <body>
  269. <header>
  270. <div class="container">
  271. <nav>
  272. <div class="navbar">
  273. <div><a href="">Bootstrap中文网</a></div>
  274. <div><i>icon</i></div>
  275. </div>
  276. <ul>
  277. <li><a href="">Bootstrap中文网</a></li>
  278. <li><a href="">Bootstrap3中文文档</a></li>
  279. <li><a href="">Bootstrap4中文文档</a></li>
  280. <li><a href="">Sass 教程</a></li>
  281. <li><a href="">Less 教程</a></li>
  282. <li><a href="">jQuery API</a></li>
  283. <li><a href="">网站实例</a></li>
  284. </ul>
  285. <ul>
  286. <li><a href="">关于</a></li>
  287. </ul>
  288. </nav>
  289. </div>
  290. </header>
  291. <main>
  292. <section class="banner">
  293. <div class="container" >
  294. <h1>Bootstrap</h1>
  295. <h2>简洁、直观、强悍的前端开发框架,让web开发更迅速、简单。</h2>
  296. <button>Bootstrap3中文文档(v3.4.1)</button>
  297. <p>Bootstrap2中文文档(v2.3.2)</p>
  298. </div>
  299. </section>
  300. <section class="box" >
  301. <div class="container" >
  302. <div class="section_title" >
  303. <h1>Bootstrap相关优质项目推荐</h1>
  304. <h2>这些项目或者是对Bootstrap进行了有益的补充,或者是基于Bootstrap开发的</h2>
  305. <hr/>
  306. </div>
  307. <div class="boxcontent" >
  308. <ul>
  309. <li>
  310. <a>
  311. <div>
  312. <img src="https://picsum.photos/300/150" alt="">
  313. </div>
  314. <div>
  315. <h1>优站精选</h1></h1>
  316. <p> Bootstrap 网站实例</p>
  317. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  318. </div>
  319. </a>
  320. </li>
  321. <li>
  322. <a>
  323. <div>
  324. <img src="https://picsum.photos/300/150" alt="">
  325. </div>
  326. <div>
  327. <h1>优站精选</h1></h1>
  328. <p> Bootstrap 网站实例</p>
  329. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  330. </div>
  331. </a>
  332. </li>
  333. <li>
  334. <a>
  335. <div>
  336. <img src="https://picsum.photos/300/150" alt="">
  337. </div>
  338. <div>
  339. <h1>优站精选</h1></h1>
  340. <p> Bootstrap 网站实例</p>
  341. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  342. </div>
  343. </a>
  344. </li>
  345. <li>
  346. <a>
  347. <div>
  348. <img src="https://picsum.photos/300/150" alt="">
  349. </div>
  350. <div>
  351. <h1>优站精选</h1></h1>
  352. <p> Bootstrap 网站实例</p>
  353. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  354. </div>
  355. </a>
  356. </li>
  357. <li>
  358. <a>
  359. <div>
  360. <img src="https://picsum.photos/300/150" alt="">
  361. </div>
  362. <div>
  363. <h1>优站精选</h1></h1>
  364. <p> Bootstrap 网站实例</p>
  365. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  366. </div>
  367. </a>
  368. </li>
  369. <li>
  370. <a>
  371. <div>
  372. <img src="https://picsum.photos/300/150" alt="">
  373. </div>
  374. <div>
  375. <h1>优站精选</h1></h1>
  376. <p> Bootstrap 网站实例</p>
  377. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  378. </div>
  379. </a>
  380. </li>
  381. <li>
  382. <a>
  383. <div>
  384. <img src="https://picsum.photos/300/150" alt="">
  385. </div>
  386. <div>
  387. <h1>优站精选</h1></h1>
  388. <p> Bootstrap 网站实例</p>
  389. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  390. </div>
  391. </a>
  392. </li>
  393. <li>
  394. <a>
  395. <div>
  396. <img src="https://picsum.photos/300/150" alt="">
  397. </div>
  398. <div>
  399. <h1>优站精选</h1></h1>
  400. <p> Bootstrap 网站实例</p>
  401. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  402. </div>
  403. </a>
  404. </li>
  405. <li>
  406. <a>
  407. <div>
  408. <img src="https://picsum.photos/300/150" alt="">
  409. </div>
  410. <div>
  411. <h1>优站精选</h1></h1>
  412. <p> Bootstrap 网站实例</p>
  413. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  414. </div>
  415. </a>
  416. </li>
  417. <li>
  418. <a>
  419. <div>
  420. <img src="https://picsum.photos/300/150" alt="">
  421. </div>
  422. <div>
  423. <h1>优站精选</h1></h1>
  424. <p> Bootstrap 网站实例</p>
  425. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  426. </div>
  427. </a>
  428. </li>
  429. <li>
  430. <a>
  431. <div>
  432. <img src="https://picsum.photos/300/150" alt="">
  433. </div>
  434. <div>
  435. <h1>优站精选</h1></h1>
  436. <p> Bootstrap 网站实例</p>
  437. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  438. </div>
  439. </a>
  440. </li>
  441. <li>
  442. <a>
  443. <div>
  444. <img src="https://picsum.photos/300/150" alt="">
  445. </div>
  446. <div>
  447. <h1>优站精选</h1></h1>
  448. <p> Bootstrap 网站实例</p>
  449. <p>Bootstrap 优站精选频道收集了众多基于 Bootstrap 构建、设计精美的、有创意的网站。</p>
  450. </div>
  451. </a>
  452. </li>
  453. </ul>
  454. </div>
  455. </div>
  456. </section>
  457. </main>
  458. <footer>
  459. <div class="container">
  460. <div class="foot">
  461. <div class="foot_box" >
  462. <div class="foot_logo" >
  463. <img src="https://picsum.photos/250/50" alt="">
  464. <p>我们一直致力于为广大开发者提供更多的优质技术文档和辅助开发工具!</p>
  465. </div>
  466. <div class="foot_nav">
  467. <dl>
  468. <dt>关于</dt>
  469. <dd>关于我们</dd>
  470. <dd>广告合作</dd>
  471. <dd>友情链接</dd>
  472. <dd>招聘信息</dd>
  473. </dl>
  474. <dl>
  475. <dt>关于</dt>
  476. <dd>关于我们</dd>
  477. <dd>广告合作</dd>
  478. <dd>友情链接</dd>
  479. <dd>招聘信息</dd>
  480. </dl>
  481. <dl>
  482. <dt>关于</dt>
  483. <dd>关于我们</dd>
  484. <dd>广告合作</dd>
  485. <dd>友情链接</dd>
  486. <dd>招聘信息</dd>
  487. </dl>
  488. <dl>
  489. <dt>关于</dt>
  490. <dd>关于我们</dd>
  491. <dd>广告合作</dd>
  492. <dd>友情链接</dd>
  493. <dd>招聘信息</dd>
  494. </dl>
  495. </div>
  496. </div>
  497. <div class="foot_copy">
  498. <p>版权xxx所有备案号xxx</p>
  499. </div>
  500. </div>
  501. </div>
  502. </footer>
  503. </body>
  504. </html>


Correcting teacher:PHPzPHPz

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