How to make bootstrap corousal responsive - css

I am making bootstrap corousal of full width and height,The height is responsive but the width is not responsive (i.e) when i resize the window the image starts crop according to the width of the viewport,when it reaches to mobile screen size the left part the corousal crops,Below is the Bootstrap and css code,Can anyone help hoe to make image width responsive,Thanks
<header id="myCarousel" class="carousel slide">
<!-- 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>
</ol>
<!-- Wrapper for Slides -->
<div class="carousel-inner">
<div class="item active">
<!-- Set the first background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal1.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 2</h2>
</div>
</div>
<div class="item">
<!-- Set the second background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal2.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 2</h2>
</div>
</div>
<div class="item">
<!-- Set the third background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal1jpg.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 3</h2>
</div>
</div>
<div class="item">
<!-- Set the third background image using inline CSS below. -->
<div class="fill" style="background-image:url('images/corousal4.jpg');"></div>
<div class="carousel-caption">
<h2>Caption 3</h2>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="icon-next"></span>
</a>
<div class="drbatras-logo">
<img src="images/logo.png" alt="logo"/>
</div>
</header>
CSS
html,
body {
height: 100%;
}
.carousel,
.item,
.active {
height: 100%;
position: relative;
}
.carousel-inner {
height: 100%;
}
/* Background images are set within the HTML using inline CSS, not here */
.drbatras-logo{
position: absolute;
top:60px;
right: 170px;
}
.fill {
width: 100%;
height: 100%;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}

you can use <img> tag and set class="img-responsive"
<img class="img-responsive" src="img_chania.jpg" alt="Chania" width="460" height="345">

you can use this
<div class="fill" id="fill"> </div>
css
#fill{
background:url('images/corousal1.jpg') no-repeat center center;
background-size:100% auto;
}

Related

Bug with carousel with Bootstrap 4

