样式表问题,div容器中内嵌2个div,如何让容器div在页面中居中。

Iamarmy 2008-01-18 07:22:23
<div id="layout">
<div id="left"></div>
<div id="right"></div>
</div>
left和right div必须在layout中居中显示,同时layout必须在页面中居中显示。
样式该如何写?

以下写法不对。(浏览器为IE7)
<style type="text/css">
#layout
{
margin:0px auto;
width:408px;
/×text-align:center;*/
}
#left
{
width:200px;
height:300px;
float:left;
}
#right
{
width:200px;
height:300px;
float:left;
}
</style>
...全文
356 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lekaishiwo 2008-04-13
  • 打赏
  • 举报
回复
我对浏览器的不兼容烦死了。大哥,大姐们有什么好的文章吗?》
lingdu_hua 2008-04-11
  • 打赏
  • 举报
回复
把三个DIV的position都设成absolute,绝对样式下设置三个层的left和top属性,慢慢调吧.肯定灵.
smboo 2008-04-11
  • 打赏
  • 举报
回复
呵呵,在我的不懈努力下,FF下自适应高度问题被我解决了
在layout中加入
height:auto!important;
height:200px;
min-height:200px;
就OK了!~~
smboo 2008-04-11
  • 打赏
  • 举报
回复
补充提问一下:这种方法FF不支持,但是网上有种方法说可以解决,就是加一个空层,清除浮动,但是我试了在FF下也是行不通的,望各位大虾们多多指教!~~
smboo 2008-04-11
  • 打赏
  • 举报
回复
#layout
{
margin:0px auto;
width:408px;
padding-top: 25px;
padding-bottom: 25px;
/×text-align:center;*/
}
不要给layout设置高度就OK了!~~
IE6.0 IE7.0都是好的!~~
junp2007 2008-04-10
  • 打赏
  • 举报
回复
margin-right:auto;
margin-left:auto;
父容器text-align:center;
shrockey 2008-04-10
  • 打赏
  • 举报
回复
我试了,都不灵
Rainany 2008-01-18
  • 打赏
  • 举报
回复
#layout{margin:auto;width:408px; }
#left
{
width:200px;
height:300px;
float:left;
}
#right
{
width:200px;
height:300px;
float:right;
}
Atai-Lu 2008-01-18
  • 打赏
  • 举报
回复
#layout{margin-left:auto;margin-right:auto;width:76%;}
或者
#layout{margin:auto;}

61,115

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