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

为什么我这种写法中间空出一大部分

<!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:100px;background:#ccc;}

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

.left{ width:200px;height:800px;background:blue;position:absolute;left:0;top:100px;}

.right{height:800px;background:#9c9;margin:0 0 0 210px;}

.foot{height:50px;background:#f63;}

</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和right之间并没有空出10px的距离,看着特别大,是网站显示有问题还是我做的有问题啊。

正在回答

4 回答

查了下left:0是相对body进行定位的,给main设置position:relative相对定位,left就会以已经进行定位的父元素main进行绝对定位position:absolute;letf:0top:0;就可以用了


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

最后一个参数是一个整型数组,数组格式写错了,应该newint[]{R.id.pic,R.id.text}sum0sum =numnumnum2num =2

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;background:red;}

.top{height:100px;background:#999}

.main{height:500px;}

.right{height:500px;background:green;position:absolute;left:210px;right:0;}

.left{ background:#00C;height:500px;width:200px;}

.foot{height:50px;background:#F30;}

</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>


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

我也是这样子的 你把left:0 去掉就好了中间就只会剩下10px了

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

慕仰5293895 提问者

确实是这样,但是为什么呢。虽然left是绝对定位,但是不应该是在main这个区间里的绝对定位吗,还是我对绝对定位的理解有问题。
2016-09-05 回复 有任何疑惑可以回复我~

举报

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

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

进入课程

为什么我这种写法中间空出一大部分

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信