使用css对齐中心 [英] working with css to align center

查看:106
本文介绍了使用css对齐中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 div 标签的HTML文件,以及该标签中的一些文本。我想要调整该文本正好在div的中间,也正确的div的任何分辨率的页面中间。我尝试用 margin:0 auto ,然后它出现在中心,但垂直它不出现在中间。

I have a html file with a div tag and some text in that tag. I want to adjust that text exactly middle of div and also div exactly middle of page for any resolution. I tried it with margin:0 auto then it appears top center, but vertically it does not appear in middle.

推荐答案

div需要这样的CSS,取决于你的HTML的其余部分:

The div needs CSS like this, depending on the rest of your HTML:

margin-left: auto;
margin-right: auto;
text-align: center;

这会将div对齐到其容器中心,并将其中的文本对齐到中心。

That will align the div in the centre of its container and align the text within it to the centre also.

编辑 - 我刚刚注意到你想垂直居中的div。有很多方法可以让Google快速显示出来,例如这个方法: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

Edit - I've just noticed you want to vertically centre the div too. There are lots of ways of doing this that a quick Google would show up, such as this method: http://www.jakpsatweb.cz/css/css-vertical-center-solution.html

这篇关于使用css对齐中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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