猿问

为什么right那块是根据内容的多少而设定的宽度 但是老师的代码却是覆盖了右边那块的全部?

<!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=utf-8" />

<title>无标题文档</title>

<style type="text/css">

.warp{margin:0 auto; }

.main1{background:#000;height:100px;}

.mainbody{background:red;height:200px;;position:relative;width:100%; }

.left{background:#666;height:100px;width:180px;}

.right{background:green;margin-left:200px;position:absolute;top:0px;}

.main4{background:#CF0;height:100px;}



</style>


</head>


<body>

<div class="wrap">

        <div class="main1"></div>

        <div class="mainbody">

            <div class="left">left</div>

            <div class="right">right</div>

        </div>

        <div class="main4"></div>

</div>

</html>


看个蛋啊
浏览 774回答 1
1回答

李晓健

.warp{margin:0 auto; } .main1{background:#000;height:100px;} .mainbody{background:red;height:200px;;position:relative;width:100%; } .left{background:#666;height:100px;width:180px;float: left} .right{background:green;margin-left:200px;height: 100px} .main4{background:#CF0;height:100px;}这样就盖全部了
随时随地看视频慕课网APP
我要回答