效果图:
方案:
对每个格子设置margin-left和margin-bottom为负值 ,大小等于border的宽度,以解决重合边框变粗的问题,不需要进行取模运算。
代码:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>无间隙格子效果</title> <style> *{margin:0; padding:0;} #wrapper{ width:600px; margin:0 auto; padding:10px; } .box { width:199px; height:199px; border:1px solid #999; float:left; margin-left:-1px; margin-bottom:-1px; } </style> </head> <body> <div id="wrapper"> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> <div class="box"></div> </div> </body> </html>