javascript - Flex Box,对齐最后 2 个项目,位于 flex 框的底部
问题描述
我在屏幕左侧有一个垂直导航栏,里面装满了一些导航项。看下面的例子。我想在菜单中对齐顶部的 2 个项目,底部的 2 个项目。这是我的导航:
<List>
<Item>
<Icon />
<span class="sc-AxiKw hDoHET">Templates</span>
</Item>
<Item>
<Icon />
<span class="sc-AxiKw hDoHET">My Projects</span>
</Item>
<hr class="MuiDivider-root">
<Item>
<Icon />
<span class="sc-AxiKw hDoHET">Profile</span>
</Item>
<Item>
<Icon />
<span class="sc-AxiKw hDoHET">Logout</span>
</Item>
</List>
我的 CSS 样式是:
export const List = styled.div`
height: 100%;
display: flex;
flex-direction: column;
justify-content: flext-start;
`;
export const Item = styled.div`
display: flex;
flex-direction: column;
align-items: center;
${({ bottom }) => bottom && 'margin-top: auto'}
`;
当前实现仅在底部对齐最后一个元素
解决方案
首先,请分类前两个项目是一个 div,接下来的两个项目在另一个 div 之后我们可以简单的 flex-box
export const List = styled.div`
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
;
这可能会做到
推荐阅读
- python - 值错误:操作数无法与形状一起广播 (114,9) (8,) (114,9)
- java - Compact Language Detector 2 的检测方法线程安全吗?
- javascript - 如何通过编码在不受用户干扰的情况下自动更改设备语言
- php - How to know the controller and method name inside blade file in Laravel 6?
- java - FireBase Storage getDownloadUrl() .Getting error in continueWithTask method
- java - 如何在spring boot中禁用事务回滚启用类中的事务回滚方法
- oracle - 我想将列数据插入到表中,间隔为 1000
- laravel - laravel excel导入数据无法正常工作
- dart - Uncaught TypeError: Cannot read property 'getInitialConfig' of nullError in dart
- ios - 故事板上的 MAP KIT 白色