文本在垂直中部Div [英] Text in vertical middle of Div

查看:79
本文介绍了文本在垂直中部Div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Div 元素的垂直中间对齐文本,前提是它具有位置:绝对属性指定?



设置 display:table-cell;



谢谢!

解决方案

包装一个内部div并给它 position:relative;顶部:-50%; 除了给出绝对值 top:50%



当然,如果它的样式很复杂,请提供您的CSS。

您可以使用 line-height 如果它只是一行文本,你必须杀死绝对规则。


How can I align text in the vertical middle of a Div element provided it has a position:absolute property specified?

Setting display:table-cell; vertical-align:middle; isn't working.

Thanks!

解决方案

Wrap an inner div and give it position:relative; top:-50%; in addition to giving the absolute a top:50%.

Though of course if it's complicated styling, please provide your CSS.

You can get away with line-height if it's just a single line of text, you'd have to kill the absolute rule though.

这篇关于文本在垂直中部Div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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