两个div上下居中对齐
时间: 2023-10-20 11:31:17 浏览: 257
要实现两个div上下居中对齐,可以使用多种方法。其中一种方法是使用CSS中的flexbox布局。通过设置父容器的display属性为flex,然后使用align-items: center;属性来实现垂直居中对齐。这样,子元素就可以在父容器中上下居中对齐了。另一种方法是使用line-height属性。首先给父容器设置一个固定的高度,然后使用line-height属性,将其值设置为等于父容器的高度。这样,子元素就可以在父容器中上下居中对齐了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [CSS 将两个button按钮垂直+水平居中](https://download.csdn.net/download/weixin_38723753/14887963)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [如何实现<div>中元素上下对齐](https://blog.csdn.net/memgxingfeixiang/article/details/52487359)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [在div中垂直居中的两个元素](https://blog.csdn.net/weixin_39853155/article/details/117878899)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文