目录
需求二:儿子在父亲的水平中央显示(儿内 margin: 0 auto;)
需求四:儿子在父亲的水平居右显示(margin-right:0)
父子场景下
需求一:sup(父亲)左上右顶格显示。即,消除默认8px
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>margin</title> <style type="text/css"> /*需求1:sup(父亲)左上右顶格显示 即,消除默认8px*/ html, body { /*初始化操作,body默认具有margin: 8px*/ margin: 0; } /*前提: sup显示区域宽全屏,高200px,红色。 sub显示区域宽高个100px,橘色。*/ .sup { width: auto; height: 200px; background-color: red; } .sub { width: 100px; height: 100px; background-color: orange; } </style> </head> <body> <div class="sup"> <div class="sub"></div> </div> </body> </html>
需求二:儿子在父亲的水平中央显示(儿内 margin: 0 auto;)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>margin</title> <style t