初入WEB前端(15)CSS 关于内边距的探讨

    技术2022-07-27  88

    1.背景颜色会默认延伸到内边距上

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; height: 200px; background-color: grey; border: 10px orange; /* 内边距(padding) 一共有四个方向的内边距,内边距在内容区和边框之间 padding-top padding-right padding-bottom padding-left 背景颜色会延伸到内边距上 */ padding-top: 100px; } </style> </head> <body> <div class="box">hello</div> <!-- hello在内容区里,上面的部分就是内边距 --> </body> </html>

    2.内容区为绿色,内边距为灰色

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 300px; height: 200px; background-color: grey; border: 10px orange solid; /* 内边距(padding) 一共有四个方向的内边距,内边距在内容区和边框之间 padding-top padding-right padding-bottom padding-left 背景颜色会延伸到内边距上 */ padding-top: 100px; padding-left: 100px; padding-right: 100px; padding-bottom: 100px; /* padding是简写属性,规则和上面说的border一样 */ } .inner{ width: 100%; height: 100%; background-color:palegreen; } </style> </head> <body> <div class="box"> <div class="inner"></div> </div> </body> </html>

    Processed: 0.012, SQL: 10