Is it possible to position different elements on the BootstrapVue Carousel slide without any limitations (in any corner, any position)?
I have tried to do that by nesting more elements inside
<b-carousel-slide></b-carousel-slide>
tags.
However, it looks like all those elements get inside the div.carousel-caption
and I can't move them outside that div.
I would like to put buttons in the top-right and bottom-left corner of carousel-slide, but I constantly get results like this:
As you can see, all elements are concentrated inside the caption div...
I have three questions:
My code:
<b-carousel
id="story-carousel"
controls
indicators
:interval = "3000"
>
<b-carousel-slide
text="asdasdasdsa"
img-src="https://picsum.photos/1024/480/?image=10">
<b-link>
LINK
</b-link>
<b-avatar size="md" variant="primary" icon="bookmark-heart" class="ml-2 highlight-button" button
</b-avatar>
</b-carousel-slide>
</b-carousel>
And CSS:
.highlight-button{
position: absolute;
top: 0;
right: 0;
}
You could use the img
slot of <b-carousel-silde>
to add the extra content, and use CSS to move that content plus the indicators and caption to the top:
Within <b-carousel-slide>
, insert a <template #img>
(the img
slot).
Within that img
slot, insert a <b-img>
with the src
that you originally had for <b-carousel-slide>.imgSrc
.
Add a <div>
with class carousel-extra-content
, and move the <b-link>
and <b-avatar>
into it.
<template>
<b-carousel>
<b-carousel-slide text="asdasdasdsa">
<template #img> 1️⃣
<b-img
fluid-grow
src="https://picsum.photos/1024/480/?image=10"
alt="Random image"
></b-img> 2️⃣
<div class="carousel-extra-content"> 3️⃣
<b-link> LINK </b-link>
<b-avatar
size="md"
variant="primary"
icon="bookmark-heart"
class="ml-2 highlight-button"
button
>
</b-avatar>
</div>
</template>
</b-carousel-slide>
</b-carousel>
</template>
Style the .carousel-extra-content
to place that element in the top-right corner; and to allow clicks on the content by using a higher z-index
than the arrow controls.
Also style .carousel-indicators
and .carousel-caption
to move them to the top of the slide. Setting top
is enough because they're already using absolute positioning.
<style>
// 4️⃣
.carousel-extra-content {
position: absolute;
right: 5em;
top: 1em;
z-index: 20; /* overlap arrow controls to allow clicks */
}
// 5️⃣
.carousel-indicators {
top: 1em;
}
.carousel-caption {
top: 1.5em;
}
</style>