display:flex;布局问题

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

clipboard.png

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

阅读 5.9k
4 个回答

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

    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;
    }

谢邀!
可以的,首先让所有的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 > div
    {
    width:110px;
    box-sizing:border-box;    
    }
    
    #box > div:nth-child(n+2)
    {
    border-left:1px solid #fff;
    }
    
    #box > div > div
    {
    
    }
    
    #box > div > div:first-of-type
    {
    border-bottom:1px solid #fff;
    }
    
    #box p
    {
    text-align:center;
    padding:10px 0;
    color:#fff;
    }
    </style>
</head>
<body>
    <div id="box">
        <div>
            <a href="#"><p>酒店</p></a>            
        </div>
        <div>
            <div><a href="#"><p>海外酒店</p></a></div>
            <div><a href="#"><p>特价酒店</p></a></div>
        </div>
        <div>
            <div><a href="#"><p>团购</p></a></div>
            <div><a href="#"><p>名宿.客栈</p></a></div>
        </div>
    </div>
</body>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题