发布时间:2025-12-09 11:58:58 浏览次数:1
CSS margin-bottom属性用于指定要在元素底部使用的边距量。可以按长度或百分比设置边距。
用法:
margin-bottom:<length> | <percentage> | auto
属性值:
例:
<!DOCTYPE html> <html> <head> <title>CSS margin-bottom</title> <style> p{ background-color:lightgreen; } </style> </head> <body> <h1 style="color:green">GeeksforGeeks</h1> <!-- margin-bottom for below p is set to 50px --> <p style="margin-bottom:50px">Line One</p> <!-- margin-bottom for below p is set to 0px --> <p style="margin-bottom:0px">Line Two</p> <p>Line Three</p> </body> </html> 输出:
例:
<!DOCTYPE html> <html> <head> <title>CSS margin-bottom</title> <style> h1 { color:green; } .larger { width:300px; background-color:white; } .smaller { width:100px; background-color:white; } p{ background-color:lightgreen; } </style> </head> <body> <h1>GeeksforGeeks</h1> <!-- margin-bottom is set to 10% with width of containing box set to 300px --> <p > <p style="margin-bottom:10%";>Line One</p> <p>Line Two</p> </p> <!-- margin-bottom is set to 10% with width of containing box set to 100px --> <p > <p style="margin-bottom:10%;">Line One</p> <p>Line Two</p> </p> </body> </html> 输出:
支持的浏览器:下面列出了margin-bottom属性支持的浏览器: