Carousel to display full width of screen for small screens only - html

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;
}
}

Related

Slider not fitting span of window css issue?

Hi everyone nice to be here on stackoverflow, I'm just having a bit of trouble fitting the slider to the span of the window happens in every browser any ideas would be very greatful. Thank you in advance. I have added the CSS and HTML code below this comment.
Hi everyone nice to be here on stackoverflow, I'm just having a bit of trouble fitting the slider to the span of the window happens in every browser any ideas would be very greatful. Thank you in advance. I have added the CSS and HTML code below this comment.
Snapshot of site im working on
/*-----Slider-----*/
#slider{
width: 100%;
margin: auto;
font-family: Chakra Petch;
}
.carousel-caption{
top: 50%;
transform: translateY(-50%);
bottom: initial !important;
}
.h1-0{
color: black !important;
font-size: 40px;
font-weight: bold;
background: #fff !important;
opacity: 0.8;
}
.h1-1{
color: black !important;
font-size: 40px;
font-weight: bold;
background: #fff !important;
opacity: 0.8;
}
.h1-2{
color: black !important;
font-size: 40px;
font-weight: bold;
background: #fff !important;
opacity: 0.8;
}
.h1-3{
color: black !important;
font-size: 40px;
font-weight: bold;
background: #fff !important;
opacity: 0.8;
}
<!-- Slider -->
<div id="slider" data-aos="fade-up" data-aos-duration="2000" data-aos-delay="1300">
<div id="headerSlider" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#headerSlider" data-slide-to="0" class="active"></li>
<li data-target="#headerSlider" data-slide-to="1"></li>
<li data-target="#headerSlider" data-slide-to="2"></li>
<li data-target="#headerSlider" data-slide-to="3"></li>
<li data-target="#headerSlider" data-slide-to="4"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="img/welcome-slider-image.jpg" class="d-block img-fluid" alt="Welcome Image">
</div>
<div class="carousel-item">
<img src="img/webdesign-image.jpg" class="d-block img-fluid" alt="Website Design Image">
<div class="carousel-caption">
<h1 class="h1-0">Web Site Design</h1>
</div>
</div>
<div class="carousel-item">
<img src="img/seo-slider-image.jpeg" class="d-block img-fluid" alt="SEO Image">
<div class="carousel-caption">
<h1 class="h1-1">Search Engine Optimization<br></h1>
</div>
</div>
<div class="carousel-item">
<img src="img/software-development-slider-image.png" class="d-block img-fluid" alt="App Development Image">
<div class="carousel-caption">
<h1 class="h1-2">App & Software Development<br></h1>
</div>
</div>
<div class="carousel-item">
<img src="img/cyber-security.jpg" class="d-block img-fluid" alt="Software Development Image">
<div class="carousel-caption">
<h1 class="h1-3">Cyber Security<br></h1>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#headerSlider" 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="#headerSlider" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>

Position a PNG image inside a div carousel

After several searches I cannot find an example of what I want to do.
I have a carousel, and my mission is to place a png image in the carousel like this :
As you can see, the png exceed slightly from the top of the div
This is what i already tried : https://codepen.io/MehdiX/pen/jOEaJox?editors=1100
But is don't work, as you can see, when i make a negatif pixel, the borders of the png image are no longer visible.
I use position: absolute; on my png image, and position: relative; on the carousel div, but it doesn't seem to work. I do not know if I should act on the div of the carousel or that of the image (which is already in relative)
HTML :
<main id="home_part" class="row" role="main">
<article>
<div id="carousel_presentation" class="col-md-12">
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="false">
<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">
<div class="carousel-item active">
<img src="https://images.pexels.com/photos/204993/pexels-photo-204993.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500" class="d-block w-100" alt="...">
<img src="https://retohercules.com/images/foto-png-online-8.png" class="women_png_sticky" alt="">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img src="..." class="d-block w-100" alt="...">
</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>
<div class="col-md-12 text-center py-5">
<div class="container">
<h2 class="mb-3">Laissez-vous emporter par le bien-être !</h2>
<p class="lead">Échappez au stress du monde moderne et venez nous retrouver dans notre institut de soins. Vous y trouverez sérénité et bien-être dans un environnement calme et apaisant.</p>
</div>
</div>
</div>
</article>
</main>
#carousel_presentation {
font-family: main, "Palatino Linotype", "Book Antiqua", Palatino, serif;
padding: 0;
color: #565656;
background-color: #FFF989;
position:relative;
}
.women_png_sticky {
margin-top:-600px;
}
#carousel_presentation h2 {
font-size: 2rem;
text-transform: uppercase;
}
#media only screen and (max-width: 780px) {
#carousel_presentation h2 {
font-size: 1.5rem;
}
}
#media only screen and (max-width: 560px) {
#carousel_presentation h2 {
font-size: 1rem;
text-decoration: underline;
}
#carousel_presentation p {
font-size: 1rem;
}
}
And i would to know if exist a simple solution, like canvas in javascript, or CSS, to manage this type of positioning ?
You have in your carousel.scss in line 25 an overflow: hidden rule that's hiding the image.
.carousel-inner {
position: relative;
width: 100%;
overflow: hidden;
#include clearfix();
}
You can make a more specific selector to overwrite the overflow:
div.carousel-inner { overflow: visible }
Check the fork in codepen: https://codepen.io/rafaelcastrocouto/pen/JjoOqXy?editors=1100

