CSS如何实现多行文本垂直居中效果_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:30:52
Original
1126 people have browsed it

CSS如何实现多行文本垂直居中效果:
想要实现单行文本在元素中垂直居中,非常的简单,只要将元素的line-height和height属性值设置为相同即可,例如:

 

line-height:30px;height:30px;
Copy after login

但是要设置多行文本垂直居中效果,就稍稍费一些周折了,代码如下:

<!DOCTYPE html><html><head><meta charset=" utf-8"><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">.vcenter {  width:100px;  height:102px;  vertical-align:middle;  display:table-cell;  overflow:hidden;  background:red;}</style></head><body><div class="vcenter">蚂蚁部落欢迎您</div></body></html>
Copy after login

以上代码可以将多行文本设置为垂直居中效果,不过IE7和IE7以下浏览器不支持。

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

更多内容可以参阅: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