display: flex子元素垂直居中
时间: 2023-09-18 20:11:53 浏览: 109
使用display: flex可以实现子元素的垂直居中。你可以通过设置父元素的属性justify-content: center和align-items: center来实现。这样子元素就会在垂直方向上居中显示。另外一种方法是通过使用flex布局,设置子元素的属性height和line-height为相同的值。这样子元素的内容就会在垂直方向上居中显示。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [[CSS] CSS display:flex实现内容水平垂直居中展示](https://blog.csdn.net/taoshihan/article/details/125563223)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [frontend-training:前端练习项目](https://download.csdn.net/download/weixin_42106357/15296317)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [css display:flex实现元素垂直居中](https://blog.csdn.net/webZRH/article/details/81435027)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文