CSS3:如何在div中垂直对齐文本?(CSS3: How to align text vertically within a div?)
我有一个自定义字体的div,我正在尝试使它的文本与它内部的div具有相同的高度。
我一直试图找到一种方法来覆盖文本的垂直对齐而没有div而没有成功。 为了这个目的,我希望有类似文本缩进方法的东西。
这是一个简单的JsFiddle和我的例子。
<!DOCTYPE html> <html> <head> <link href='http://fonts.googleapis.com/css?family=Lekton' rel='stylesheet' type='text/css'> <style> .texto { background-color: #000; height: 24px; font-family: 'Lekton', sans-serif; color:white; font-size: 24px; } </style> </head> <body> <div class="texto">Test</div> </body> </html>I have a div with a custom font and I'm trying to make it so the text has the same height as the div it's inside of.
I've been trying to find a way to override the vertical alignment of text without a div with no success. I was hoping there was something like the text-indent method for this purpose.
Here's a simple JsFiddle with my example.
<!DOCTYPE html> <html> <head> <link href='http://fonts.googleapis.com/css?family=Lekton' rel='stylesheet' type='text/css'> <style> .texto { background-color: #000; height: 24px; font-family: 'Lekton', sans-serif; color:white; font-size: 24px; } </style> </head> <body> <div class="texto">Test</div> </body> </html>最满意答案
使用line-height CSS属性:
line-height : 24px;Use a line-height CSS property :
line-height : 24px;更多推荐
发布评论