为了账号安全,请及时绑定邮箱和手机立即绑定

关于position absolute

<!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">

body{ margin:0; padding:0; font-size:30px; color:#fff}

.top{height:40px;background:#ccc}

.main{height:400px;background:red;}

.left{width:200px;height:400px;background:blue;}

.right{height:400px;background:green;margin-left:210px;}

.foot{height:40px;background:orange}

</style>


</head>


<body>

<div class="top">top</div>

<div class="main">

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

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

</div>

<div class="foot">foot</div>


</body>

</html>

为什么、.left里不加position absolute就会变到下面去,而且被footer覆盖?能解释下面,明明只mian的子元素,为什么会到下面了

正在回答

3 回答

我重新测试了下   发现我前面说的有误    我说的关于为什么left会在main之外是正确的  后半部分错误

实际上     left算是处于main所在区域  只是显示的时候显示在下面了(因为被right独占一行)   那么 既然left不存在  ,foot实际上显示出来是与foot重叠的(文字部分就已经重叠了) 。之所以你测试和我的测试结果之前都显示不重叠,因为那是设计窗口,当把代码保存之后,或者使用实时窗口就会发现 foot和left重叠

0 回复 有任何疑惑可以回复我~
#1

仰望01 提问者

前面给.right设置了margin-left,mian前面是不留了足够的空间给left吗,但是left显示还在下面,是不是电脑没有这个智慧啊
2016-06-26 回复 有任何疑惑可以回复我~

正好我刚做完这个    因为代码里RIGHT 是在LEFT之前的 而你的main right是没有width属性的,所以right独占main的一行且拥有margin-left属性,然后left没地方就被挤出来了。但是left本身应该算是在main所在区域。 所以在main的   两个都是main的子元素   没有float属性的话就会这样,这个的话什么原因我也说不好  我测试了下,left里的文字影响了foot的位置(如果left中文字是两行,那么foot往下移两行)。  这只是我的个人看法和测试结果的猜测。

0 回复 有任何疑惑可以回复我~

<!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">

body{ margin:0; padding:0; font-size:30px; color:#fff}

.boss{width: 800px;height: auto; margin: 0px auto;}

.top{height:40px;background:#ccc}

.main{height:400px;width:800px;background-color: aquamarine;}

.left{width:200px;height:400px;background:blue;float: left;}

.right{height:400px; width:600px;background:green;float: right;}

.foot{height:40px;background:orange;float: none;}

</style>


</head>


<body>

<div class="boss">

<div class="top">top</div>

<div class="main">

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

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

</div>

<div class="foot">foot</div>

</div>

</body>

</html>


0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
如何用CSS进行网页布局
  • 参与学习       209551    人
  • 解答问题       1206    个

用最简洁的案例教你布局的那些知识,这是前端工程师基本技能

进入课程

关于position absolute

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号