html - CSS Flexbox children items not taking up full available width
问题描述
I'm trying to position the title of a card component to the left most side and some other data to the right most, as shown in the picture below:
the component I've written for this looks like the following:
<div className="card">
<div className="card-title">Some Title</div>
<div className="card-data">
<span>{`Some data: 07/22/2020`}</span>
<span>TEST</span>
</div>
</div>
For the CSS, I've seen from several previous posts that a solution is to assign flex-grow:1
or flex: 1 1 auto
to the children items. For that I've done the following:
.card {
display: flex;
justify-content: space-between;
.card-title {
flex: 1;
}
.card-data {
flex: 1;
}
}
Despite specifying the flex-grow
to be 1, it's not taking up the full space of the content, as highlighted here.
The card
div is literally at the top of the component so nothing else is messing with the styles here. Is there any other property/specification needed here to make the two divs take up the full width?
解决方案
如果你需要让.card-title
and.card-data
元素占据卡片宽度的一半,以及定位到左侧和右侧,试试这个:
.card {
display: flex;
justify-content: space-between;
.card-title {
flex-grow: 1;
}
.card-data {
display: flex;
flex-grow: 1;
justify-content: flex-end;
}
}
推荐阅读
- sql - 需要 SSIS 帮助 - 如何从目的地获取 ID
- ipython - 如何显示
在 spyder IPython 控制台中? - python - How to create subset of data based on data type when using NumPy?
- java - 将 Spring 参数添加到 VSCode Debug launch.json
- python - Python将一个数据框中的列值添加到另一个数据框中的列
- matlab - 将 Matlab 图形复制到具有完全相同的轴和字体大小的 Power Point
- jenkins - Jenkinsfile访问变量内部参数
- angular - 在某些情况下,带有 navigationExtras 的 ionic 4 router.navigate 不会覆盖 queryParams
- java - Pivotal Cloud Foundry (PCF) spring boot 应用程序停止工作且没有错误
- java - 以角度调用 Spring Boot Web 应用程序并获得响应