左中心浮动 [英] centering float left

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

问题描述

我有一系列浮动的块,我需要将页面集中在页面上。


< div class =" center" align =" center">


< div style =" width:100 px; float:left"> thumbnail 1< / div>

< div style =" width:100 px; float:left"> thumbnail 2< / div>

< div style =" width:100 px; float:left" >缩略图3< / div>


< / div>


这些都不起作用:


..center {margin:auto}

..center {text-align:center}


如何集中课堂中心div ?


我不是中心人物的忠实粉丝,但我只是一个程序员,而不是一个

设计师。


杰夫

解决方案

Jeff Thies写道:

我有一系列的浮动的块我需要居中在页面上。

< div class =" center" align =" center">

< div style =" width:100 px; float:left"> thumbnail 1< / div>
< div style =" ;宽度:100 px; float:left"> thumbnail 2< / div>
< div style =" width:100 px; float:left"> thumbnail 3< / div>

< / div>

这些都不起作用:

。中心{margin:auto}
.center {text-align:center}

如何将班级中心div居中?




您需要在该中心div上指定宽度:-)

IIRC(任何人,请纠正我,如果我错了)

text-align:中心需要IE5,而保证金:自动

适用于较新的浏览器。


-

Els


Mentehumanaécomopára-quedas; funciona melhor aberta。


2003年9月13日星期六13:13:28 + 0200,Els

< el * ********@PLEASEtiscali.nl.invalid>写道:

Jeff Thies写道:

我有一系列浮动的块,我需要集中在
上页面。

< div class =" center" align =" center">

< div style =" width:100 px; float:left"> thumbnail 1< / div>
< div style =" ;宽度:100 px; float:left"> thumbnail 2< / div>
< div style =" width:100 px; float:left"> thumbnail 3< / div>

< / div>

这些都不起作用:

。中心{margin:auto}
.center {text-align:center}

我如何将班级中心div居中?



您需要在该中心div上指定宽度:-)
IIRC(任何人,请纠正我,如果我错了的话)IE5需要
text-align:center,而新的浏览器需要保证:自动




IMO最容易的事情是外部< div>是以

为中心,明确设置左右边距的宽度,例如:


..center

{

保证金左:10%;

保证金权利:10%;

}


,即使使用IE5也应该可以工作(哎呀,它甚至可以在NS4中使用

,如果你不想太过花哨的话)。


尼克


-

Nick Theodorakis
ni ****************** @ urmc.rochester.edu


Els写道:


IIRC(任何人,请纠正我,如果我错了)text-align:center需要
IE5,而边距:auto适用于较新的浏览器。




text-align:应用于块时的中心将使所有元素居中
$ b块中包含$ b,例如将一个img包装在div中并将其应用

text-align:center到div。

http://www.w3.org/TR/CSS1#text-align


margin:auto用于居中块级元素。

http://www.w3.org/TR/CSS1#horizo​​ntal-formatting

--Nikolaos


I have a series of blocks that are float left that I need centered on
the page.

<div class="center" align="center">

<div style="width: 100 px;float: left">thumbnail 1</div>
<div style="width: 100 px;float: left">thumbnail 2</div>
<div style="width: 100 px;float: left">thumbnail 3</div>

</div>

None of these work:

..center{margin: auto}
..center{text-align: center}

How do I center the class center div?

I''m not a big fan of centering stuff but I''m just a programmer, not a
designer.

Jeff

解决方案

Jeff Thies wrote:

I have a series of blocks that are float left that I need centered on
the page.

<div class="center" align="center">

<div style="width: 100 px;float: left">thumbnail 1</div>
<div style="width: 100 px;float: left">thumbnail 2</div>
<div style="width: 100 px;float: left">thumbnail 3</div>

</div>

None of these work:

.center{margin: auto}
.center{text-align: center}

How do I center the class center div?



You need to specify a width on that center div :-)
IIRC (anyone, please correct me if I''m wrong) the
text-align: center is needed for IE5, while the margin:auto
is there for the newer browsers.

--
Els

Mente humana é como pára-quedas; funciona melhor aberta.


On Sat, 13 Sep 2003 13:13:28 +0200, Els
<el*********@PLEASEtiscali.nl.invalid> wrote:

Jeff Thies wrote:

I have a series of blocks that are float left that I need centered on
the page.

<div class="center" align="center">

<div style="width: 100 px;float: left">thumbnail 1</div>
<div style="width: 100 px;float: left">thumbnail 2</div>
<div style="width: 100 px;float: left">thumbnail 3</div>

</div>

None of these work:

.center{margin: auto}
.center{text-align: center}

How do I center the class center div?



You need to specify a width on that center div :-)
IIRC (anyone, please correct me if I''m wrong) the
text-align: center is needed for IE5, while the margin:auto
is there for the newer browsers.



IMO the easist thing is to do with the outer <div> is to center it by
explicitly setting the widths of the left and right margins, eg:

..center
{
margin-left: 10%;
margin-right: 10%;
}

and that should work even with IE5 as well (heck, it even works in NS4
if you don''t try to get too fancy).

Nick

--
Nick Theodorakis
ni******************@urmc.rochester.edu


Els wrote:


IIRC (anyone, please correct me if I''m wrong) the text-align: center is
needed for IE5, while the margin:auto is there for the newer browsers.



text-align: center when applied to a block will center all elements
contained in the block e.g. to center an img wrap it in a div and apply
text-align: center to the div.

http://www.w3.org/TR/CSS1#text-align

margin: auto is used to center block level elements themselves.

http://www.w3.org/TR/CSS1#horizontal-formatting

--Nikolaos


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

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