如何将两个div相邻放置 [英] How to center two divs floating next to one another

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

问题描述

我写了以下HTML,试图将两个div相邻。

I have written the following HTML trying to center two div's next to each other.

<div id='wrapper' style='text-align:center;'>
    <div style='float:left;'>
        Lorem ipsum<br />
        dolor sit amet
    </div>
    <div style='float:left;'>
    Lorem ipsum<br />
    dolor sit amet
    </div>
</div>

但是,我写的代码导致两个div向左移动。

However, the code I've written results in the two div's floating all the way to the left. What this does do correctly is float the two div's side by side.

我需要改变哪两个div并排放置?

What do I need to change to center the two div's side by side?

推荐答案

您必须自动设置保证金,可能还有一个特定宽度到您的包装div

You will have to automatically set the margin and probably a specific width to your wrapper div

<div id="wrapper"></div>

在您的CSS中:

#wrapper {
    width: 70%;
    margin: 0 auto;
}

这篇关于如何将两个div相邻放置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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