5.7 弹性盒子

本文详细介绍了CSS中的弹性盒子布局模型,包括如何定义弹性盒子、子元素的排列方式、换行方式及对齐方式等关键属性。并通过具体示例展示了如何使用这些属性来实现灵活的页面布局。

弹性盒子
定义弹性盒子 display:flex
定义子元素排列方式 flex-diection
定义子元素换行方式 flxe-wrap
定义子元素对齐方式
横向对齐 justify-content
纵向对齐 align-items

 

媒体查询    @media screen and (max-width:最大宽度)and (min-width:最小宽度)
line-height与vertical-align
line-height 主要作为调节文本的垂直对齐方式,通过设置行高的大小
vertical-align 主要作为调节行内元素(span/img)的垂直对齐方式 top bottom middle text-top text-bottom

!DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title></title>
  <style type="text/css">
   #parent{
    width:800px;
    height: 400px;
    border:1px solid black;
    /*定义父元素为弹性盒子*/
    display:flex;
    /*规定子元素的排列方式*/
    flex-direction: row-reverse;
    /*规定换行方式*/
    flex-wrap: nowrap;
    /*子元素在父元素的横向对齐方式*/
    justify-content: space-between;
    /*子元素在父元素的纵向对齐方式*/
    align-items:stretch ;
    }
    .children{
     width :170px;
     height: 180px;
     border: 1px solid red;
     float:left ;
     flex: 1;
     align-self: flex-start;
    }
    .children1{border: 1px solid red;
    flex:3;
    order: 0;}
  </style>
 </head>
 <body>
  <div id="parent">
  <div class="children">1</div>
  <div class="children">2</div>
  <div class="children">3</div>
  <div class="children">4</div>
  <div class="children">5</div>
  <div class="children">6</div>
  <div class="children1">7</div>
  <div class="children">8</div>
  
  </div>
  
  
  
  
 </body>
</html>

 

转载于:https://www.cnblogs.com/sunhao1987/p/9004054.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值