The below code worked perfectly fine for me using Bootstrap version 3. However, since upgrading to Bootstrap 4 Beta2 the fade transition does not work. It just jumps to the next image rather than a smooth transition:
HTML
<div id="carousel1" class="carousel fade" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel1" data-slide-to="0" class="active"></li>
<li data-target="#carousel1" data-slide-to="1"></li>
<li data-target="#carousel1" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="item active"><img src="images/a.jpg" alt="First slide image" class="center-block">
<div class="carousel-caption">
<h3>First slide Heading</h3>
<p>First slide Caption</p>
</div>
</div>
<div class="item"><img src="images/b.jpg" alt="Second slide image" class="center-block">
<div class="carousel-caption">
<h3>Second slide Heading</h3>
<p>Second slide Caption</p>
</div>
</div>
<div class="item"><img src="images/c.jpg" alt="Third slide image" class="center-block">
<div class="carousel-caption">
<h3>Third slide Heading</h3>
<p>Third slide Caption</p>
</div>
</div>
</div>
<a class="left carousel-control" href="#carousel1" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel1" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
CSS
.carousel.fade {
opacity: 1;
}
.carousel.fade .item {
transition: opacity ease-out .7s;
left: 0;
opacity: 0; /* hide all slides */
top: 0;
position: absolute;
width: 100%;
display: block;
}
.carousel.fade .item:first-child {
top: auto;
opacity: 1; /* show first slide */
position: relative;
}
.carousel.fade .item.active {
opacity: 1;
}
JS
$(function(){
$('.carousel').carousel({
interval: 6000
});
});
Looking around and it seems that there has been a few issues with the recent bootstrap upgrade, any help would be appreciated.
As you have already noticed, quite a lot of things have been changed in Bootstrap 4. Let me walk you through the approach I took with the solution below.
.fade was renamed to .carousel-fade not to interfere with the default Bootstrap .fade class.
.item was renamed to .carousel-item, since that is the name in Bootsrap 4 for carousel items.
As the positioning of the slides is absolute now because of the fading effect, I added .embed-responsive embed-responsive-16by9 classes to .carousel-inner and also .embed-responsive-item to .carousel-item to preserve the height of the slide container and also to take care of the positioning of the slide items. (In case you want to use images with other aspect ratios, you should change the .embed-responsive-16by9 class. Defaults are listed here.)
So this would be my approach:
.carousel.carousel-fade .carousel-item {
display: block;
opacity: 0;
transition: opacity ease-out .7s;
}
.carousel.carousel-fade .carousel-item.active {
opacity: 1 !important;
}
<div id="carousel-fade" class="carousel carousel-fade" data-ride="carousel" data-interval="2000">
<ol class="carousel-indicators">
<li data-target="#carousel-fade" data-slide-to="0" class="active"></li>
<li data-target="#carousel-fade" data-slide-to="1"></li>
<li data-target="#carousel-fade" data-slide-to="2"></li>
</ol>
<div class="carousel-inner embed-responsive embed-responsive-16by9" role="listbox">
<div class="carousel-item embed-responsive-item active">
<img src="http://via.placeholder.com/1600x900/483D8B/ffffff?text=Slide%201" alt="First slide image" class="img-fluid">
<div class="carousel-caption">
<h3>First slide Heading</h3>
<p>First slide Caption</p>
</div>
</div>
<div class="carousel-item embed-responsive-item">
<img src="http://via.placeholder.com/1600x900/9400D3/ffffff?text=Slide%202" alt="Second slide image" class="img-fluid">
<div class="carousel-caption">
<h3>Second slide Heading</h3>
<p>Second slide Caption</p>
</div>
</div>
<div class="carousel-item embed-responsive-item">
<img src="http://via.placeholder.com/1600x900/FF1493/ffffff?text=Slide%203" alt="Third slide image" class="img-fluid">
<div class="carousel-caption">
<h3>Third slide Heading</h3>
<p>Third slide Caption</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carousel-fade" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-fade" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
Two more notes:
You can also set the change interval via the data-interval attribute of the .carousel.
The markup of the carousel controls have also been changed in Bootstrap 4.
Related
Hello I have a Carousel in bootstrap with a video in it
The main problem I can't fix is that video controls cannot be clicked because of the carousel indicators.
I tried to add some margin and padding to them and it worked for the begging and the end of the video (where the two coincide, but then in the middle of the seeking bar I can't click without any reason). If I didn't explain me please let me know.
I couldn't add any snippet but you can see what I am trying to explain on my site: Here
HTML:
<div id="carousel-home" class="carousel slide carousel-fade" data-ride="carousel" data-interval="false">
<ol class="carousel-indicators">
<li data-target="#carousel-home" data-slide-to="0" class="active"></li>
<li data-target="#carousel-home" data-slide-to="1" id="slide_1"></li>
<li data-target="#carousel-home" data-slide-to="2" id="slide_2"></li>
<li data-target="#carousel-home" data-slide-to="3" id="slide_3"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<video id="myvideo" class="crop" poster="imgs/video_thumb.jpg" preload="auto" playsinline controls>
<source src="vid/video_2019.mp4" type="video/mp4" onclick="this.play();">
</video>
</div>
<div class="carousel-item">
<img class="d-block w-100 mx-auto" src="imgs/slider/1.png" alt="First slide">
<div class="carousel-caption">
<h2 class="title" style="text-shadow: 1px 1px black">First</h2>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100 mx-auto" src="imgs/slider/2.png" alt="Second slide">
<div class="carousel-caption">
<h2 class="title" style="text-shadow: 1px 1px black">Second</h2>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100 mx-auto" src="imgs/slider/3.png" alt="Third slide">
<div class="carousel-caption">
<h2 class="title" style="text-shadow: 1px 1px black">Third</h2>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carousel-home" role="button" data-slide="prev" id="carousel_l">
<i class="fa fa-chevron-left"></i>
<span class="sr-only">Back</span>
</a>
<a class="carousel-control-next" href="#carousel-home" role="button" data-slide="next" id="carousel_r">
<i class="fa fa-chevron-right"></i>
<span class="sr-only">Next</span>
</a>
</div>
CSS:
.carousel-indicators li {
margin-bottom: 2rem;
padding-bottom: 1rem;
padding-top: 1rem;
border-radius: 100%;
}
.carousel-item img {
object-fit: cover
}
.carousel-item {
overflow:hidden;
}
JQuery:
$(window).ready(function() {
$('#carousel_l').on("click", function() {
$('#myvideo').get(0).pause();
});
$('#carousel_r').on("click", function () {
$('#myvideo').get(0).pause();
});
$('#slide_1').on("click", function () {
$('#myvideo').get(0).pause();
});
$('#slide_2').on("click", function () {
$('#myvideo').get(0).pause();
});
$('#slide_3').on("click", function () {
$('#myvideo').get(0).pause();
});
});
You can use
.carousel-indicators {
pointer-events: none;
}
.carousel-indicators > li {
pointer-events: auto;
}
to remove the interactivity of the carousel indicators.
Pardon me if I am asking something silly, but I have a requirement to create a full page slider with solid color as background and some text on left side and an image on right. Something like Google's Gmail Page.
Currently the result I want is
I have used Bootstrap 4's Carousel
I have modified it slightly and made its background grey as its in Google's image. Now I want the text to be left aligned and have a responsive auto resizeable image on the right (Or even if I can have an image adjusted on the top of the text only) which is also responsive when viewed on mobile. Something like
.
I am using this fiddle and I have modified the code as
<div class="carousel-item" style="background-color: #eff0f1">
<div class="carousel-caption d-none d-md-block">
<h2 class="display-4">First Slide</h2>
<p class="lead">This is a description for the first slide.</p>
</div>
</div>
<style>
.carousel-item {
background-color: #eeeeee; /*Solid grey background*/
}
.carousel-caption {
color: black;
}
</style>
Remove d-none class from carousel-caption and try this way :
.carousel-item {
height: 100vh;
min-height: 350px;
background: no-repeat center center scroll;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.text_part{
display: none;
}
#media (max-width: 575px){
.text_part{
display: block;
}
.left_part{
display: none;
}
}
<section class="text_part">
<div class="text">
<h2 >your text</h2>
</div>
</section>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<!-- Slide One - Set the background image for this slide in the line below -->
<div class="carousel-item active" style="background-color: gray">
<div class="carousel-caption d-md-block">
<div class="row">
<div class="col-md-6 left_part">
your text
</div>
<div class="col-md-6 col-sm-12">
img
</div>
</div>
</div>
</div>
<!-- Slide Two - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-color: pink">
<div class="carousel-caption d-md-block">
<div class="row">
<div class="col-md-6 left_part">
your text
</div>
<div class="col-md-6 col-sm-12">
img
</div>
</div>
</div>
</div>
<!-- Slide Three - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-color: green">
<div class="carousel-caption d-md-block">
<div class="row">
<div class="col-md-6 left_part">
your text
</div>
<div class="col-md-6 col-sm-12">
img
</div>
</div>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
I have a carousel that is centered and only takes half the screen by adding this to the class "w-50". When the browser resizes to a smaller screen, like a mobile device, I want that carousel to take up the whole width of the screen. To do this I'm sure I'll need to find a way to change that to "w-100", but I'm not sure how to go about doing that.
I have tried to play around with #media in CSS, but haven't had any luck.
<div id="catalogueSelection">
<div id="catalogueCarousel" class="carousel slide w-50" data-ride="carousel" data-interval="5000">
<ol class="carousel-indicators">
<li data-target="#catalogueCarousel" data-slide-to="0" class="active"></li>
<li data-target="#catalogueCarousel" data-slide-to="1"></li>
<li data-target="#catalogueCarousel" data-slide-to="2"></li>
<li data-target="#catalogueCarousel" data-slide-to="3"></li>
<li data-target="#catalogueCarousel" data-slide-to="4"></li>
<li data-target="#catalogueCarousel" data-slide-to="5"></li>
<li data-target="#catalogueCarousel" data-slide-to="6"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img id="franceImage" class="d-block w-100" src="../images/france.jpg">
<div class="carousel-caption countryCaption">
<h2>France</h2>
<p>See Products</p>
</div>
</div>
<div class="carousel-item">
<img id="italyImage" class="d-block w-100" src="../images/italy.jpg">
<div class="carousel-caption countryCaption">
<h2>Italy</h2>
<p>See Products</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="../images/spain.jpg">
<div class="carousel-caption countryCaption">
<h2>Spain</h2>
<p>See Products</p>
</div>
</div>
<div class="carousel-item">
<img id="lebanonImage" class="d-block w-100" src="../images/lebanon.jpg">
<div class="carousel-caption countryCaption">
<h2>Lebanon</h2>
<p>See Products</p>
</div>
</div>
<div class="carousel-item">
<img id="southAfricaImage" class="d-block w-100" src="../images/south_africa.jpg">
<div class="carousel-caption countryCaption">
<h2>South Africa</h2>
<p>See Products</p>
</div>
</div>
<div id="southAmericaImage" class="carousel-item">
<img class="d-block w-100" src="../images/south_america.jpg">
<div class="carousel-caption countryCaption">
<h2>South America</h2>
<p>See Products</p>
</div>
</div>
<div id="domesticImage" class="carousel-item">
<img class="d-block w-100" src="../images/united_states.jpg">
<div class="carousel-caption countryCaption">
<h2>Domestic</h2>
<p>See Products</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#catalogueCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#catalogueCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
#catalogueCarousel {
margin: auto;
border: 3px solid;
border-color: black;
}
.carousel-inner {
}
.carousel-item img {
height: 500px; !important
overflow: hidden;
opacity: 0.9;
opacity: 0.8;
}
.countryCaption h2 {
color: red;
font-family: 'Prosto One', cursive;
opacity: 1; !important
}
.countryCaption p{
color: darkred;
font-weight: bold;
font-family: 'Prosto One', cursive;
font-size: 20px;
opacity: 1; !important
}
Above is a snippet of the carousel html code, as well as it's stylesheet.
Any tips or ideas to help me resolve this is appreciated.
Thank you.
You can try using a combination of media queries and the !important rule.
Assuming 768px is your mobile breakpoint:
#media(max-width:768px){
#catalogueCarousel {
width: 100% !important;
}
}
Alternatavely you could use jQuery:
function resizeCarousel() {
if($window.width() < 768) {
$('#catalogueCarousel')
.removeClass('w-50')
.addClass('w-100');
} else {
$('#catalogueCarousel')
.removeClass('w-100')
.addClass('w-50');
}
}
resizeCarousel();
$window.resize(resizeCarousel);
You just need add media query for small device. Add below CSS in style sheet i hope it'll resolve your issue. Thanks
#media only screen and (max-width: 768px) {
#catalogueCarousel {
width: 100% !important;
}
}
I'm trying to make a bootstrap carousel. However, I'm trying to make one of the slides consist of 3 images that sit next to each other wrapped in a div.
All the other slides in the show are centered and look nice enough, but the slide that consists of 3 img wrapped in a div just keeps floating to the left of the page even though I haven't told them to.
I will include code.
Carousel
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="images/jumbotron.jpg" alt="cd release promo">
</div>
<div class="item">
<img src="images/Coldclock Knockout Local 662 (10).jpg" alt="Robby and Ryan in blue">
</div>
<!-- Div containing 3 images -->
<div id="ryanSlide" class="item">
<div id="ryanSlideContainer">
<img src="images/Coldclock Knockout Local 662 (38).jpg" alt="Ryan 1">
<img src="images/Coldclock Knockout Local 662 (46).jpg" alt="Ryan 2 B&W">
<img src="images/Coldclock Knockout Local 662 (47).jpg" alt="Ryan 3">
</div>
</div>
<div class="item">
<img src="images/Coldclock Knockout Local 662 (48).jpg" alt="Crowd Shot">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
CSS + bootstrap is also being used on this page
body {
background-color: black;
}
/*================================================================================================
NAVIGATION
================================================================================================*/
.active {
border-bottom: 1px solid red;
}
.navbar-inverse .navbar-nav > .active > a{
font-size: 1.25em;
}
#navigation {
margin-bottom: 0px;
border-radius: 0px;
}
/*================================================================================================
JUMBOTRON
================================================================================================*/
#myCarousel img {
height: 500px;
margin: 0 auto;
}
#ryanSlide {
margin: 0 auto;
width: 100%;
}
#ryanSlideContainer {
margin: 0 auto;
}
#ryanSlide img {
margin: 0 auto;
}
/*================================================================================================
================================================================================================*/
I'm not using any custom javascript.
I just cant seem to figure out how to get the one slide to center itself like the others.
You can technically put anything in a carousel, it doesn't need to just be a single image, so you could just use bootstrap columns to do it.
For example:
<div id="ryanSlide" class="item">
<div class="col-md-4">
<img src="" class="img-responsive center-block" alt=""/>
</div>
<div class="col-md-4">
<img src="" class="img-responsive center-block" alt=""/>
</div>
<div class="col-md-4">
<img src="" class="img-responsive center-block" alt=""/>
</div>
</div>
Okay, so I'm trying to get a webpage to show a Bootstrap image carousel, which works! But I want some text to the right of it. I'm not trying to get the text to change with the image, just be to the side.
Here is the HTML for the page;
http://pastebin.com/EabGfv3H#
And here is the custom CSS I'm using;
http://pastebin.com/MEtF1hTR
And a JSFiddle;
http://jsfiddle.net/swfour/52VtD/3942/
Needed code for JSFiddle link, so here is the html;
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<div id="carousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel" data-slide-to="0" class="active"></li>
<li data-target="#carousel" data-slide-to="1"></li>
<li data-target="#carousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="images/Beaches and Villages\Golden Beach umbrellas home.JPG" alt="...">
<div class="carousel-caption">
Golden Beach
</div>
</div>
<div class="item">
<img src="images/Beaches and Villages\Limenas ancient city.jpg" alt="...">
<div class="carousel-caption">
Limenas
</div>
</div>
<div class="item">
<img src="images/Beaches and Villages\Potos sunset.JPG" alt="...">
<div class="carousel-caption">
Potos
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<div id="carousel_text" class="col-md-6">
<div>
<p>
Thasos, an island surrounded by the crystal-clear emerald waters of the Aegean Sea is part of the Northeastern islands of
Greece, also being the closest one to the continent. It is the perfect getaway for holidays during summer, a place where
you can relax and enjoy your holidays, forget about all your worries on a quiet sandy beach, but also a place where you
can explore the Greek way of life, try the best foods and meet the most amazing people.
</p>
</div>
</div>
</div>
I've tried not using the bootstrap columns and just using float left and right, which didn't work.
From your image mockup, I assume you need the carousel on some 75% width while the other text/div on remaining 25% width within your main container. OR the text/div should be outside of carousel.
So if that's the case, try using this -
add a new class carousel-left to <div id="carousel-example-generic" class="carousel slide carousel-left" data-ride="carousel">
add/update your text-div in html as shown below:
<div class="bs-example" data-example-id="simple-carousel">
<div id="carousel-example-generic" class="carousel slide carousel-left" data-ride="carousel">...</div>
<div class="some-text">your text div</div>
</div>
add following in your css -
.carousel-left { width: 75%; float: left; }
.some-text { float: left; width: 25%; }
Hope it helps.
I add pull-left class to img, and add pull-right class to your text and place it inside <span> not <div> and remove carousel-caption from it.seems to work Pluncker
<div class="item">
<img class="pull-left" src="images/Beaches and Villages\Limenas ancient city.jpg" alt="...">
<span class="pull-right">
Limenas
</span>
</div>