使用 Bootstrap 4 在特定屏幕尺寸上创建 flexbox 容器
使用 Bootstrap 中的 .d-*-flex 类,可以在特定屏幕尺寸上创建 flexbox 容器。
针对不同的屏幕尺寸,可使用“d-sm-flex”、“d-md-flex” 等,如下所示 −
<span class="d-sm-flex bg-warning"> Small Screen </span> <span class="d-md-flex bg-info"> Medium Screen </span> <span class="d-lg-flex bg-success"> Large Screen </span> <span class="d-xl-flex bg-danger"> Extra Large Screen </span>
上述 flex-items 针对小、中、大、超大屏幕尺寸进行设置。
接下来我们看看该类的示例及其实现 −
示例
<!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://ajax.googleapis.com/ajax/libs/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"> <h2>Flex Example</h2> <div class="d-flex bg-primary">d-flex</div> <span class="d-sm-flex bg-warning">d-sm-flex</span> <span class="d-md-flex bg-info">d-md-flex</span> <span class="d-lg-flex bg-success">d-lg-flex</span> <span class="d-xl-flex bg-danger">d-xl-flex</span> </div> </body> </html>
广告