css中使用flex布局中子元素高度height没有达到100%
希望实现两个盒子左右分布,内容垂直居中对齐
<style>.box {display: flex;align-items: center;border: 1px solid #eeeeee;}.box-left {background-color: pink;}.box-right {background-color: skyblue;}
</style><div class="box"><div class="box-left">《绝句》唐杜甫</div><div class="box-right"><div class="box-right__item">两个黄鹂鸣翠柳,一行白鹭上青天。</div><div class="box-right__item">窗含西岭千秋雪,门泊东吴万里船。</div></div>
</div>
可以看到,左边的盒子高度并没有撑满
将父元素的样式align-items: center
去除,单独设置子元素的对齐样式
.box {display: flex;/* align-items: center; */border: 1px solid #eeeeee;}.box-left {background-color: pink;/* 增加如下样式 */display: flex;align-items: center;}.box-right {background-color: skyblue;}
使用 align-self: stretch;
将子元素撑满
.box {display: flex;align-items: center;border: 1px solid #eeeeee;}.box-left {background-color: pink;/* 子元素撑满 */align-self: stretch;display: flex;align-items: center;}.box-right {background-color: skyblue;}
处理结果
本文发布于:2024-01-30 23:24:56,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170662829723588.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |