以两个div为中心 [英] centering two divs

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

问题描述

我如何将两个并排的div组合在一起?


我已经写了一段时间的CSS页面,但还有一件事情还是

包括我。

我可以将一个div设置为自动保证金。

我可以将两个div并排浮动。

但我不能将两个并排的div放在一起。

如果我浮动它们并给它们自动边距,则自动边距被忽略。


如果我将两个浮动的div包装在另一个div中,两个div没有其他div的概念。


所以要么我需要一些方法来制作他们并排浮动,或者我需要一些其他方式让他们居中。


有什么想法吗?我一直遇到这个问题而且我能做的最好。

给左右边缘带来艺术上令人愉悦的价值,但

集中在他们身上。


red

How do I center two side by side divs ?

I''ve been writing css pages for a while but there''s one thing tha still
eludes me.
I can center a div with margin auto.
I can place two divs side by side with float.
But I can''t center two side by side divs.
If I float them and give them auto margins, the auto margins are ignored.

If I wrap the two floated divs in another div, the two divs have no
concept of the other div.

So either I need some way to make the divs side by side without floating
them, or I need some other way to center them.

Any ideas ? I run across this problem all the time and the best I can do
is give the left and right margins artisticly pleasing values, but
centered they ain''t.

red

推荐答案

2004年10月28日星期四17:20:58 GMT,红色< gr *****@reenie.org>写道:
On Thu, 28 Oct 2004 17:20:58 GMT, red <gr*****@reenie.org> wrote:
我如何将两个并排的div中心?

我已经写了一段时间的CSS页面,但有一件事我仍然没有把我弄清楚。
我可以将一个div与marg auto对中。
我可以将两个div并排浮动。
但是我不能把两个中心放在一边旁边的div。
如果我浮动它们并给它们自动边距,则自动边距被忽略。

如果我将两个浮动的div包裹在另一个div中,则两个div没有
所以要么我需要一些方法让div并排而不是浮动它们,或者我需要一些其他方法来使它们居中。

任何想法?我一直遇到这个问题而且我能做的最好的事情是给左右边缘带来艺术上令人愉悦的价值,但是它们不会集中在一起。
How do I center two side by side divs ?

I''ve been writing css pages for a while but there''s one thing tha still
eludes me.
I can center a div with margin auto.
I can place two divs side by side with float.
But I can''t center two side by side divs.
If I float them and give them auto margins, the auto margins are ignored.

If I wrap the two floated divs in another div, the two divs have no
concept of the other div.

So either I need some way to make the divs side by side without floating
them, or I need some other way to center them.

Any ideas ? I run across this problem all the time and the best I can do
is give the left and right margins artisticly pleasing values, but
centered they ain''t.




将它们包裹在一个div中,该div居中并设置为position:relative with

no offset,因此它将作为包含块。然后将内部

div设置为宽度:50%(或左右,取决于边距等)。



Wrap them in one div which is centered and set to position: relative with
no offset so it will serve as the containing block. Then set both inner
divs to width: 50% (or thereabouts, depending on margins etc.).


Neal写道:
将它们包裹在一个div中,该div居中并设置为position:relative
没有偏移,因此它将作为包含块。然后将内部div设置为宽度:50%(或左右,取决于边距等)。
Wrap them in one div which is centered and set to position: relative
with no offset so it will serve as the containing block. Then set both
inner divs to width: 50% (or thereabouts, depending on margins etc.).



在执行此操作之前,我是否先浮动2个div?其他明智的他们并不是b $ b并排。


Do I float the 2 divs first before I do this ? Other wise they aren''t
side by side.


2004年10月28日星期四17:50:41 GMT,红色< gr*****@reenie.org>写道:
On Thu, 28 Oct 2004 17:50:41 GMT, red <gr*****@reenie.org> wrote:
Neal写道:
将它们包裹在一个div中,该div居中并设置为position:relative
没有偏移因此它将服务作为包含块。然后将两个
内部div设置为宽度:50%(或左右,取决于边距等)。
Wrap them in one div which is centered and set to position: relative
with no offset so it will serve as the containing block. Then set both
inner divs to width: 50% (or thereabouts, depending on margins etc.).


在我这样做之前,我是否先浮动2个div?其他明智的他们并不是并排的。


Do I float the 2 divs first before I do this ? Other wise they aren''t
side by side.




你可以,或者你可以使用定位。请记住,当包装器div设置为非静态位置时,它现在是包含块,并且你可以安全地绝对定位内部div关于它。



You could, or you can use positioning. Remember, when the wrapper div is
set to a non-static position, it''s now the containing block, and you can
safely absolute-position the inner divs with respect to it.


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

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