<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { margin: 0; padding: 0; list-style: none; } body { background-color: #eee; font-size: 22px; } h3 { margin: 10px; font-weight: normal; } section { width: 1000px; margin: 0 auto; } ul { background-color: #fff; border: 1px solid #ccc; } ul li { width: 200px; height: 200px; background-color: pink; margin: 10px; } section:nth-child(1) ul { display: flex; /* flex-wrap: nowrap; 默认就是不换行的 */ /* flex-wrap: nowrap; */ } section:nth-child(2) ul { display: flex; flex-wrap: wrap; } </style> </head> <body> <section> <h3>换行模式 flex-wrap: nowrap;</h3> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> </section> <section> <h3>换行模式 flex-wrap: wrap; 自动换行</h3> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> </ul> </section> </body> </html>
demo 效果: