简体   繁体   English

Bootstrap 4警报框关闭按钮未对齐

[英]Bootstrap 4 alert box close button not aligned

I'm using bootstrap and I currently have an alert box:我正在使用引导程序,目前有一个警告框:

<div class="alert alert-secondary alert-dismissible" id="delAlbumAlert">
  <span><strong>Delete Album!</strong> Select the album(s) you want to delete.</span>
  <button type="button" class="close" aria-label="Close" onclick="return handleOptions($('#btnDeleteAlbum'));">
    <span aria-hidden="true" style="color:black;">&times;</span>
  </button>
</div>

The close button is not aligned vertically.关闭按钮未垂直对齐。 Here is how it shows up.这是它的显示方式。

图像

How can I make the button aligned?如何使按钮对齐? I tried using the <div clas="alert..." style="top: -4px;"> and it kind of worked but I was wondering if there is a better approach.我尝试使用<div clas="alert..." style="top: -4px;">并且它有点工作,但我想知道是否有更好的方法。

Override the padding-top property of the button like the following: 覆盖按钮的padding-top属性,如下所示:

 .close { padding-top: .60rem !important; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> <div class="alert alert-secondary alert-dismissible" id="delAlbumAlert"> <span><strong>Delete Album!</strong> Select the album(s) you want to delete.</span> <button type="button" class="close" aria-label="Close" onclick="return handleOptions($('#btnDeleteAlbum'));"> <span aria-hidden="true" style="color:black;">&times;</span> </button> </div> 

You can remove the class alert-dismissable because it's not necessary to make the alert dismissable, this class only has styling purposes.您可以删除 class alert-dismissable因为没有必要使警报可关闭,此 class 仅具有样式目的。 You can use flexbox to align the close-button vertically:您可以使用 flexbox 垂直对齐关闭按钮:

<div class="alert alert-success fade show d-flex justify-content-center align-items-center">
    <i class="fa-duotone fa-circle-exclamation fa-lg me-auto"></i>
    <span class="me-auto px-3">This is a success alert ...</span>
    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>

Important is to use data-bs-dismiss="alert" attribute.重要的是使用data-bs-dismiss="alert"属性。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM