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

看看我这个错哪了, 为什么左和右放到中间就出问题,单独放一个就没事

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

body{margin: 0;padding: 0;font-size: 20px;font-weight:bold}

div{text-align: center;line-height: 30px}

.top{height: 100px;background: blue}

.main{width: 800px;height: 300px;background: red;margin: 0 auto}

.left{width: 300px;height: 300px;background: yellow;float: left}

.right{width: 500px;height: 300px;background: #369;float: right}

.foot{height: 100px;background: #900;margin: 0 auto}

</style>

</head>

<body>

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

<div class="main">main

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

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

</div>

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

</div>

</body>

</html>


正在回答

6 回答

<div class="main"> main  这main是内容了,单独要成一个块,覆盖不了!

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

<div class="main">main把最右main删除就行了

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

首先,我觉得你想得好像复杂了一些。,其实他要求完成什么就写什么就行了。。你的main设置margin: 0 auto,他左右自动了,然后你的left又是左浮动,所以main就变成了left的右边来了,

main我把他想作是一个背景,所以只设置和左右侧相同的高度,然后宽度就随便他变化了。你的top高100px,所以你可以直接给left设置绝对定位 position:absolute;top:100px;left:0px; ,然后left上面就紧贴top,并也在最左侧了。然后给left设置一个宽度,例如你的300px,把right的位置用margin-left,这样就可以将right和left的位置拉开,例如right设置margin-left:310px,这样right距离左侧边缘就是310px,距离left就是10px。

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

倒数第三行,多了一个</div>吧。

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

举报

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

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

进入课程

看看我这个错哪了, 为什么左和右放到中间就出问题,单独放一个就没事

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