Blogger Information
Blog 62
fans 2
comment 1
visits 42270
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
11 阶段性实战学习:网站首页框架
老黑
Original
689 people have browsed it

主要内容:

1-建立一个css文件,通过class的方式将有可能用到的所有flex设置都放到里面。这样就不用再为每个类去写flex设置了。
2-header、聚焦图等里面有很多好玩的地方,当然也是要动心思的地方,见下面吧。


1、flex的通用设置文件

例如下面这种,而且在class取名方面就想好。这样的话,后面要用的时候直接取就好了。

这种情况类似于将flex所有的设置通过.class变成了属性的选项。只要在搭建的时候给对应的元素赋予对应的.class名称,那么这个元素就具有了对应的flex特征。是一种很巧妙的方法。

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. html,
  7. body {
  8. width: 100%;
  9. height: 100%;
  10. overflow: hidden;
  11. overflow-y: auto;
  12. }
  13. {
  14. transition: all 200ms ease;
  15. }
  16. @font-face {
  17. font-family: icon;
  18. src: url("../fonts/icon.ttf") format("truetype"),
  19. url("../fonts/icon.eot") format("embedded-opentype"),
  20. url("../fonts/icon.woff") format("woff"),
  21. url("../fonts/icon.svg") format("svg");
  22. }
  23. a {
  24. color: #444;
  25. text-decoration: none;
  26. }
  27. li,
  28. dd {
  29. list-style: none;
  30. }
  31. button,
  32. img {
  33. border: none;
  34. outline: none;
  35. }
  36. .contrain {
  37. width: 1200px;
  38. margin: 0 auto;
  39. }
  40. .flexDis {
  41. display: -webkit-flex;
  42. display: -moz-flex;
  43. display: -o-flex;
  44. display: -ms-flexbox;
  45. display: flex;
  46. }
  47. .applyFlex {
  48. flex-grow: 1;
  49. }
  50. .flexShrinkStatic {
  51. flex-shrink: 0;
  52. }
  53. .flexShrinkAuto {
  54. flex-shrink: 1;
  55. }
  56. .flexDirV {
  57. flex-direction: column;
  58. }
  59. .flexDirH {
  60. flex-direction: row;
  61. }
  62. .flexWrap {
  63. flex-wrap: wrap;
  64. }
  65. .flexNoWrap {
  66. flex-wrap: nowrap;
  67. }
  68. .flexContentS {
  69. justify-content: flex-start;
  70. }
  71. .flexContentC {
  72. justify-content: center;
  73. }
  74. .flexContentE {
  75. justify-content: flex-end;
  76. }
  77. .flexContentV {
  78. justify-content: space-evenly;
  79. }
  80. .flexContentA {
  81. justify-content: space-around;
  82. }
  83. .flexContentB {
  84. justify-content: space-between;
  85. }
  86. .flexAlignS {
  87. align-items: flex-start;
  88. }
  89. .flexAlignC {
  90. align-items: center;
  91. }
  92. .flexAlignE {
  93. align-items: flex-end;
  94. }
  95. .flexAlignB {
  96. align-items: baseline;
  97. }
  98. .flexAlignT {
  99. align-items: stretch;
  100. }

2、header的解析

  1. <header id="mainHeader" class="flexDis"> <!--这个地方直接设置flexdis就实现了flex效果-->
  2. <div>LOGO</div>
  3. <ul>
  4. <li><a href="#">导航1</a></li>
  5. <li><a href="#">导航2</a></li>
  6. <li><a href="#">导航3</a></li>
  7. <li><a href="#">导航4</a></li>
  8. </ul>
  9. <div class="searchInfo">
  10. <input type="text" placeholder="请输入关键字" value="" /><a
  11. href="#"
  12. ></a>
  13. </div>
  14. <p><a href="#">登录</a><a href="#">注册</a></p>
  15. </header>
  • 每块用相对独立的块区分开。
  • 菜单直接用ul li。
  • 搜索用一个input+a。
  • 登录、注销用一个p中间加两个a。

