百分百源码网-让建站变得如此简单! 登录 注册 签到领金币!

主页 | 如何升级VIP | TAG标签

当前位置: 主页>网站教程>CSS教程> CSS弹性盒模型flex在布局中的运用办法
分享文章到:

CSS弹性盒模型flex在布局中的运用办法

发布时间:09/01 来源:未知 浏览: 关键词:

CSS弹性盒模型flex在规划中的利用

元素居中

【1】伸缩容器上使用主轴对齐justify-content和侧轴对齐align-items

<style>.parent{
    display: flex;
    justify-content: center;
    align-items: center;}</style>
<div class="parent"  style="background-color: lightgrey; height: 100px; width: 200px;">
    <div class="in" style="background-color: lightblue;">DEMO</div>      </div>

【2】在伸缩项目上使用margin:auto

<style>.parent{
    display: flex;}.in{
    margin: auto;}</style>
<div class="parent"  style="background-color: lightgrey;height: 100px;width: 200px;">
    <div class="in" style="background-color: lightblue;">DEMO</div>      </div>

两端对齐

<style>.parent{
   display: flex;    
   justify-content:space-between
   }
</style>
<div class="parent"  style="background-color: lightgrey;height: 100px;width: 200px;">
    <div class="in" style="background-color: lightblue;">DEMO</div>
    <div class="in" style="background-color: lightgreen;">DEMO</div>
    <div class="in" style="background-color: lightcyan;">DEMO</div>    
    <div class="in" style="background-color: lightseagreen;">DEMO</div>     
 </div>

底端对齐

<style>.parent{
    display: flex;
    align-items: flex-end;
    }
</style>
<div class="parent"  style="background-color: lightgrey;height: 100px;width: 200px;">
    <div class="in" style="background-color: lightblue; height:20px;">DEMO</div>
    <div class="in" style="background-color: lightgreen; height:30px;">DEMO</div>
    <div class="in" style="background-color: lightcyan; height:40px;">DEMO</div>
    <div class="in" style="background-color: lightseagreen; height:50px;">DEMO</div>      
</div>

输入框按钮

<style>.inputBox{
    display: flex;
    width: 250px;}.inputBox-ipt{
    flex: 1;}
</style>
<div class="inputBox">
  <input class="inputBox-ipt">
  <button class="inputBox-btn">按钮</button>
</div>

等分规划

<style>body,p{margin: 0;}.parent{
    display: flex;}.child{
    flex:1;
    height: 100px;}.child + .child{
    margin-left: 20px;}
</style>
<div class="parent" style="background-color: lightgrey;">
    <div class="child" style="background-color: lightblue;">1</div>
    <div class="child" style="background-color: lightgreen;">2</div>
    <div class="child" style="background-color: lightsalmon;">3</div>
    <div class="child" style="background-color: pink;">4</div>                
</div>

多列自顺应规划

<style>p{margin: 0;}.parent{display: flex;}.left,.center{margin-right: 20px;}.right{flex: 1;}</style>
<div class="parent" style="background-color: lightgrey;">
    <div class="left" style="background-color: lightblue;">
        <p>left</p>
        <p>left</p>
    </div>            
    <div class="center" style="background-color: pink;">
        <p>center</p>
        <p>center</p>
    </div>            
    <div class="right"  style="background-color: lightgreen;">
        <p>right</p>
        <p>right</p>
    </div>                    
</div>

吊挂规划

<style>        
     .box{
    display: flex;
    background-color: lightgrey;
    width: 300px;}.left{
    margin-right: 20px;
    background-color: lightblue;
    height: 30px;}.main{
    flex:1;}
 </style>
<div class="box">
    <div class="left">左侧吊挂</div>
    <div class="main">主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容</div>    
</div>

全屏规划

<style>body,p{margin: 0;}body,html,.parent{height: 100%;}.parent{
    display: flex;
    flex-direction: column;}.top,.bottom{
    height: 50px;}.middle{
    display: flex;
    flex: 1;}.left{
    width: 100px;
    margin-right: 20px;}.right{
    flex: 1;
    overflow: auto;}.right-in{
    height: 1000px;}</style>
<div class="parent" id="parent" style="background-color: lightgrey;">
    <div class="top" style="background-color: lightblue;">
        <p>top</p>
    </div> 
    <div class="middle" style="background-color: pink;">
        <div class="left" style="background-color: orange;">
            <p>left</p>
        </div>     
        <div class="right" style="background-color: lightsalmon;">
            <div class="right-in">
                <p>right</p>
            </div>            
        </div>                    
    </div>              
    <div class="bottom" style="background-color: lightgreen;">
        <p>bottom</p>
    </div>        
</div>

以上就是CSS弹性盒模型flex在规划中的利用的全部内容。

相关参照 :百分百源码网

以上就是CSS弹性盒模型flex在规划中的使用办法的具体内容,更多请关注百分百源码网其它相关文章!

打赏

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

百分百源码网 建议打赏1~10元,土豪随意,感谢您的阅读!

共有152人阅读,期待你的评论!发表评论
昵称: 网址: 验证码: 点击我更换图片
最新评论

本文标签

广告赞助

能出一分力是一分吧!

订阅获得更多模板

本文标签

广告赞助

订阅获得更多模板