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

请教下 我这是main里面right宽度已经自适应了 怎么把right和left 相隔为10px

请教下 我这是main里面right宽度已经自适应了 怎么把right和left 相隔为10px

qq_12月_0 2016-11-23 14:31:04
<style type="text/css">body{ margin:0; padding:0; font-size:30px; color:#000}.top{height:100px;background:#9FC;}.main,.left,.right{height:600px;background:#F00;}.right{float:right;margin-left:300px;background:#993;}.left{width:200px;background:#00C;}.foot{height:50px;background:#666;}</style></head><body><div class="top">21112top</div><div class="main">      <div class="right">right</div>    <div class="left">left</div></div><div class="foot">foot</div>在DW里 left和right总是隔着好长的距离
查看完整描述

3 回答

?
A空城

TA贡献14条经验 获得超3个赞

左右DIV都自适应布局,用百分比来定义宽度。记得要清楚浮动!

<style type="text/css">

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

.top{height:100px;background:#9FC;}

.main,.left,.right{height:600px;background:#F00; }

.main:after{display:table;clear:both} 

.right{float:right;background:#993; width:75%;}

.right_l,.left_l{width:5px; background:#F00; height:inherit}

.right_l{float:left;}

.right_r{float:right;}

.left{width:25%;background:#00C; float:left;}

.left_l{ float:right;}

.left_r{ float:left;}

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

</style>

</head>

<body>

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

<div class="main">  

    <div class="right">

      <div class="right_l"></div>

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

    </div>

    <div class="left">

      <div class="left_l"></div>

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

    </div>

</div>

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

</body>

查看完整回答
反对 回复 2016-11-24
?
tietth

TA贡献17条经验 获得超8个赞

1.左边定宽 右边自适应

左边float:left       右边margin-left:210px

<!doctype html>
<html>
<head>
    <style type="text/css">
        body{ 
            margin:0; 
            padding:0; 
/*            font-size:30px;*/
            color:#000;
        }
        .top{
            height:100px;
            background:#9FC;
        }
        .main,.left,.right{
            height:600px;
            background:#F00;
        }
        .right{
        	
        	margin-left:210px;
        	background:#993;
        }
        .left{
        	width:200px;
        	background:#00C;
        	float: left;
        }
        .foot{
        	height:50px;
        	background:#666;
        }
    </style>
</head>

<body>
	<div class="top">21112top</div>
	<div class="main">
		<div class="left">left</div>
		<div class="right">right</div>
	</div>
	<div class="foot">foot</div>
</body>  
</html>

2 绝对定位

<!doctype html>
<html>
<head>
    <style type="text/css">
        body{ 
            margin:0; 
            padding:0; 
/*            font-size:30px;*/
            color:#000;
        }
        .top{
            height:100px;
            background:#9FC;
        }
        .main{
        	position: relative;
        }
        .main,.left,.right{
            height:600px;
            background:#F00;
        }
        .right{
        	position: absolute;
        	left: 210px;
        	top:0;

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

        }
        .foot{
        	height:50px;
        	background:#666;
        }
    </style>
</head>

<body>
	<div class="top">21112top</div>
	<div class="main">
		<div class="left">left</div>
		<div class="right">right</div>
	</div>
	<div class="foot">foot</div>
</body>  
</html>

。。。还有一些 各有优缺点

查看完整回答
反对 回复 2016-11-23
?
lijune

TA贡献2条经验 获得超0个赞

设置left右浮动就可以了

查看完整回答
反对 回复 2016-11-23
?
啊啊啊啊123

TA贡献25条经验 获得超8个赞

你.right{float:right;  .left什么都没给,自然一个在左一个在右咯  隔着好长的距离

查看完整回答
反对 回复 2016-11-23
?
团酱

TA贡献16条经验 获得超10个赞

两个div都左浮动:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <style type="text/css">
        body{ margin:0; padding:0; font-size:30px; color:#000}
        .top{height:100px;background:#9FC;}
        .main,.left,.right{height:600px;background:#F00;}
        .right{float:left;margin-left:10px;background:#993;}
        .left{float:left;width:200px;background:#00C;}
        .foot{height:50px;background:#666;}
    </style>

</head>

<body>
<div class="top">21112top</div>
<div class="main">
    <div class="left">left</div>
    <div class="right">right</div>

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


查看完整回答
反对 回复 2016-11-23
  • 3 回答
  • 0 关注
  • 2235 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信