绝对定位文本对齐 [英] Absolute Positioning & Text Alignment
本文介绍了绝对定位文本对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在屏幕底部居中显示一些文本。
I would like some text to be centered in the bottom of the screen.
我尝试了这,但它不工作。看起来绝对定位与对齐方式冲突。
I tried this, but it doesn't work. It looks like absolute positioning conflicts with the alignment.
如何实现这个简单的任务?
How could I achieve this simple task ?
推荐答案
当绝对定位时,div不占用所有可用的水平空间。显式设置宽度为100%可以解决问题:
The div doesn't take up all the available horizontal space when absolutely positioned. Explicitly setting the width to 100% will solve the problem:
HTML
<div id="my-div">I want to be centered</div>
CSS
#my-div {
position: absolute;
bottom: 15px;
text-align: center;
width: 100%;
}
这篇关于绝对定位文本对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文