如何垂直居中? [英] How to center vertically ?

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

问题描述

大家好,


我知道如何使用

margin-left:auto;

margin-right :auto;


但是我试图垂直居中一个盒子,有什么想法解决这个问题吗?

解决方案

>但是我试图将一个盒子垂直居中,有什么想法可以解决这个问题吗?

如果没有某种客户端脚本语言就不可能完成


(JavaScript) - 据我所知。即便如此,你怎么知道这将是有效的?b $ b?你不能没有它吗?


e n | ckma写道:

但我试图垂直居中一个盒子,有什么想法解决这个问题吗?



can如果没有某种客户端脚本语言(JavaScript),我可以完成 - 据我所知。即便如此,你怎么知道它会有效?难道你不能没有它吗?




我可以,我的老板不能; o)

(丑陋的)方式要做到这一点是创建5帧,每边4空,

主要接收内容,但我不喜欢帧...

我可以'看不出有任何理由能够水平居中并且不会垂直地使用


FL< ml ** @ mangoosta.fr> ;写在

< bv *********** @ biggoron.nerim.net>

e n | ckma写道:

但我试图垂直居中一个盒子,有什么想法解决这个问题吗?



can如果没有某种客户端脚本语言(JavaScript),我可以完成 - 据我所知。即便如此,你怎么知道它会有效?难道你不能没有它吗?



我可以,我的老板不能; o)
(丑陋)这样做的方法就是创造5帧, 4,每边都是空的,然后是接收内容的主要内容,但我不喜欢框架...
我看不出有任何理由可以水平居中/>而不是垂直




如果元素的组合丑陋,不推荐使用,无效,则使用表格

进行布局但不是''使用框架是可以接受的 - 尝试使用

a单个单元格的桌子

< td valign =" middle" align =" center">


工作当桌子被设置为100%的高度时 - 它*没有*

验证,虽然我刚检查它确实垂直居中并且

IE 5x / 6 Opera 7 Mozilla 1.6和Netscape 7.1中的水平方式

http://informer.postmaster.co.uk/index.html (与

我无关,BTW)


我想这取决于老板得多少 - 我害怕有时候我会选择支付给谁,w3c或者

老板。也许你比我勇敢地坚持真理,正义和

编码标准:)


有一种css方法需要你知道

中心材料的尺寸。你将材料放在一个div中,它的左上角是屏幕中间的
一角 - 位于顶部:50%左边:50% - 然后是

然后设置顶部和左侧的负边距是高度和宽度的一半

div。这使得左上角的div高度位于

垂直中心的一半,而div的宽度的一半位于水平

中心的左侧 - 并且所以div的中心位于窗口的中心。如果div大于窗口,则打破

- 你不能向左或向上滚动看

隐藏的材料:(

http://www.wpdfd.com/editorial/thebox/deadcentre4。 HTML

我还是会让老板说出来 - 即使网站现在有效,

它会是维持和适应新要求的噩梦,它对内容施加了严重的限制......对于

来说,这是一件非常糟糕的事情你必须要忏悔。你的孩子会问:为什么那些人在街上指着你?你必须告诉他们你做了什么

你年轻的时候卖掉了你的灵魂以获得一大堆浓汤。


-

PeterMcC

如果你觉得任何一个以上是不正确的,

不合适或以任何方式冒犯,

请求e忽略它并接受我的道歉。


Hi Everyone,

I know howto center a block using
margin-left: auto ;
margin-right: auto ;

but I''m trying to center vertically a box, any idea to solve this?

解决方案

> but I''m trying to center vertically a box, any idea to solve this?

can''t be done without some kind of client-side scripting language
(JavaScript) - as far as I know. even then, how do you know it''ll be
effective? can''t you live without it?


e n | c k m a wrote:

but I''m trying to center vertically a box, any idea to solve this?


can''t be done without some kind of client-side scripting language
(JavaScript) - as far as I know. even then, how do you know it''ll be
effective? can''t you live without it?



I can, my boss can''t ;o)
The (ugly) way to do this is create 5 frames, 4 empty on each side and
the main that receive the content but I don''t like frames...
I can''t see any good reason to be able to center a box horizontally and
not vertically


FL <ml**@mangoosta.fr> wrote in
<bv***********@biggoron.nerim.net>

e n | c k m a wrote:

but I''m trying to center vertically a box, any idea to solve this?


can''t be done without some kind of client-side scripting language
(JavaScript) - as far as I know. even then, how do you know it''ll be
effective? can''t you live without it?



I can, my boss can''t ;o)
The (ugly) way to do this is create 5 frames, 4 empty on each side and
the main that receive the content but I don''t like frames...
I can''t see any good reason to be able to center a box horizontally
and not vertically



If a combination of elements that is ugly, deprecated, invalid, uses tables
for layout but doesn''t use frames is any more acceptable - try a table with
a single cell
<td valign="middle" align="center">

That "works" when the table is set to a height of 100% - it *doesn''t*
validate, though I''ve just checked that it does center vertically and
horizontally in IE 5x/6 Opera 7 Mozilla 1.6 and Netscape 7.1

Example at http://informer.postmaster.co.uk/index.html (nothing to do with
me, BTW)

I guess it depends on how much say the boss gets - I''m afraid that sometimes
the choice for me is informed by the question as to who pays, w3c or the
boss. Perhaps you''re braver than me in standing up for truth, justice and
coding standards :)

There is a css method that requires that you know the dimensions of the
centered material. You position the material in a div which has its top left
corner at the middle of the screen - positioned top:50% and left:50% - and
then set negative margins for top and left at half the height and width of
the div. That puts the top left corner half the div''s height above the
vertical center and half the div''s width to the left of the horizontal
center - and so the center of the div is at the center of the window. Breaks
if the div is bigger than the window - you can''t scroll left or up to see
the hidden material :(

http://www.wpdfd.com/editorial/thebox/deadcentre4.html
I''d still give talking the boss out of it a go - even if the site works now,
it''s going to be a nightmare to maintain and adapt to new requirements, it
imposes severe limitations as to content... and it''s a very bad thing for
which you will have to do penance. Your children will ask, "Why are those
people pointing at you in the street?"and you will have to tell them what
you did when you were young and sold your soul for a mess of pottage.

--
PeterMcC
If you feel that any of the above is incorrect,
inappropriate or offensive in any way,
please ignore it and accept my apologies.


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

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