如何实现Bootstrap 4 .flex-*-nowrap类
flex-*-nowrap类的工作方式类似于flex-no-wrap类,以避免包装flex项。
但是,如果您希望避免在不同的屏幕尺寸上换行,请使用flex-*-no-wrap类,例如-
flex-lg-nowrap:避免在大屏幕上换行
flex-sm-nowrap:避免在小屏幕尺寸上包装
flex-md-nowrap:避免在中等屏幕尺寸上换行
以下是实现flex-*-nowrap类的示例-
示例
<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> </head> <body> <div class="container mt-3"> <p>Flex items will wrap</p> <div class="d-flex flex-wrap bg-warning"> <div class="p-2 border">One</div> <div class="p-2 border">Two</div> <div class="p-2 border">Three</div> <div class="p-2 border">Four</div> <div class="p-2 border">Five</div> <div class="p-2 border">Six</div> <div class="p-2 border">Seven</div> <div class="p-2 border">Eight</div> <div class="p-2 border">Nine</div> <div class="p-2 border">Ten</div> <div class="p-2 border">Eleven</div> <div class="p-2 border">Twelve</div> <div class="p-2 border">Thirteen</div> <div class="p-2 border">Fourteen</div> </div><br> <p>Flex items won't wrap (small screen size)</p> <div class="d-flex flex-sm-nowrap bg-danger"> <div class="p-2 border">One</div> <div class="p-2 border">Two</div> <div class="p-2 border">Three</div> <div class="p-2 border">Four</div> <div class="p-2 border">Five</div> <div class="p-2 border">Six</div> <div class="p-2 border">Seven</div> <div class="p-2 border">Eight</div> <div class="p-2 border">Nine</div> <div class="p-2 border">Ten</div> <div class="p-2 border">Eleven</div> <div class="p-2 border">Twelve</div> <div class="p-2 border">Thirteen</div> <div class="p-2 border">Fourteen</div> </div><br> <p>Flex items won't wrap (medium screen size)</p> <div class="d-flex flex-md-nowrap bg-success"> <div class="p-2 border">One</div> <div class="p-2 border">Two</div> <div class="p-2 border">Three</div> <div class="p-2 border">Four</div> <div class="p-2 border">Five</div> <div class="p-2 border">Six</div> <div class="p-2 border">Seven</div> <div class="p-2 border">Eight</div> <div class="p-2 border">Nine</div> <div class="p-2 border">Ten</div> <div class="p-2 border">Eleven</div> <div class="p-2 border">Twelve</div> <div class="p-2 border">Thirteen</div> <div class="p-2 border">Fourteen</div> </div> </div> </body> </html>