1

How do I place a button at the bottom and center of an image? I currently have a carousel with multiple images which works fine, but when I try to add a button for navigation purposes it is positioned outside of the image to the right.

Here is the HTML:

<div class="swiper-container">
    <div class="swiper-wrapper">
        <div class="swiper-slide">
            <img src="">
            <button type="button" class="btn btn-success">Click Me</button>
        </div>
    </div>
</div>
4
  • Can't help you without seeing your CSS. You'll need to be using the right combination of position: relative and position: absolute with the right elements to achieve what you want. Commented Mar 6, 2021 at 15:22
  • @codeth why do you need to see his css for it? No matter what, the css will work the same by using an absoltue positioning and a z-index. Commented Mar 6, 2021 at 15:23
  • @tacoshy Sure, but there are classes assigned and therefore clearly existing CSS. To help solve the problem appropriately it is useful to understand what the actual problem is. Commented Mar 6, 2021 at 15:31
  • @codeth those are satndard bootstrap classes. they wont interfere with custom css. Commented Mar 6, 2021 at 15:36

1 Answer 1

2

use position: relative; ont he wrapping parent then use position:absoltue; on the button. you can align it to the bottom by using bottom: 0; To cenetr an element in an absoltue positioning you have to use transform

div.swiper-slide {
  width: 400px;
  position: relative;
}

img {
  object-fit: contain;
}

div.swiper-slide > button {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}
<div class="swiper-wrapper">
  <div class="swiper-slide">
    <img src="https://via.placeholder.com/400x400.jpg">
    <button type="button" class="btn btn- success">click me</button>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.