Bootstrap 5 模态页脚左右对齐
Bootstrap 5 modal footer align left and right
有人可以帮我 Bootstrap 5 模态页脚吗?
我想让模态页脚在左侧有一个文本(跨度或标签),在右侧有一个按钮
我找到了 this 解决方案并尝试了(将所有内容从“左”更改为“开始”)但没有用。
我尝试使用 d-flex justify-content-start
,也尝试使用 float-start
,但仍然无法正常工作。
你需要修改一些结构来实现它。
CSS:
.modal-footer {
justify-content: space-between;
}
HTML:
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#inputInv">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="inputInv" tabindex="-1" aria-labelledby="InputInventory" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InputInventory">INPUT DATA</h5>
</div>
<div class="modal-body">
<!-- CONTENT HERE -->
</div>
<div class="modal-footer">
<div>
<span>Example vertically aligned text</span>
</div>
<div class="actions">
<button id="btnInClose" type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
<button id="btnInSave" type="button" class="btn btn-sm btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>
检查 this 示例。
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#inputInv">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="inputInv" tabindex="-1" aria-labelledby="InputInventory" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InputInventory">INPUT DATA</h5>
</div>
<div class="modal-body">
<!-- CONTENT HERE -->
</div>
<div class="modal-footer">
<div class="flex-grow-1 bd-highlight">Example vertically aligned text</div>
<div class="bd-highlight"><button id="btnInClose" type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button></div>
<div class="bd-highlight"><button id="btnInSave" type="button" class="btn btn-sm btn-primary">Save</button></div>
</div>
</div>
</div>
</div>
我认为这可以解决您的问题
刚刚将按钮和文本添加到 div 元素中,并将 class bd-highlight
添加到三个 div 元素中
还添加了 class flex-grow-1
到文本 div 元素
如果您使用的是 Bootstrap-5,则无需为 text
或元素对齐编写 CSS,因此您需要使用预定义的 class es 来自 BS-5.
您只需要在 <span>
或 <label>
中添加 me-auto
class 然后文本将从 左侧 .
呈现
有帮助喜欢:
https://getbootstrap.com/docs/5.1/utilities/flex/
https://css-tricks.com/how-auto-margins-work-in-flexbox/
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary m-5" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<span class="me-auto">Example vertically aligned text</span>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
只需在模态页脚上使用 justify-content-between
class...
<!-- Modal -->
<div class="modal fade" id="inputInv" tabindex="-1" aria-labelledby="InputInventory" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InputInventory">INPUT DATA</h5>
</div>
<div class="modal-body">
<!-- CONTENT HERE -->
</div>
<div class="modal-footer justify-content-between">
<div>
<span>Example vertically aligned text</span>
</div>
<div class="actions">
<button id="btnInClose" type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
<button id="btnInSave" type="button" class="btn btn-sm btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>
有人可以帮我 Bootstrap 5 模态页脚吗?
我想让模态页脚在左侧有一个文本(跨度或标签),在右侧有一个按钮
我找到了 this 解决方案并尝试了(将所有内容从“左”更改为“开始”)但没有用。
我尝试使用 d-flex justify-content-start
,也尝试使用 float-start
,但仍然无法正常工作。
你需要修改一些结构来实现它。
CSS:
.modal-footer {
justify-content: space-between;
}
HTML:
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#inputInv">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="inputInv" tabindex="-1" aria-labelledby="InputInventory" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InputInventory">INPUT DATA</h5>
</div>
<div class="modal-body">
<!-- CONTENT HERE -->
</div>
<div class="modal-footer">
<div>
<span>Example vertically aligned text</span>
</div>
<div class="actions">
<button id="btnInClose" type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
<button id="btnInSave" type="button" class="btn btn-sm btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>
检查 this 示例。
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#inputInv">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="inputInv" tabindex="-1" aria-labelledby="InputInventory" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InputInventory">INPUT DATA</h5>
</div>
<div class="modal-body">
<!-- CONTENT HERE -->
</div>
<div class="modal-footer">
<div class="flex-grow-1 bd-highlight">Example vertically aligned text</div>
<div class="bd-highlight"><button id="btnInClose" type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button></div>
<div class="bd-highlight"><button id="btnInSave" type="button" class="btn btn-sm btn-primary">Save</button></div>
</div>
</div>
</div>
</div>
我认为这可以解决您的问题
刚刚将按钮和文本添加到 div 元素中,并将 class bd-highlight
添加到三个 div 元素中
还添加了 class flex-grow-1
到文本 div 元素
如果您使用的是 Bootstrap-5,则无需为 text
或元素对齐编写 CSS,因此您需要使用预定义的 class es 来自 BS-5.
您只需要在 <span>
或 <label>
中添加 me-auto
class 然后文本将从 左侧 .
有帮助喜欢:
https://getbootstrap.com/docs/5.1/utilities/flex/
https://css-tricks.com/how-auto-margins-work-in-flexbox/
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary m-5" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<span class="me-auto">Example vertically aligned text</span>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
只需在模态页脚上使用 justify-content-between
class...
<!-- Modal -->
<div class="modal fade" id="inputInv" tabindex="-1" aria-labelledby="InputInventory" aria-hidden="true" data-bs-backdrop="static">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="InputInventory">INPUT DATA</h5>
</div>
<div class="modal-body">
<!-- CONTENT HERE -->
</div>
<div class="modal-footer justify-content-between">
<div>
<span>Example vertically aligned text</span>
</div>
<div class="actions">
<button id="btnInClose" type="button" class="btn btn-sm btn-secondary" data-bs-dismiss="modal">Close</button>
<button id="btnInSave" type="button" class="btn btn-sm btn-primary">Save</button>
</div>
</div>
</div>
</div>
</div>