Div + CSS常用布局不明白的一个例子

xflltw xflltw 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我的问题是:1. 在下列代码中,div.content中的“margin-left:200px;”是相对left div, 还是相对Cotainer?但是如果是相对left,content显示的离left div的右边距离远远少于200px;即便是针对Cotainer,content div离container的右边距离远远少于200px,为什么? 2. content div是否能用left: 2px;position:relative,而不是margin-left:200px;
代码如下:
<html>
<head>
<style type="text/css">
div.container
{
width:100%;
margin:0px;
border:1px solid gray;
line-height:150%;
}
div.header,div.footer
{
padding:0.5em;
color:white;
background-color:gray;
border: 1px solid yellow;
clear:left;
}
h1.header
{
padding:0;
margin:0;
}
div.left
{
float:left;
width:160px;
margin:0;
padding:1em;
border: 1px solid red;
}
div.content
{
margin-left:200px;
border:1px solid blue;
padding:1em;
}
</style>
</head>
<body>

<div class="container">

<div class="header"><h1 class="header">W3School.com.cn</h1></div>

<div class="left"><p>William of Ockham (1285-1349)</p></div>

<div class="content">
<p>Content: At W3School.com.cn you will find
from basic HTML and XHTML to advanced XML, XSL, Multimedia and WAP.</p>
</div>

<div class="footer">Copyright 2008 by YingKe Investment.</div>
</div>

</body>
</html>
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
xflltw
CSS 61,116 成员 60,701 内容