CSS-文本垂直居中_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:32:45
Original
1265 people have browsed it

文本水平居中可以将text-align设置为center即可,垂直居中的话如果是单纯的设置vertical-align是没办法单独设置成功的,垂直居中的文字分为单行文本和多行文本,主要是两种不同的实现方式。

单行文本垂直居中

设置line-height和height高度一样即可:

    .outer-line {        border: 1px solid red;        height: 200px;        line-height: 200px;        width: 200px;    }    <div class="outer-line">        博客园-FlyElephant    </div>
Copy after login

多行文本垂直居中

通过table和table-cell的方式实现垂直居中:

    <div class="outer-table">        <div class="inner">            博客园-FlyElephant 原文地址:http://www.cnblogs.com/xiaofeixiang/        </div>    </div>
Copy after login

样式设置:

    .outer-table {        border: 1px solid red;        height: 200px;        width: 200px;        margin-top: 20px;        display: table;    }        .inner {        display: table-cell;        vertical-align: middle;    }
Copy after login

  

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!