日期:2014-05-17  浏览次数:20540 次

Div+Css问题,请教如何在一个float:right的层内放置一个居左定位的层?
我刚开始学Div+Css,按照经典的三行两列布局作了个页面,现在想在一个float:right的层A内放置一个层B,B相对A的左侧定位。

我的CSS写法如下:
#A   {
float:right;
margin:0   auto;
clear:right;
overflow:hidden;
text-align:left;
}

#B   {
overflow:auto;
margin-top:116px;
margin-left:78px;
width:630px;
height:250px;
}

可实际上,B却默认相对A的右侧定位。因为我的站要求是宽度100%,居右显示在大分辨率下就很难看,希望各位高人能帮助我。

另外,大家看到B层是设置了宽度的,但我想最好能根据分辨率伸缩,不知道直接写width:90%之类是否可以,是否是相对A层宽度的百分比来伸缩的。

谢谢大家!

------解决方案--------------------
<!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 " />
<title> test </title>
<script type= "text/javascript ">
<!--
-->
</script>
<style type= "text/css ">
<!--
* {
padding:0;
margin:0;
}
#A {
float:right;
margin:0 auto;
clear:right;
overflow:hidden;
text-align:left;
background:#000;
width:100%;
}

#B {
overflow:auto;
margin-top:116px;
margin-left:78px;
width:630px;
height:250px;
background:#ff0;
}
-->
</style>
</head>

<body>
<div id= "A ">
<div id= "B "> </div>
</div>
</body>
</html>