用flex做一个简单的border布局

 

A君有阵子没写前端代码了 今天看了下flex layout 觉得真的很方便 以前要js解决的 几行配置就可以搞定了!

 

上代码 

<html>

<head>

    <meta charset="utf-8">
    <meta name="google" value="notranslate">
    <style>
        .hbox {
            display: flex;
        }
        
        .vbox {
            display: flex;
            flex-direction: column;
        }
        
        * {
            box-sizing: border-box;
        }

        
    </style>
</head>

<body style="background: rgb(255, 255, 255);">

    <div style="display: flex; height: 100%;">
        <div style="width: 100px;background: coral;height: 100%;"></div>
        <div class="vbox" style="
            flex-grow: 1;
            height: 100%;
            background: beige;
            
            ">
            <div style="
                height: 100px;
                border: 5px solid darkgray;
            "></div>
            <div style="
                border: 5px solid cadetblue;
                flex-grow: 1;
            "></div>


        </div>
    </div>






</body>

</html>

 

 

大功告成~~

 


 

好的,下面是一个简单的网页设计示例,使用flex布局: HTML: ``` <!DOCTYPE html> <html> <head> <title>Flex布局示例</title> <style> body { margin: 0; padding: 0; } header { background-color: #333; color: #fff; height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; } nav { background-color: #555; color: #fff; height: calc(100vh - 60px); width: 200px; display: flex; flex-direction: column; justify-content: center; align-items: center; } main { background-color: #eee; height: calc(100vh - 60px); display: flex; flex-wrap: wrap; padding: 20px; } .box { background-color: #fff; border: 1px solid #ccc; border-radius: 5px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1); width: calc(33.33% - 20px); margin: 10px; padding: 20px; display: flex; flex-direction: column; justify-content: center; align-items: center; } footer { background-color: #333; color: #fff; height: 60px; display: flex; justify-content: center; align-items: center; } </style> </head> <body> <header> <h1>Flex布局示例</h1> <nav> <ul> <li><a href="#">链接1</a></li> <li><a href="#">链接2</a></li> <li><a href="#">链接3</a></li> </ul> </nav> </header> <main> <div class="box"> <h2>盒子1</h2> <p>这是一段文字。</p> <button>按钮</button> </div> <div class="box"> <h2>盒子2</h2> <p>这是一段文字。</p> <button>按钮</button> </div> <div class="box"> <h2>盒子3</h2> <p>这是一段文字。</p> <button>按钮</button> </div> <div class="box"> <h2>盒子4</h2> <p>这是一段文字。</p> <button>按钮</button> </div> <div class="box"> <h2>盒子5</h2> <p>这是一段文字。</p> <button>按钮</button> </div> <div class="box"> <h2>盒子6</h2> <p>这是一段文字。</p> <button>按钮</button> </div> </main> <footer> <p>版权所有 © 2021</p> </footer> </body> </html> ``` CSS: ``` body { margin: 0; padding: 0; } header { background-color: #333; color: #fff; height: 60px; display: flex; justify-content: space-between; align-items: center; padding: 0 20px; } nav { background-color: #555; color: #fff; height: calc(100vh - 60px); width: 200px; display: flex; flex-direction: column; justify-content: center; align-items: center; } main { background-color: #eee; height: calc(100vh - 60px); display: flex; flex-wrap: wrap; padding: 20px; } .box { background-color: #fff; border: 1px solid #ccc; border-radius: 5px; box-shadow: 2px 2px 5px rgba(0,0,0,0.1); width: calc(33.33% - 20px); margin: 10px; padding: 20px; display: flex; flex-direction: column; justify-content: center; align-items: center; } footer { background-color: #333; color: #fff; height: 60px; display: flex; justify-content: center; align-items: center; } ``` 该示例包含一个顶部导航栏,一个侧边栏,一个主内容区域和一个底部页脚。主内容区域包含了6个盒子,使用了flex布局来实现等分排列。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值