Blogger Information
Blog 64
fans 6
comment 2
visits 82999
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CSS弹性布局flex布局
王娇
Original
882 people have browsed it

演示链接

http://www.xuanransoftware.com/phpStudy/0409/

课程总结

  • 弹性布局和盒模型是完美搭配可以使所有元素和元素框放在自己想要的位置
  • 注意弹性布局的容器属性和项目属性有时候受限于容器的width属性

CSS弹性布局flex布局的属性演示

1.display属性演示

  • 把页面的头部设置为弹性布局,头部包含网页图标和导航栏
  • css示例代码
  1. header {
  2. width: 920px;
  3. height: 65px;
  4. background-color: lightseagreen;
  5. margin-left: auto;
  6. margin-right: auto;
  7. display: flex;
  8. box-sizing: border-box;
  9. }
  • html示例代码
  1. <header>
  2. <!-- 页面导航 -->
  3. <img src="images/logo.jpg" width="100" height="50" />
  4. <nav>
  5. <ul>
  6. <li>
  7. <a href="mainIndex.html" target="mainFrame">首页</a>
  8. <a href="formTable.html" target="mainFrame">用户注册</a>
  9. <a href="table.html" target="mainFrame">表格</a>
  10. <a href="listTable.html" target="mainFrame">列表</a>
  11. </li>
  12. </ul>
  13. </nav>
  14. </header>
  • 效果图

2.justify-content属性演示

  • 把页面的头部的项目在水平方向两端对齐
  • css示例代码
  1. header {
  2. width: 920px;
  3. height: 65px;
  4. background-color: lightseagreen;
  5. margin-left: auto;
  6. margin-right: auto;
  7. display: flex;
  8. justify-content: space-between;
  9. box-sizing: border-box;
  10. }
  • 效果图

3.align-item属性演示

  • 把页面的头部的项目在垂直方向居中对齐
  • css示例代码
  1. header {
  2. width: 920px;
  3. height: 65px;
  4. background-color: lightseagreen;
  5. margin-left: auto;
  6. margin-right: auto;
  7. display: flex;
  8. justify-content: space-between;
  9. align-items: center;
  10. box-sizing: border-box;
  11. }
  • 效果图

3.flex-flowalign-content 属性演示

  • 页面导航菜单过多换行显示,多行显示后设置交叉轴的对齐方式为向起始线对齐
  • css示例代码
  1. nav {
  2. width: 600px;
  3. box-sizing: border-box;
  4. }
  5. nav div {
  6. display: flex;
  7. flex-flow: row wrap;
  8. align-items: center;
  9. align-content: flex-start;
  10. }
  11. nav div a {
  12. text-decoration: none;
  13. padding: 2px 15px;
  14. }
  15. nav div a:link {
  16. color: white;
  17. }
  18. nav div a:visited {
  19. color: blueviolet;
  20. }
  21. nav div a:hover {
  22. color: tomato;
  23. }
  • html示例代码
  1. <header>
  2. <!-- 页面导航 -->
  3. <img src="images/logo.png" width="220" height="56" />
  4. <nav>
  5. <div>
  6. <a href="index.php">首 页</a>
  7. <a href="invitejob.php">招聘信息</a>
  8. <a href="foster.php">培训信息</a>
  9. <a href="house.php">房屋信息</a>
  10. <a href="seekbuy.php">求购信息</a>
  11. <a href="seekjob.php">求职信息</a>
  12. <a href="teaching.php">家教信息</a>
  13. <a href="car.php">车辆信息</a>
  14. <a href="sale.php">出 售信息</a>
  15. <a href="recruitbusiness.php">招商引资</a>
  16. <a href="search.php">寻物启示</a>
  17. </div>
  18. </nav>
  19. </header>
  • 效果图

3.align-self 属性演示

  • 页面导航菜单居中显示并且添加背景图片
  • css示例代码
  1. header {
  2. width: 920px;
  3. height: 56px;
  4. margin-left: auto;
  5. margin-right: auto;
  6. display: flex;
  7. justify-content: space-between;
  8. background-color: tomato;
  9. align-items: center;
  10. box-sizing: border-box;
  11. }
  12. nav {
  13. background-image: url(../images/menu.png);
  14. height: 56px;
  15. align-self: flex-start;
  16. display: flex;
  17. }
  18. nav div {
  19. align-self: center;
  20. display: flex;
  21. flex-flow: row wrap;
  22. align-items: center;
  23. align-content: flex-start;
  24. }
  25. nav div a {
  26. text-decoration: none;
  27. padding: 2px 15px;
  28. }
  • html示例代码
  1. <header>
  2. <!-- 页面导航 -->
  3. <img src="images/logo.png" width="220" height="56" />
  4. <nav>
  5. <div>
  6. <a href="index.php">首 页</a>
  7. <a href="invitejob.php">招聘信息</a>
  8. <a href="foster.php">培训信息</a>
  9. <a href="house.php">房屋信息</a>
  10. <a href="seekbuy.php">求购信息</a>
  11. <a href="seekjob.php">求职信息</a>
  12. <a href="teaching.php">家教信息</a>
  13. <a href="car.php">车辆信息</a>
  14. <a href="sale.php">出 售信息</a>
  15. <a href="recruitbusiness.php">招商引资</a>
  16. <a href="search.php">寻物启示</a>
  17. </div>
  18. </nav>
  19. </header>
  • 效果图

4.项目flex 属性演示

  • 页面侧边栏缩放显示
  • css示例代码
  1. aside {
  2. width: 220px;
  3. height: 500px;
  4. display: flex;
  5. flex-flow: column nowrap;
  6. box-sizing: border-box;
  7. }
  8. aside > section {
  9. flex: 1 1 auto;
  10. }
  11. aside > section:first-of-type {
  12. background-color: tomato;
  13. }
  14. aside > section:nth-of-type(2) {
  15. background-color: yellow;
  16. }
  17. aside > section:last-of-type {
  18. background-color: turquoise;
  19. }
  20. aside > section > ul > li {
  21. list-style-type: none;
  22. margin-top: 5px;
  23. padding: 2px;
  24. }
  • html示例代码
  1. <aside>
  2. <section>
  3. <label for="" class="iconfont"> 新闻资讯</label>
  4. </section>
  5. <section>
  6. <label for="" class="iconfont"> 搜索内容</label>
  7. </section>
  8. <section>
  9. <label for="" class="iconfont"> 联系我们</label>
  10. <ul>
  11. <li>名称:北京瑄然软件</li>
  12. <li>地址:北京顺义区...</li>
  13. <li>电话:<a href="tel:15010046927">1501004xxxx</a></li>
  14. <li>
  15. 邮箱:<a href="mailto:573661083@qq.com">5736610xx@qq.com</a>
  16. </li>
  17. </ul>
  18. </section>
  • 效果图
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