flex布局,没有justify-self,如何实现一左一中布局

自从接触到flex布局后,就觉得用的特别爽,后来发现flex布局的justify-self好像不起作用,不像 align-self 属性那样可以单独对子元素自己设置是左对齐还是右对齐和居中对齐;
现在直接上代码:

<style>
        * {
            margin: 0;
            padding: 0;
        }

        .header {
            display: flex;
            width: 900px;
            height: 120px;
            margin: 0 auto;
            background: paleturquoise;
        }

        .back {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 200px;
            /*这个宽度是你左边元素的宽度*/
            font-size: 20px;
        }

        .title {
            display: flex;
            justify-content: center;
            align-items: center;
            flex: 1;
            background-color: wheat;
        }

    </style>
</head>

<body>
    <div class="header">
        <div class="back">返回</div>
        <div class="title">中间标题</div>
        <div class="back"></div>
    </div>
</body>

显示效果:
在这里插入图片描述
其实就是给右边加了一个空的div,如果大家有啥更好的方法可以评论区留言!

在Vue中,可以通过多种方式将两个按钮放在一行,并且一个靠左一个靠右。以下是几种常见的方法: ### 方法一:使用Flexbox ```html <template> <div class="button-container"> <button class="left-button">左按钮</button> <button class="right-button">右按钮</button> </div> </template> <style> .button-container { display: flex; justify-content: space-between; } </style> ``` ### 方法二:使用浮动 ```html <template> <div class="button-container"> <button class="left-button">左按钮</button> <button class="right-button">右按钮</button> </div> </template> <style> .button-container { overflow: hidden; } .left-button { float: left; } .right-button { float: right; } </style> ``` ### 方法三:使用Grid布局 ```html <template> <div class="button-container"> <button class="left-button">左按钮</button> <button class="right-button">右按钮</button> </div> </template> <style> .button-container { display: grid; grid-template-columns: 1fr 1fr; align-items: center; } .left-button { justify-self: start; } .right-button { justify-self: end; } </style> ``` ### 方法四:使用内联块元素 ```html <template> <div class="button-container"> <button class="left-button">左按钮</button> <button class="right-button">右按钮</button> </div> </template> <style> .button-container { text-align: justify; } .button-container::after { content: ''; display: inline-block; width: 100%; } .left-button, .right-button { display: inline-block; } .left-button { text-align: left; } .right-button { text-align: right; } </style> ``` 以上方法都可以实现将两个按钮放在一行,并且一个靠左一个靠右。根据具体需求选择合适的方法即可。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值