自从接触到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,如果大家有啥更好的方法可以评论区留言!