我如何居中对齐div [英] How do i center align divs

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

问题描述

我讨厌DIVS和不同的浏览器!我一整天都在寻找一种方法来对齐愚蠢的div,问题是代码是如此敏感,我试图让它们以某种方式工作而失去理智(就像有些人应该用固定的背景滚动而且其他人不应该滚动bla bla ..)和div嵌套并以不同的方式定位如果我改变一些东西它搞砸了,在IE中工作的东西在firefox中不起作用,反之亦然......反正我最终得到了几乎想要的东西,现在我有两个主要问题:

  1. 将所有div放在页面中心的所有div中搞乱他们的立场
  2. 能够显示一个背景不会滚动的div,并且它应该显示另一个带有滚动文本的div


$问题1的b $ b这里有一些代码,我不知道它是否因位置(绝对或固定或相对或其他)而无效:

html代码:

展开 | 选择 | Wrap | 行号

解决方案


我讨厌DIVS和不同的浏览器! !我一整天都在寻找一种方法来对齐愚蠢的div,问题是代码是如此敏感,我试图让它们以某种方式工作而失去理智(就像有些人应该用固定的背景滚动而且其他人不应该滚动bla bla ..)和div嵌套并以不同的方式定位如果我改变一些东西它搞砸了,在IE中工作的东西在firefox中不起作用,反之亦然......反正我最终得到了几乎想要的东西,现在我有两个主要问题:

  1. 将所有div放在页面中心的所有div中搞乱他们的立场
  2. 能够显示一个背景不会滚动的div,并且它应该显示另一个带有滚动文本的div


$问题1的b $ b这里有一些代码,我不知道它是否因位置(绝对或固定或相对或其他)而无效:

html代码:

展开 | 选择 | Wrap | 行号


上帝与你的问题有什么关系?


罗纳德:cool:


感谢您的回复,我已经尝试了许多对齐中心,但它只是将文本对齐到中心,而div仍然粘在左侧。至于问题的第二部分,我只有2个div在彼此之上,底部有一个固定的背景,不滚动,上面的那个有滚动的文本。这实际上是在IE中工作,当我设置z-index = -1就像你在我的代码中看到的那样,但是它在firefox中不起作用。


谢谢你:)

I HATE DIVS AND DIFFERENT BROWSERS!!! i spent the whole day and night searching for a way to center align stupid divs, the problem is that the code is so sensitive, i lost my mind trying to make them work in a certain way (like some should scroll with a fixed background and others shouldn''t scroll bla bla..) and the divs are nested and positioned in different ways and if i change something it gets messed up and what works in in IE doesn''t work in firefox and vice versa... anyways i managed at the end to get almost what want, now i have 2 main problems:

  1. center all divs together in the center of the page wihtout messing up their positions
  2. be able to dispaly a div with a background that doesnt scroll, and over it should appear another div with text in it that scrolls


for problem 1 here''s some code, i dont know if it''s not working because of the position (absolute or fixed or relative or whatever):
html code:

Expand|Select|Wrap|Line Numbers

解决方案

I HATE DIVS AND DIFFERENT BROWSERS!!! i spent the whole day and night searching for a way to center align stupid divs, the problem is that the code is so sensitive, i lost my mind trying to make them work in a certain way (like some should scroll with a fixed background and others shouldn''t scroll bla bla..) and the divs are nested and positioned in different ways and if i change something it gets messed up and what works in in IE doesn''t work in firefox and vice versa... anyways i managed at the end to get almost what want, now i have 2 main problems:

  1. center all divs together in the center of the page wihtout messing up their positions
  2. be able to dispaly a div with a background that doesnt scroll, and over it should appear another div with text in it that scrolls


for problem 1 here''s some code, i dont know if it''s not working because of the position (absolute or fixed or relative or whatever):
html code:

Expand|Select|Wrap|Line Numbers


What does any god have to do with your problem??

Ronald :cool:


thanks for your reply, i already tried many align-center but it''s only aligning the text to the center while the divs are still sticking to the left side. as for the second part of the question, i just 2 divs on top of each others, the bottom one will have a fixed background that does not scroll, and the one above have the text that will scroll. this is actually working in IE when i set z-index=-1 like u see in my code, but it''s not working in firefox.

Thank you :)


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

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