<!DOCTYPE html> <html lang="en"> <head> <style> body { color: orange; } div { position: absolute; /*box-sizing: border-box; /*加box-sizing: border-box;时的content=(width-border-padding);未加时的width=content*/*/ width: 400px; border: 5px solid orange; padding: 50px; height: 160px; background: lightgray; } p { position: absolute; /* 包含块为最近的祖先元素(可能是块也可能不是块元素)的内边距边缘(padding-left + content + padding-right)组成; width: 50%; /* == (50+400+50)px * 50% = 250px */ height: 25%; /* == (50+160+50)px * 25% = 65px */ margin: 5%; /* == (50+400+50)px * 5% = 25px */ border: 5px solid orange; padding: 5%; /* == (50+400+50)px * 5% = 25px */ background: pink; color: green; } /*p { /* 包含块为最近的祖先块元素(只能是块元素)或格式化上下文的内容区的边缘(content)组成; width: 50%; /* == 400px * 50% = 200px */ height: 25%; /* == 160px * 25% = 40px */ margin: 5%; /* == 400px * 5% = 20px */ border: 5px solid orange; padding: 5%; /* == 400px * 5% = 20px */ background: pink; color: green; }*/ </style> </head> <body> <div> <p>This is a paragraph!</p> </div> </body> </html> |