css部分:

  1. #mainHeader {
  2. background: white;
  3. padding: 1.5em;
  4. box-shadow: 0 0.2em 0.4em rgba(0, 0, 0, 0.2);
  5. }
  6. #mainHeader ul {
  7. padding: 0 1em;
  8. }
  9. #mainHeader ul li {
  10. display: inline-block;/*这个是让li水平显示*/
  11. padding: 0 0.8em;
  12. }
  13. #mainHeader ul li a {
  14. color: #38e;
  15. }
  16. #mainHeader ul li a:hover {
  17. color: black;
  18. }
  19. #mainHeader .searchInfo {
  20. padding: 0 1em;
  21. }
  22. #mainHeader .searchInfo a {
  23. vertical-align: middle;
  24. background: #38e;/*这个地方是一个搜索icon一样的,设置了背景色。具体内容则是由下面的伪元素来占据*/
  25. padding: 0.3em 0.6em;
  26. color: white;
  27. }
  28. #mainHeader .searchInfo a::after {
  29. content: "\f001";/*添加伪元素*/
  30. font-family: icon;
  31. }
  32. #mainHeader .searchInfo input {
  33. border: solid 1px silver;
  34. padding: 0.5em;
  35. outline: none;
  36. vertical-align: middle;
  37. border-radius: 0.3em 0 0 0.3em;
  38. }
  39. #mainHeader > p {
  40. margin-left: auto;
  41. }
  42. /*p"登录、注销"通过margin-left自动放大来实现向最右侧的靠齐*/
  43. #mainHeader > p a {
  44. color: #38e;
  45. margin: 0 0.6em;
  46. }

3、焦点图部分focus area的解析

  1. <section class="contrain secCon1 flexDis">
  2. <ul>
  3. <li><a href="#">列表1</a></li>
  4. <li><a href="#">列表2</a></li>
  5. <li><a href="#">列表3</a></li>
  6. <li><a href="#">列表4</a></li>
  7. <li><a href="#">列表5</a></li>
  8. <li><a href="#">列表6</a></li>
  9. <li><a href="#">列表7</a></li>
  10. </ul>
  11. <div class="preview applyFlex">
  12. <p><a href="#"></a><a href="#"></a></p>
  13. <!--这里用两个box旋转(后面会看到)来形成向左、向右的两个箭头——旋转并只加两个变的border。见下图-->
  14. <div class="applyFlex">
  15. <img src="./images/1.jpg" alt="" />
  16. <img src="./images/2.jpg" alt="" />
  17. <img src="./images/3.jpg" alt="" />
  18. <img src="./images/4.jpg" alt="" />
  19. </div>
  20. <div class="controler">
  21. <span></span><span></span>
  22. <span></span><span></span>
  23. /*通过span实现右下角的小点*/
  24. </div>
  25. </div>
  26. </section>

css部分:

  1. .secCon1 {
  2. height: 480px;
  3. margin: 1em auto;
  4. }
  5. /* ① 左侧的几个列表部分*/
  6. .secCon1 ul {
  7. width: 200px;
  8. background: gray;
  9. }
  10. .secCon1 ul li {
  11. background: gray;
  12. }
  13. .secCon1 ul li a {
  14. display: block;
  15. /*上面这个还挺关键的,没有的话就无法让a像块(block)一样地去操作*/
  16. color: white;
  17. padding: 1em 1.5em;
  18. }
  19. .secCon1 ul li a:hover {
  20. background: rgba(255, 255, 255, 0.2);
  21. }
  22. .secCon1 .preview {
  23. position: relative;
  24. height: 100%;
  25. }
  26. /* ② 下面为焦点图部分*/
  27. .secCon1 .preview .applyFlex {
  28. position: relative;
  29. height: 100%;
  30. }
  31. .secCon1 .preview img {
  32. position: absolute;
  33. display: block; /*重点*/
  34. left: 0;
  35. top: 0;
  36. width: 100%;
  37. height: 100%;
  38. object-fit: cover; /*重点*/
  39. }
  40. /* ③ 两个箭头的地方*/
  41. .secCon1 .preview p {
  42. position: absolute;
  43. width: 100%;
  44. top: 50%;
  45. left: 0;
  46. z-index: 1;/*这个还不知道是干什么的*/
  47. }
  48. .secCon1 .preview p a {
  49. position: absolute;
  50. width: 30px;
  51. height: 30px;
  52. }
  53. .secCon1 .preview p a:first-of-type {
  54. border: solid 2px white;
  55. border-style: solid none none solid;
  56. transform: rotate(-45deg); /*旋转*/
  57. left: 1em;
  58. }
  59. .secCon1 .preview p a:last-of-type {
  60. border: solid 2px white;
  61. border-style: none solid solid none;
  62. transform: rotate(-45deg);
  63. right: 1em;
  64. }
  65. /* ④ 下面四个小控制点*/
  66. .secCon1 .controler {
  67. position: absolute;
  68. right: 1em;
  69. bottom: 1em;
  70. }
  71. .secCon1 .controler span {
  72. display: inline-block;/*重点*/
  73. width: 9px;
  74. height: 9px;
  75. background: white;
  76. border-radius: 1em;
  77. margin: 0 1em;
  78. cursor: pointer;
  79. opacity: 0.5;/*透明度*/
  80. }
  81. .secCon1 .controler span:hover {
  82. opacity: 1;
  83. }

