使几个DIV在同一行并排显示,有间隙的情况的处理方案
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>让块级标签并排显示并且设置间隙</title> <style> *{margin:0;padding:0} .father{ height: 460px; width:460px; border: 1px solid gray; } .son{ height:100px; width: 100px; } </style> </head> <body> <div class="father"> <div style="background-color: red;" class="son">son1</div> <div style="background-color: gold;" class="son">son2</div> <div style="background-color: green;" class="son">son3</div> <div style="background-color: blue;" class="son">son4</div> </div> </body> </html> 上面的代码是没有设置时的代码。 设置完成后的效果图 如果只对父元素和子元素设置width和height