I trying make a carousel using bootstrap 4, but I have a problem with arrows and cycles. Using bootstrap 3 it's work perfectly, including the CSS. I have already changed the item class to carousel-item as it sends the documentation, but still I am not having success. I think the problem is very simple, but I can not find it. Could someone help me with this? I would appreciate it and apologize if you infiltrate some stackoverflow rule
My code is:
.carousel-control {
left: -12px;
height: 40px;
width: 40px;
background: none repeat scroll 0 0 #222222;
border: 4px solid #FFFFFF;
border-radius: 23px 23px 23px 23px;
margin-top: 90px;
}
.carousel-control.right {
right: -12px;
}
/* The indicators */
.carousel {
margin-bottom: 0;
padding: 0 40px 30px 40px;
}
.carousel-indicators {
right: 50%;
top: auto;
bottom: -10px;
margin-right: -19px;
margin: 0 auto;
}
/* The colour of the indicators */
.carousel-indicators li {
background: #cecece;
}
.carousel-indicators .active {
background: #428bca;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<div id="Carousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#Carousel" data-slide-to="0" class="active"></li>
<li data-target="#Carousel" data-slide-to="1"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="carousel-item active">
<div class="row">
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
</div>
<!--.row-->
</div>
<!--.carousel-item-->
<div class="carousel-item">
<div class="row">
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
<div class="col-md-3">
<img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;">
</div>
</div>
<!--.row-->
</div>
<!--.carousel-item-->
</div>
<!--.carousel-inner-->
<a data-slide="prev" href="#Carousel" class="left carousel-control">‹</a>
<a data-slide="next" href="#Carousel" class="right carousel-control">›</a>
</div>
<!--.Carousel-->
What can be this error?
The icons are not showed because you need to add a inside the tags and you can use predefined classes of bs carousel for controlling it:
<a id="previous" class="carousel-control-prev" href="#carrousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a id="after" class="carousel-control-next" href="#carrousel" data-slide="next">
<span class="carouse`enter code here`l-control-next-icon"></span>
</a>
In order for bootstrap 4 Carousel to work you have to add jquery, popper and bootstrap js files to your project.
You can see in the link a section named Show components requiring JavaScript, in it your can see Carousel for all slide behaviors, controls, and indicators,
In the code you've added there is no sign for theme and this could be your problem.
You can see in this DEMO that your buttons are working. Take a look at index.html file where I've added this js file scripts (removing theme will reproduce your problem where the buttons are not working).

how to control the size of images in carousel

hi guys i hope you all having a good day just in brief my problem is i have a carousel code made by bootstrap and it's working good but the three images that i had inside the carousel they don't have the same height and i wanna make them full width and i tried to control them by their classes but it didn't work and i tried to gave each image a id but the same thing happened again i didn't work .in honestly i'm seeking from this issue and i don't know how i can deal with it so hopefully y'all can help me with that and thanx again.
You could give a fixed height and overflow: hidden; to .carousel-inner .item class.
So the lines to be added will be
.carousel-inner .item{
height: 300px;
overflow: hidden;
}
On doing this, if the image inside any of the slide is greater than the provided height, then the rest of the image will be hidden. But this may not be the best practice as this may hide important portions of the slide images but if you wish to have uniform height for all the slides in the carousel, then probably this is the best option (2nd best if you consider the option of keeping all images of same dimensions).
here is the css of my file
/*------------------------------------------*/
/*Bootstrap button outline override*/
/*------------------------------------------*/
.btn-outline {
background-color: transparent;
color: inherit;
transition: all .2s;
}
.btn-primary.btn-outline {
color: #428bca;
}
.btn-success.btn-outline {
color: #5cb85c;
}
.btn-info.btn-outline {
color: #5bc0de;
}
.btn-warning.btn-outline {
color: #f0ad4e;
}
.btn-danger.btn-outline {
color: #d9534f;
}
.btn-primary.btn-outline:hover,
.btn-success.btn-outline:hover,
.btn-info.btn-outline:hover,
.btn-warning.btn-outline:hover,
.btn-danger.btn-outline:hover {
color: #fff;
}
/*------------------------------------------*/
/*CSS CUSTOMIZE*/
/*------------------------------------------*/
#info-btn { margin-right: 2%; }
/*------------------------------------------*/
/*carousel*/
/*-----------------------------------------*/
.carousel-inner .item{
height: 638px;
overflow: hidden;
}
<!-- Carousel feature -->
<header id="myCarousel" class="carousel slide">
<!-- 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>
</ol>
<!-- Wrapper for Slides -->
<div class="carousel-inner">
<div class="item active">
<!-- Set the first background image using inline CSS below. -->
<img src="img/taxi.jpeg" class="fill">
<div class="carousel-caption">
<h2>Caption 1</h2>
</div>
</div>
<div class="item">
<!-- Set the second background image using inline CSS below. -->
<img src="img/ocean.jpeg" class="fill">
<div class="carousel-caption">
<h2>Caption 2</h2>
</div>
</div>
<div class="item">
<!-- Set the third background image using inline CSS below. -->
<img src="img/nyc.jpeg" class="fill">
<div class="carousel-caption">
<h2>Caption 3</h2>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="icon-next"></span>
</a>
</header>

Bring carousel caption on top of the overlay

I have this Bootstrap carousel:
HTML:
<div id="carousel-example" class="carousel slide" data-ride="carousel">
<div class="carousel-overlay"></div>
<ol class="carousel-indicators">
<li data-target="#carousel-example" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example" data-slide-to="1"></li>
<li data-target="#carousel-example" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="http://placekitten.com/1600/600" />
<div class="carousel-caption">
<h3>Meow</h3>
<p>Just Kitten Around</p>
</div>
</div>
<div class="item">
<img src="http://placekitten.com/1600/600" />
<div class="carousel-caption">
<h3>Meow</h3>
<p>Just Kitten Around</p>
</div>
</div>
<div class="item">
<img src="http://placekitten.com/1600/600" />
<div class="carousel-caption">
<h3>Meow</h3>
<p>Just Kitten Around</p>
</div>
</div>
</div>
<a class="left carousel-control" href="#carousel-example" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
CSS:
.carousel-overlay{
background-color: black;
width: 100%;
opacity: 0.3;
height: 100%;
position: absolute;
z-index: 15;
}
I want the caption and arrow buttons to be on the top the overlay like the carousel indicators. I tried using z-index, but it is not working.
here's a fiddle: http://jsfiddle.net/bM32G/39/
I put the captions and arrow buttons on top of the overlay with z-index in this Fiddle:
http://jsfiddle.net/1xu2fpc8/
I used some !important for simplicity, but it seems to work for me.
To change the color of the content of the carousel you need to refer to, in this case, img. Add the following code to your CSS:
img{
-webkit-filter: sepia(90%) hue-rotate(90deg);
}
Remove or comment out the following line in your HTML:
<div class="carousel-overlay"></div>
You can also look into the following posts:
Tint image using CSS without overlay
CSS image overlay with color and transparency
Since z-index is not working for you..
Try this
.item a img {
opacity: 0.6;
}
.carousel-control {
opacity: 1;
}
.item .carousel-caption {
opacity: 1;
}
FIDDLE

Bootstrap Carousel Pushing and Pulling Content

I am having some issues with my bootstrap carousel. The images that are currently in it are different sizes and switching between images pushes and pulls content of the page. I want a static height and for the pictures to fill the static height while maintaining aspect ratio. Where have I gone wrong here?
Here is the code from the Carousel:
<header id="main_carousel" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#main_carousel" data-slide-to="0" class="active"></li>
<li data-target="#main_carousel" data-slide-to="1" class=""></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="center-block fill" style="background-color:#6A6A6A" src="sample_house_one.jpg" height="inherit" alt="First slide" >
<div class="carousel-caption">
<h3>Next Esate Sale</h3>
<p>July 8th at 9:00 AM</p>
</div>
</div>
<div class="item">
<img class="center-block fill" style="background-color:#6A6A6A" src="Sample_house_two.jpg" height="inherit" alt="Second slide">
<div class="carousel-caption">
<h3>Congrats to the new owners</h3>
<p>Winning bid olny $65,000!!!</p>
</div>
</div>
</div>
<a class="left carousel-control" href="#main_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="#main_carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</header>
Here is the css I'm using with the carousel everything else is standard Bootstrap theme and css:
html,
body {
height: 360px;
}
.carousel {
height: 360px;
}
.carousel-inner > .item img,
.carousel-inner > .item > a > img {
min-height:500px;
max-width: 100%;
}
.item,
.active,
.carousel-inner {
height: 100%;
}
.fill {
width: 100%;
height: 100%;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
footer {
margin: 50px 0;
}
Put a max-height: 500px on your img tag so that way it can't shrink or grow with different picture sizes.
Or better, get rid of the min-height and just define height. If your pictures are cropping oddly, you might want to either use a background-image div or crop them to the same size and aspect ratio in an image editing program for the simplest solultion. Since you're using a carousel, cropping the images ahead of time might be the easiest solution.
You could also just allow the div to overflow and hide scroll bars as well, and use flexbox to position the image in the middle with align-items: center to crop the top and bottom evenly.

Image positioned over container div limit

For better understanding I'm updating the entire question.
I'm using bootstrap 3 and the carousel component, however, one of the pages of the carousel contains an image that needs to be positioned in the bottom of the section tag without resizing the container.
Here is the code I'm using:
<section id="header-slider" class="section carousel slide" data-ride="carousel" style="padding-bottom: 0;">
<!-- Start Slider Navigation -->
<ol class="carousel-indicators">
<li class="active" data-slide-to="0" data-target="#header-slider"></li>
<li data-slide-to="1" data-target="#header-slider" class=""></li>
</ol>
<!-- End Slider Navigation -->
<div class="carousel-inner">
<div class="item row active">
<div class="col-xs-5 hidden-sm">
<img src="..." style="margin-top: -40px">
</div>
<div class="col-xs-7">
<h1>...</h1>
<p>...</p>
</div>
</div>
<div class="item row">
<div class="col-xs-8">
<h1>...</h1>
<p>...</p>
</div>
</div>
</div>
</section>
Here is a running page with the problem: www.remotepark.com.br
You may see that after transitioning to the second page on carousel component, it is resized.
How can I fix this keeping the height of the pages equal (actually all pages need to have the same height as page 2)?
Not sure if I completely understood..
but maybe give this a try and see if it accomplishes what you're aiming for.
<div style="width: 400px; height: 250px; position: relative;">
<div style="width: 400px; height: 150px">
<img src="..." style="width: 200px; height: 200px; position: absolute; bottom: 0;" />
</div>
</div>
Try changing your style.css from
.carousel .item {
padding-top: 50px;
height: 300px;
}
to:
.carousel .item {
height: 290px; /* the image height */
}
also remove:
style="margin-top: -40px" from the image in the first carousel item

Resources