要最后证明弹性项,请使用 justify-content-end 类。
要在不同的屏幕尺寸上最后调整弹性项目,请使用justify-content-*-end类。在不同的屏幕尺寸下,末尾对齐的flex项目将如下所示-
小屏幕尺寸
<div class="d-flex justify-content-sm-end bg-danger mb-5"> <div class="p-2 bg-primary">Alabama</div> <div class="p-2 bg-info">New York</div> <div class="p-2 bg-secondary">Texas</div> </div>
中等屏幕尺寸
<div class="d-flex justify-content-md-end bg-danger mb-5"> <div class="p-2 bg-primary">Alabama</div> <div class="p-2 bg-info">New York</div> <div class="p-2 bg-secondary">Texas</div> </div>
让我们看完整的代码并学习如何使用justify-content-*-end类-
<!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"> <h3>US</h3> <div class="d-flex justify-content-sm-end bg-danger mb-5"> <div class="p-2 bg-primary">Alabama</div> <div class="p-2 bg-info">New York</div> <div class="p-2 bg-secondary">Texas</div> </div> <div class="d-flex justify-content-md-end bg-danger mb-5"> <div class="p-2 bg-primary">Alabama</div> <div class="p-2 bg-info">New York</div> <div class="p-2 bg-secondary">Texas</div> </div> <div class="d-flex justify-content-lg-end bg-danger mb-5"> <div class="p-2 bg-primary">Alabama</div> <div class="p-2 bg-info">New York</div> <div class="p-2 bg-secondary">Texas</div> </div> </div> </body> </html>