^-^菜鸟求教---当网页很长时,posiontion定位的不方便问题解决办法
当网页height值很大时,那么#header和#footer中间的#container部分定位问题:
当把#container相对定位后,让其里面的所有div均继承,这时里面的div内容老是以#container进行绝对定位,计算就会比较
繁琐,哪位高手能不能教教我怎么再进行#shop # food #info #fun 等盒子的定位(这四个盒子直排下来即可)
=====================================================================================
上代码:
html部分:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link rel="stylesheet" type="text/css" href="style/layout.css"/>
<title>栗子</title>
</head>
<body>
<div id="header">
<div id="header_top">header_top</div>
<div id="title">title</div>
<div id="navMenu">navMenu</div>
</div>
<div id="container">
<div id="flash_info">flash_info</div>
<div id="info_list">info_list</div>
<div id="board">board</div>
<div id="ad_1">ad_1</div>
<div id="shop"></div>
<div id="food">food</div>
<div id="info">info</div>
<div id="fun">fun</div>
</div>
<div id="footer">footer</div>
</body>
</html>
===========================================================================================
css部分:
/*---------date----2012-2-24--------*/
/*---------base--------*/
*{
margin:0;
padding:0;
}
body{
font-size:12px;
width:960px;
margin:0 auto;
position:relative;
}
ul{
list-style-type:none;
}
a:link{
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
/*--------------header------------*/
#header{
height:169px;
width:960px;
margin:0 auto;
position:relative;
}
#header #header_top{
height:29px;
background:maroon;
}
#header #title{
height:100px;
background:green;
}
#header #navMenu{
height:40px;
background:orange;
}
/*------------container------------*/
#container{
position:relative;
background:1px solid gray;
margin-top:10px;
border:1px solid gray;
height:1000px;
}
#container #flash_info{
position:absolute;
background:purple;
height:171px;
width:710px;
}
#container #info_list{
margin-top:10px;
position:absolute;
left:0;
top:171px;
background:pink;
height:400px;
width:710px;
}
#container #board{
position:absolute;
left:720px;
top:0;
background:gray;
height:250px;
width:238px;
}
#container #ad_1{
position:absolute;
left:720px;
top:260px;
background:green;
height:320px;
width:238px;
}
#container #shop{
}
#container #food{
}
#container #info{
}
#container #fun{
}
/*------------footer------------*/
#footer{
margin-top:10px;
background:gray;
height:100px;
}
[解决办法]
一般不会全部用绝对定位的。只有小个别元素才会,其他都用文档流或float。
我目前是没遇过楼主所说的问题。
[解决办法]
同学,一般情况下别用position:absolute; 我就是不到万不得已才会用,
我把你的 position:absolute; 都去掉后,你页面乱了,
你要分清楚,左边就是左边,右边就是右边。。。
还有是不是 info_list 会变高么?还是就是那么高这个就好搞了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><link rel="stylesheet" type="text/css" href="style/layout.css"/><title>栗子</title><style>/*---------date----2012-2-24--------*//*---------base--------*/*{margin:0;padding:0;}body{font-size:12px;width:960px;margin:0 auto;}ul{list-style-type:none;}a:link{text-decoration:none;}a:hover{text-decoration:underline;}/*--------------header------------*/#header{height:169px;width:960px;margin:0 auto;}#header #header_top{height:29px;background:maroon; } #header #title{height:100px;background:green; }#header #navMenu{height:40px;background:orange; }/*------------container------------*/#container{background:1px solid gray;margin-top:10px;border:1px solid gray;height:1000px;}#container #flash_info{background:purple;height:171px;width:710px;}#container #info_list{margin-top:10px;background:pink;height:400px;width:710px;}#container #board{background:gray;height:250px;width:238px; }#container #ad_1{background:green;height:320px;width:238px;}#container #shop{background:green;clear:both;}#container #food{background:green;}#container #info{background:green;}#container #fun{background:green;}/*------------footer------------*/#footer{margin-top:10px;background:gray;height:100px;}</style></head><body><div id="header"><div id="header_top">header_top</div><div id="title">title</div><div id="navMenu">navMenu</div> </div><div id="container"> <div style="float:left;"> <div id="flash_info">flash_info</div> <div id="info_list">info_list</div> </div> <div style="float:right;"> <div id="board">board</div> <div id="ad_1">ad_1</div> </div> <div id="shop">shop</div> <div id="food">food</div> <div id="info">info</div> <div id="fun">fun</div></div><div id="footer">footer</div></body></html>