css 文字上下居中
时间: 2023-11-30 19:49:07 浏览: 90
要在CSS中实现文字的上下居中,有几种方法可以选择。一种方法是使用line-height属性,将文字框的line-height属性设置为框的高度,这样可以让文字在框中上下居中。例如,可以使用以下代码实现:
```
h1 {
font-size: 3em;
height: 100px;
line-height: 100px;
}
```
这样,文字就会在高度为100px的框中上下居中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [3种实现CSS 上下居中的方法](https://blog.csdn.net/snsHL9db69ccu1aIKl9r/article/details/109684875)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *3* [css上下左右居中得几种方法](https://blog.csdn.net/m0_56125881/article/details/123653103)[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^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文