當咱們作一個頁面時,默認頁面元素距頁面左右上下都有一個很小的間隙。以下所示:html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>三角形</title> </head> <style> .three{ width: 100px; height: 100px; border-style: solid; border-width: 1px; } </style> <body> <div class="three"> </div> </body> </html>
效果以下圖所示:spa
這是因爲盒子模型中,默認的body與整個頁面間的外邊距不爲0,將body的margin設置爲0px便可消除該間隙。以下所示:code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>三角形</title> </head> <style> .three{ width: 100px; height: 100px; border-style: solid; border-width: 1px; } body{ margin: 0px; } </style> <body> <div class="three"> </div> </body> </html>
效果以下圖所示:htm