HTML5 VIdeo Controls visibility / z-index

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.

Center responsive bootstrap carousel

I'm trying to fully customize a bootstrap carousel. I need to have it on the sidebar with the indicators at the bottom(outside the carousel). So far I was I able to make it work on large screens, but on smaller screens, the carousel refuse to be centered in the middle. Is there is a way to keep it centered (without using margin)? Thanks in advance
The current result:
The HTML of the element in question:
.other-articles {
padding: 1.2rem;
}
.other-articles>h3 {
font-size: .8rem;
}
.others {
padding: 1.2rem;
margin-top: 1.2rem;
margin-bottom: 1.2rem;
}
.other-places {
margin-top: 1.5rem;
}
.flex-other-articles {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
}
.item-other-articles {
display: flex;
align-items: center;
border-bottom: 1px solid rgba(162, 163, 163, 0.344);
margin-top: .2rem;
}
.last-it-oth {
border-bottom: none !important;
}
.item-other-articles img {
border-radius: 3px;
margin-top: -.7rem;
height: 50px;
width: 56px;
flex-grow: 0;
flex-shrink: 0;
}
.item-other-articles-txt {
margin-left: .7rem;
}
.item-other-articles-txt>h6 {
font-size: .7rem;
}
.item-other-articles-txt>p {
font-size: .6rem;
}
#media (max-width:965px) and (min-width:780px) {
.other-articles {
text-align: center;
}
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<div class="others block">
<h6>OTHER PLACE</h6>
<div class="other-place-dots">
<i class="fas fa-circle"></i>
<i class="fas fa-circle"></i>
<i class="fas fa-circle"></i>
</div>
<div class="the-mini-slider-on-the-sidebar container-fluid">
<div id="carouselExample" class="carousel slide" data-ride="carousel">
<div class="carousel-inner mini-carousel-img">
<div class="carousel-item">
<img class="d-block w-100 " src="https://i.imgur.com/lCcKhji.jpg" alt="First slide">
<div class="carousel-caption d-none d-md-block cap-1-black">
<div class="carr-text-img">
<h5>Ski Lifts</h5>
</div>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="https://i.imgur.com/lCcKhji.jpg" alt="Second slide">
<div class="carousel-caption d-none d-md-block cap-1-black">
<div class="carr-text-img">
<h5>Ski Lifts</h5>
</div>
</div>
</div>
<div class="carousel-item active">
<img class="d-block w-100" src="https://i.imgur.com/lCcKhji.jpg" alt="Third slide">
<div class="carousel-caption d-none d-md-block cap-1-black">
<div class="carr-text-img">
<h5>Ski Lifts</h5>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExample" 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="#carouselExample" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<div class="carousel slide carousel-in-li" data-ride="carousel">
<ol class="carousel-indicators carousel-in-1">
<li data-target="#carouselExample" data-slide-to="0" class=""></li>
<li data-target="#carouselExample" data-slide-to="1" class=""></li>
<li data-target="#carouselExample" data-slide-to="2" class="active"></li>
</ol>
</div>
</div>
</div>
</div>

Bootstrap 4: Carousel Fade Transition Not Working

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.