css - display:flex;布局问题
PHP中文网
PHP中文网 2017-04-17 13:49:00
[HTML讨论组]

下图的布局方式有哪几种?还有没有其他的:
1、左右布局
2、左中右布局

下面代码这种可以实现吗?都在一个盒子里面

PHP中文网
PHP中文网

认证0级讲师

全部回复(4)
PHPz

可以是可以,但这是竖着排的,按着顺序横着排可能有点问题,而且是写死的...

    ul{
        display: flex;
        list-style: none;
        width: 180px;
        height: 60px;
        flex-direction: column;
        flex-wrap:wrap;
    }
    li{
        display: inline-block;
        height: 30px;
        border: 1px solid red;
    }
    li:first-of-type{
        height: 60px;
    }
PHPz

谢邀!
可以的,首先让所有的li,float:left;,同时在写一个css伪类li:first-chlid让其高度改变,改成其他元素的1倍,这样就可以解决你的问题了。
demo

天蓬老师
ul {
    display: flex;
    flex-flow: column wrap;
    align-content: flex-start;
    align-items: flex-start;
    height: 60px;
    padding: 0;
    list-style-type: none;
}
li {
    width: 100px;
    margin: 0 0 1px 1px;
    font: 14px/30px "Microsoft Yahei";
    text-align: center;
    color: #fff;
    background: rgb(255, 105, 122);
}
li:first-child {
    line-height: 62px;
}
怪我咯
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="../css.css">
    <style>
    #box
    {
    display:flex;
    
    margin:20px;
    width:330px;
    background:#FF697A;
    border-radius:5px;
    }
    
    #box > p
    {
    width:110px;
    box-sizing:border-box;    
    }
    
    #box > p:nth-child(n+2)
    {
    border-left:1px solid #fff;
    }
    
    #box > p > p
    {
    
    }
    
    #box > p > p:first-of-type
    {
    border-bottom:1px solid #fff;
    }
    
    #box p
    {
    text-align:center;
    padding:10px 0;
    color:#fff;
    }
    </style>
</head>
<body>
    <p id="box">
        <p>
            <a href="#"><p>酒店</p></a>            
        </p>
        <p>
            <p><a href="#"><p>海外酒店</p></a></p>
            <p><a href="#"><p>特价酒店</p></a></p>
        </p>
        <p>
            <p><a href="#"><p>团购</p></a></p>
            <p><a href="#"><p>名宿.客栈</p></a></p>
        </p>
    </p>
</body>
</html>
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号