使flexbox中的div在水平和垂直方向居中,同时占用剩余空间



我可以让它垂直或水平居中,但不能同时居中。这是我目前为止的css代码:

.my-flex{
display: flex;
height: 100%;
width: 100%
}
//other pieces of the the flexbox that i have before it that aren't relevent
.last-element{
flex-grow: 1 0 auto;
align-self: center;
justify-self:center;
}

我还试着让我的flex也成为jusify内容中心和flex启动以及对齐项目

.my-flex{
display: flex;
height: 100%;
width: 100%
}
//other pieces of the the flexbox that i have before it that aren't relevent
.last-element{
flex-grow: 1;
align-self: center;
justify-self:center;
text-align: center
}

这就是我要做的!

如果<div class="my-flex">是父div,则

.my-flex{
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}

最新更新