Code
<!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>
<title>test</title>
<style type ="text/css">
.main{}{
width:450px;
background:#cccccc;
}
.content{}{
float:left;
width:150px;
margin-right:150px;
background:#999999;
};
.content_center{}{
position:relative;
float:right;
margin-left:150px;
margin-right:-300px;
width:150px;
background:#333333;
color:#ffffff;
};
.left{}{
float:left;
width:150px;
height:100px;
margin-left:-300px;
background:#999999;
position:relative;
color:#000000;
};
.right{}{
float:right;
width:150px;
};
.middle{}{
float:left;
margin-left:-150px;
width:150px;
};
.clear{}{
clear:both;
};
</style>
</head>
<body>
<div class ="main">
<div class = "content">
<div class ="content_center">
<div class ="left">左侧可变内容</div>
<div class = "right">右侧可变内容</div>
</div>
</div>
<div class ="middle">中间固定内容</div>
<div class ="clear"></div>
</div>
</body>
</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>
<title>test</title>
<style type ="text/css">
.main{}{
width:450px;
background:#cccccc;
}
.content{}{
float:left;
width:150px;
margin-right:150px;
background:#999999;
};
.content_center{}{
position:relative;
float:right;
margin-left:150px;
margin-right:-300px;
width:150px;
background:#333333;
color:#ffffff;
};
.left{}{
float:left;
width:150px;
height:100px;
margin-left:-300px;
background:#999999;
position:relative;
color:#000000;
};
.right{}{
float:right;
width:150px;
};
.middle{}{
float:left;
margin-left:-150px;
width:150px;
};
.clear{}{
clear:both;
};
</style>
</head>
<body>
<div class ="main">
<div class = "content">
<div class ="content_center">
<div class ="left">左侧可变内容</div>
<div class = "right">右侧可变内容</div>
</div>
</div>
<div class ="middle">中间固定内容</div>
<div class ="clear"></div>
</div>
</body>
</html>
说明:该样式中,同样是使用了负边界。由于负边界不能使用无限制的大小(只能让子元素处于父元素的边界而不能完全脱离父元素),所以要给content元素一个150px的右边界,这样content_center元素才恩那个处于最右端。
同样的道理,要给content_center元素定义一个左边界,才能让left元素处于最左端,用以上的定义实现了最左端和最右端的定位。由于中间部分是元素边界所在的区域,所以会显示出main元素的背景色。