4、某度假景点网站照猫画虎

臭了点,主要是为了练习。

代码如下:
html部分:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <link rel="stylesheet" href="css/header.css">
  7. <link rel="stylesheet" href="myicon/iconfont.css">
  8. <title>Document</title>
  9. </head>
  10. <body>
  11. <section class = "h1">
  12. <a class = "h1-itms" href="">浏览Disney.cn</a>
  13. <div>
  14. <a class = "h1-itms" href="">登陆或创建账号</a>
  15. <a class = "h1-itms" href="">简体中文 (Simplified Chinese)</a>
  16. <input class = "h1-itms" type="text">
  17. </div>
  18. </section>
  19. <section class = "h2">
  20. <a href="" class="h2-itms">
  21. <img src="img/logo.png" alt="">
  22. </a>
  23. <a href="" class="h2-itms">乐园门票与年卡</a>
  24. <a href="" class="h2-itms">住宿体验</a>
  25. <a href="" class="h2-itms">活动一览</a>
  26. <a href="" class="h2-itms">年卡</a>
  27. <a href="" class="h2-itms">旅行信息</a>
  28. <a href="" class="h2-itms">须知及帮助</a>
  29. </section>
  30. <section class = "slide">
  31. <img src="img/slide1.png" alt="" class="slide-img">
  32. <img src="" alt="" class="slide-img">
  33. </section>
  34. <section class = "focus">
  35. <div class="focus-itms">
  36. <a href="" class="focus-eles">
  37. <img src="img/prom1.png" alt="">
  38. </a>
  39. <div>
  40. <a href="" class="focus-eles">立即购买</a>
  41. <a href="" class="focus-eles">主题乐园门票</a>
  42. <span class="iconfont icon-taiyang-shuishang"></span>
  43. </div>
  44. </div>
  45. <div class="focus-itms">
  46. <a href="" class="focus-eles">
  47. <img src="img/prom2.png" alt="">
  48. </a>
  49. <div>
  50. <a href="" class="focus-eles">立即购买</a>
  51. <a href="" class="focus-eles">主题乐园门票</a>
  52. <span class="iconfont icon-taiyang-shuishang"></span>
  53. </div>
  54. </div>
  55. <div class="focus-itms">
  56. <a href="" class="focus-eles">
  57. <img src="img/prom3.png" alt="">
  58. </a>
  59. <div>
  60. <a href="" class="focus-eles">立即购买</a>
  61. <a href="" class="focus-eles">主题乐园门票</a>
  62. <span class="iconfont icon-taiyang-shuishang"></span>
  63. </div>
  64. </div>
  65. </section>
  66. <section class = "links1">
  67. </section>
  68. <section class = "links2">
  69. </section>
  70. <section class = "links3">
  71. </section>
  72. <section class = "footer">
  73. </section>
  74. </body>
  75. </html>

css部分:

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. :root {
  7. font-size: 14px;
  8. background-color: #d3d3d3;
  9. }
  10. a {
  11. text-decoration: none;
  12. }
  13. body {
  14. width: 85vw;
  15. min-height: 100vh;
  16. border: 1px solid black;
  17. margin: 5px auto;
  18. }
  19. .h1 {
  20. height: 35px;
  21. line-height: 35px;
  22. display: flex;
  23. justify-content: space-between;
  24. }
  25. .h1 > .h1-itms {
  26. margin: 2px 10px;
  27. }
  28. .h2 {
  29. height: 60px;
  30. line-height: 60px;
  31. display: flex;
  32. }
  33. .h2 > .h2-itms:not(:first-of-type ) {
  34. margin: 0 15px;
  35. }
  36. .h2 > .h2-itms:first-of-type > img {
  37. height: 60px;
  38. }
  39. .slide {
  40. display: flex;
  41. flex: row nowrap;
  42. justify-content: center;
  43. height: 450px;
  44. }
  45. .slide > img {
  46. width: 200vw;
  47. }
  48. .focus {
  49. display: flex;
  50. flex: row nowrap;
  51. justify-content: space-around;
  52. height: 150px;
  53. }
  54. .focus > .focus-itms {
  55. display: flex;
  56. align-items: center;
  57. }
  58. .focus > .focus-itms > .focus-eles > img {
  59. height: 140px;
  60. }
  61. .focus > .focus-itms > div {
  62. display: flex;
  63. flex-flow: column nowrap;
  64. }
  65. .focus-eles {
  66. margin: 5px 5px;
  67. }
  68. .iconfont {
  69. font-size: larger;
  70. color: yellowgreen;
  71. text-align: right;
  72. }
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