有一种简单的方法可以在div中垂直居中文本吗? [英] Is there an easy way to center text vertically in a div?

查看:76
本文介绍了有一种简单的方法可以在div中垂直居中文本吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在< div> >中有文字,我想垂直居中。任何简单的方法来做到这一点(非绝对定位方法)。

解决方案

这是另一种方法:



http://jsfiddle.net/SebastianPataneMasuelli/V2D3L/1/

诀窍是让div的高度与line-height相同。

 < div>一些文字< / div> 

div {
line-height:100px;
height:100px;
}

这给你一行垂直居中的文字。



有一种方法: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html



对不起,那是绝对的定位。



(但有效)


I have text in a <div> that I want centered vertically. Any easy way to do this (non-absolute positioning method).

解决方案

this is another method:

http://jsfiddle.net/SebastianPataneMasuelli/V2D3L/1/

the trick is to make the height of the div the same value as line-height.

<div>some text</div>

div {
 line-height: 100px;
 height: 100px;   
}

this gives you a line of vertically centered text.

there is a way: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html.

sorry, that uses absolute positioning.

(but it works)

这篇关于有一种简单的方法可以在div中垂直居中文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