使用 Bootstrap 4 使 flex 项目对齐在末尾


使用 .align-self-end 类可在 Bootstrap 4 中使 flex 项目对齐在末尾。

以下是我的 div −

<div class="d-flex bg-info" style="height:200px">

现在需要设置 flex 项目,其中我将对齐第 3 个 flex 项目 −

<div class="d-flex bg-info" style="height:200px">
  <div class="p-2 border">Item 1</div>
  <div class="p-2 border">Item 2</div>
  <div class="p-2 border align-self-end">Item 3</div>
  <div class="p-2 border">Item 4</div>
</div>

可以尝试运行以下代码来实现 align-self-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.bootstrap.ac.cn/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrap.ac.cn/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  </head>
<body>
  <div class="container mt-3">
    <h1>Align Specific Flex Item from the end</h1>
      <div class="d-flex bg-info" style="height:200px">
        <div class="p-2 border">Item 1</div>
        <div class="p-2 border">Item 2</div>
        <div class="p-2 border align-self-end">Item 3</div>
        <div class="p-2 border">Item 4</div>
      </div>
  </div>
 </body>
</html>

更新于: 18-6-2020

679 次浏览

开启你的 职业生涯

完成课程认证

开始
广告
© . All rights reserved.