Please can anyone guide me on how I can create an element that overlaps both the modal and its overlay inside bootstrap 5 modal.
Thanks in advance
position-absolute
.left
and transform
.const myModal = new bootstrap.Modal('#exampleModal');
myModal.show();
.modal-badge {
margin-top: -50px;
left: 50%;
transform: translateX(-50%);
width: 100px;
height: 100px;
border-radius: 50px;
background: #ddd;
display: flex;
justify-content: center;
align-items: center;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="position-absolute modal-badge">Hi!</div>
<div class="modal-header mt-4">
<h1 class="modal-title fs-5 mt-2" id="exampleModalLabel">Modal title</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.min.js" integrity="sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk" crossorigin="anonymous"></script>