float和flex区别

tech2023-02-27  105

float是让自己进行浮动

flex相当于是让子元素进行浮动

 

<html> <head> <style type="text/css"> *{ margin: 0; padding: 0; } .main{ float:left; background-color: #0f0; display: flex;/*父div设置该属性*/ } .main>div{ width: 50px; height: 50px; border: 1px solid black; } </style> </head> <body> <div>想让外面两个大DIV在一行显示,需要在DEV上面添加float:left属性,要让里面小的div显示在一行,需要添加display: flex属性</div> <div class="main"> <div></div> <div></div> <div></div> <div></div> </div> <div class="main"> <div></div> <div></div> <div></div> <div></div> </div> </body> </html>

 

最新回复(0)