Home > Web Front-end > HTML Tutorial > 文本如何做到垂直居中对齐_html/css_WEB-ITnose

文本如何做到垂直居中对齐_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:31:22
Original
1632 people have browsed it

文本如何做到垂直居中对齐:
建议:尽可能的手写代码,可以有效的提高学习效率和深度。
网页布局中经常用到让文本在一行中垂直居中对齐。默认情况下文本是居上对齐的。
实例:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.mytest {  width: 200px;  height: 40px;  line-height: 40px;  border: 1px solid blue;}</style></head><body><div class="mytest">大家好,我要居中对齐</div></body></html>
Copy after login

以上代码可以将div中的文本垂直居中对齐,对齐的方法就是把div的height属性值和line-height的属性值设为相等即可达到文本垂直居中效果,上面代码中两个属性值都设置为40px。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4762

更多内容可以参阅:http://www.softwhy.com/divcss/

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template