编程练习。
来源:3-5 编程练习
sx1011
2020-09-01 20:56:02
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .content{ width:800px; height:400px; background-color: skyblue; padding-left:200px; box-sizing:border-box; } .top{ width:400px; height:200px; background-color: yellow; top:100px; position:absolute; } </style> </head> <body> <div class="content"> <div class="top"></div> </div> </body> </html>
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> .content{ width:800px; height:400px; background-color: skyblue; padding-left:200px; padding-top:100px; box-sizing:border-box; } .top{ width:400px; height:200px; background-color: yellow; /*top:100px; position:absolute;*/ } </style> </head> <body> <div class="content"> <div class="top"></div> </div> </body> </html>
第一个用的.top里面的top下移100px和第二个用的.content里padding-top100px效果不太一样。
1回答
同学你好,课题完成的不错,很棒,继续加油
不一样是因为浏览器会有个默认的边距,而这两个属性的参照物不同
top:10px;是指容器本身的顶部距离页面的顶端有10个像素
padding-top:10px;是指容器内的内容距离容器的顶部有10个像素
如果想清除默认边距,可以如下设置
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!