如何实现如下图效果,让元素在两侧分布?

template代码如下,
<template>
<div class="top-header">
<div class="header-left" style="display:inline">left</div>
<div class="header-right" style="display:inline">right</div>
</div>
</template>
给 top-header 设置如下即可
.top-header{
/* border-block-end: 1px solid black; */
background-color: #99CCFF;
height: 65px;
display: flex;
justify-content: space-between;
}
注,如果 top-header 还有父级元素,其父级元素不能是 display: flex;
文章介绍了如何通过在.top-header中设置display:flex和justify-content:space-between,实现元素在两侧分布的效果。这种方法适用于需要左右对齐的布局设计,同时提醒注意父级元素不应为display:flex。
347





