20170314 第十五课时盒模型之padding详解

20170314 第十五课时盒模型之padding详解
和margin类似

margin主要控住一个元素内部文字之间的距离。如果一个div,内部有一个子div,为了让子div和父div保持距离,优先使用子div的margin,而不是父div的padding。
因为场合不一样,padding主要是控制文字,margin主要是控制布局、距离。
盒子和盒子之间的距离优先用margin,盒子和文字之间的距离优先使用padding。

作业:盒子的宽高各是100px如果盒子有30像素的padding值,同时设置背景为灰色,灰色的面积多大。
(原以为:灰色面积应该为100*100px,文字不包含的地方也是灰色的。×)

灰色的面积应该为130130像素方,文字实际可以写的面积为100px100px,但是为了使有一个内边距,灰色面积会增大,因为包含写字的部分,和内边距。

第十四课时作业:制作一个圣诞树
使用绝对定位,

box_relative { position: absolute; left: 30px; top: 20px;

}
[图片上传中。。。(1)]

代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>8小时第十五课时</title>
<style >
{
/
调整缩进,这样就是整个页面贴合网页*/
padding: 0;
margin: 0;
}

#trip{
    width: 0px;
    height: 0px;
    border-top: 50px solid transparent;
    border-right: 50px solid transparent;
    border-bottom: 50px solid green;
    border-left: 50px solid transparent;   
    position: absolute;
    left: 20px;
    top: 0px;
}
#leaf{
    width: 0px;
    height: 0px;
    border-top: 70px solid transparent;/*边框宽70px,实线,颜色白色*/
    border-right: 70px solid transparent;
    border-bottom: 70px solid green;
    border-left: 70px solid transparent;
    position: absolute;
    left: 0px;
    top: 30px;   
}
#tree{
    width:10px;
    height: 20px;
    background-color: #CD9B1D;
    position: absolute;
    left:65px;
    top: 170px;
}

</style>
<title>8小时第十五课时 盒模型之padding详解</title>
</head>
<body>
<div id=trip>
</div>
<div id=leaf>
</div>
<div id=tree></div>
</body>
</html>

效果:

Paste_Image.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 各种纯css图标 CSS3可以实现很多漂亮的图形,我收集了32种图形,在下面列出。直接用CSS3画出这些图形,要比...
    剑残阅读 9,688评论 0 8
  • 1、垂直对齐 如果你用CSS,则你会有困惑:我该怎么垂直对齐容器中的元素?现在,利用CSS3的Transform,...
    kiddings阅读 3,200评论 0 11
  • 5.椭圆 #ellipse{ width: 200px; height: 100px; background-co...
    小茶叶叶阅读 2,127评论 0 1
  • 1.长方形 #Rectangle{ width: 200px; height: 50px; background-...
    一直以来都很好阅读 518评论 0 0
  • 本周白天学习特长,晚上回到家完成阅读和作业。虽然时间特别有限,但是还是完成的不错。特别是英语方面,已经形...
    橄榄树翔阅读 584评论 0 1