如何水平放置< div> [英] How to horizontally center a <div>

查看:115
本文介绍了如何水平放置< div>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CSS将< div> 在另一个< div> 中水平居中? p>

How can I horizontally center a <div> within another <div> using CSS?

<div id="outer">
  <div id="inner">Foo foo</div>
</div>




推荐答案

我已经创建了此示例,以展示如何垂直水平 align

I've created this example to show how to vertically and horizontally align.

代码基本上是这样的:

#outer {
  position: relative;
}

和...

#inner {
  margin: auto;
  position: absolute;
  left:0;
  right: 0;
  top: 0;
  bottom: 0;
}

它将保留在中心,即使您调整大小屏幕。

And it will stay in the center even when you resize your screen.

这篇关于如何水平放置&lt; div&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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