html - 如何使 div 以与 Drawer React Material UI 相同的宽度粘在 Drawer 的底部?
问题描述
我用Drawer
右手边做一个<Drawer/>
,我要1<div>
是粘在底部,<Drawer />
同时,宽度<div>
要和那个一样<Drawer />
。
期望的结果:
这就是我试图实现上述结果的原因:
const useStyles = makeStyles({
list: { // <-- this set the width of Drawer
width: 500,
},
bottomContainer: {
position: "fixed",
bottom: 0,
display: 'flex',
flex: 1,
flexDirection: 'row',
justifyContent: 'space-between',
margin: '30px'
},
});
但是当我设置时position:fixed
,底部的 div 变成了这样:
如您所见,整个 div 是凝胶在一起的,与抽屉的宽度不匹配。但如果设置position: relative
,则bottomContainer
出现相同的宽度div in top
并显示在其下方,而不是底部<Drawer />
。
如果我设置width: '100%'
为bottomContainer
,则Abc
出现在<Drawer />
因此我的问题是:
如何制作<div>
具有相同宽度<Drawer/>
并出现在底部的<Drawer />
?
解决方案
在这种情况下使用flexbox 。
您应该设置一个包含高度和两个子元素的容器。通过添加display: flex
和flex-direction: column
。justify-content: space-between
在包含两个段落元素的第二个 div 中,添加另一个display: flex
and justify-content: space-between
。您无需在flex-direction
此处添加,因为默认值为flex-direction: row
. 您还可以align-items: center
在此处添加以垂直居中对齐内容。
* {
margin: 0;
padding: 0;
}
.flex {
width: 100%;
height: 500px;
background-color: grey;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.div1, .div2 {
width: 100%;
height: 100px;
background-color: red;
}
.div2 {
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="flex">
<div class="div1"></div>
<div class="div2">
<p>abc</p>
<p>123</p>
</div>
</div>
推荐阅读
- python - 雅虎邮件错误550,b'请求失败;信箱不可用'
- google-apps-script - 有值时,Google 表格脚本 GetValue/GetDisplayValue 返回 #N/A
- celery - 气流 dag - 任务立即进入 'up_for_retry' 状态('start_date' 是 1 天前)
- javascript - 在表中动态添加行 - Bootstrap & JS
- javascript - 如何从 url 隐藏 id?
- javascript - 如何使输入元素只读取决于两个变量的值
- json - 如何在 Swift 的 collectionview 中为 JSON 数据添加分页
- python - 从 kwargs 构建条件逻辑
- vue.js - 如何分离基本相同但使用不同状态的功能?Vue2/Vuex
- javascript - 找到对@deprecated 代码的所有引用