在CSS中居中div [英] Center a div in CSS

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

问题描述

我尝试将此页面上的newsslider(位于div底部容器)置于中心位置:

I'm trying to center the newsslider (in the div bottom-container) on this page:

http://www.luukratief-design.nl/dump/parallax/index.html

我已经有 text-align:center;

任何建议?

推荐答案

text-align:center; 只是元素的内容内容的中心,而不是元素本身。

The text-align: center; only centers the element's inline contents, not the element itself.

如果是 元素 div ),您需要设置 margin:0 auto; ,否则如果是 内联元素,则您需要在其父元素上设置 text-align:center;

If it is a block element (a div is), you need to set margin: 0 auto;, else if it is an inline element, you need to set the text-align: center; on its parent element instead.

margin:0 auto; 将顶部和底部边距设置为 0 ,将左右边距设置为 auto (相同大小),以便自动将其放在中心。这只有在所讨论的块元素具有已知的 width (固定或相对)时才有效,否则它无法确定开始和结束的位置。

The margin: 0 auto; will set top and bottom margin to 0 and left and right margin to auto (of the same size) so that it automagically puts itself in the center. This only works if the block element in question has a known width (either fixed or relative), else it cannot figure where to start and end.

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

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