Bootstrap carousel with background - css

My client has bootstrap template. I made a slider there:
Slider
Images are mooving only in laptop. I want to add description to the right side of the laptop (Now sliding description does not work). And have no idea how to do it. Tried many variations.
Or better and faster just to write slider myself, not using Bootstrap?
Will be greatful for any help!
html:
<!-- 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">
<img src="images/people.png" alt="">
</div>
<div class="item">
<img src="images/people.png" alt="">
</div>
<div class="item">
<img src="images/people.png" alt="">
</div>
</div>
<div class="carousel-description current">
<div>Отчёт по результатам обследования в форме документа в PS QUASTIO PRO</div>
</div>
<div class="carousel-description">
<div>Отчёт по результатам обследования в форме документа</div>
</div>
<div class="carousel-description">
<div>Отчёт по результатам обследования</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
CSS:
#myCarousel{
height: 510px;
background: url(../images/computer.png) no-repeat;
background-size: 1350px auto;
}
#myCarousel .carousel-inner{
width: 441px;
height: 250px;
position: absolute;
left: 225px;
top: 24px;
}
.carousel {
margin-bottom: 0;
}
#myCarousel .carousel-inner .item img{
width: 441px;
height: 250px;
}
.carousel-description{
display: none;
width: 25%;
position: absolute;
right: 150px;
top: 185px;
font-size: 20px;
}
.carousel-description.current{
display: block;
}

You can use my code which doesnt use any library and is similar to the pic you attached ,just change the pics path from css.
you can control the speed of slides from changing variable yourinterval
var yourinterval=2000;
DEMO:http://jsbin.com/xegufazuyi/2/edit?html,css,js,output

Related

How to make images fit carousel containers?

I am trying to make all the images of different heights and widths within the carousel the same height matching the size of the carousel container '.carouselWrapper'
https://codepen.io/SashaSashaSasha/pen/MWgepEe
HTML
<div class="carouselWrapper">
<div class="carousel">
<div><img src="https://trendland.com/wp-content/uploads/2019/01/Myles_Pedlar_3.jpg"></div>
<div><img src="https://1aike31wshtt3k0e9u2nxtwz-wpengine.netdna-ssl.com/wp-content/uploads/2019/01/Myles_Pedlar_13-770x1090.jpg"></div>
<div><img src="https://trendland.com/wp-content/uploads/2019/01/Myles_Pedlar_3.jpg"></div>
<div><img src="https://1aike31wshtt3k0e9u2nxtwz-wpengine.netdna-ssl.com/wp-content/uploads/2019/01/Myles_Pedlar_13-770x1090.jpg"></div>
</div>
</div>
CSS
img {
max-width:100%;
max-height:100%;
margin: auto;
}
.carouselWrapper {
margin: 0px;
height: 80vh;
width: 100
}
.carousel{
width: 100%;
height: 100%;
margin:0px auto;
}
.slick-slide{
margin: 10px;
}
.slick-slide img{
width: 100%;
}
Try to see this example. Hoping this is what you're looking for. All the best!
.carousel-inner .item{ height:500px; background-size:cover;background-position: center center;}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<br>
<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" style="background-image: url(//placehold.it/1024x700) ">
</div>
<div class="item" style="background-image: url(//placehold.it/100x100) ">
</div>
<div class="item" style="background-image: url(//placehold.it/1024x700) ">
</div>
<div class="item" style="background-image: url(//placehold.it/200x200) ">
</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>
</div>
<script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type='text/javascript' src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
Add this code in your css.
.slick-list, .slick-track {
height: 100%;
}
.slick-slide img{
width: fit-content;
}
See if this what you want, I'm just inherit the img in "carousel div" and set the div with 100%
.carousel{ max-height:100%; overflow:hidden;}
.carousel div { width:100%; height: 100%; }
.carousel div img {
max-width:100% ;
max-height:100%;
width:auto;
margin: auto;
}
.carouselWrapper {
margin: 0px;
height: 80vh;
width: 100
}
.carousel{
width: 100%;
height: 100%;
margin:0px auto;
}
this was the result

Height of images used within carousel is not relating to the div used to hold the carousel

.mainIDv
{
height:300px;
width:400px;
padding:5px;
margin: 8px auto 8px auto;
}
.ImgDisp{
background-color:cyan;
height:100%;
width:100%;
}
.carousel-inner > .carousel-item > img {
width: 100% !important;
height: 100% !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<div class="mainIDv">
<div class="ImgDisp">
<div id="carouselSection" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#carouselSection" data-slide-to="0"></li>
<li data-target="#carouselSection" data-slide-to="1"></li>
<li data-target="#carouselSection" data-slide-to="2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg" alt="Los Angeles" >
<div class="carousel-caption">
<h3>Tomorrow land </h3>
<p>We had good friends here!</p>
</div>
</div>
<div class="carousel-item">
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f9/Phoenicopterus_ruber_in_S%C3%A3o_Paulo_Zoo.jpg" alt="Chicago" style="width: 100%; height: 100%;">
<div class="carousel-caption">
<h3>HappyLand</h3>
<p>Thank you!</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</div>
</div>
I tried to create a slide show using carousel of bootstrap 4. I used the carousel code section within a div block. But my problem is height of images used within the carousel is not matching with the height of the div holding it. I tired every solutions suggested here, but none works for me.
here is my code.
<div class="ImgDisp">
<div id="demo" class="carousel slide" data-ride="carousel">
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<img src="Images/Img12.png" alt="Los Angeles" >
<div class="carousel-caption">
<h3>Tomorrow land </h3>
<p>We had good friends here!</p>
</div>
</div>
<div class="carousel-item">
<img src="Images/Img4.jpg" alt="Chicago" style="width: 100%; height: 100%;">
<div class="carousel-caption">
<h3>HappyLand</h3>
<p>Thank you!</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</div>
I want images with height and width 100% matching with the div ImgDisp.
I tired overriding the styles defined for components like carousel, carousel-inner, carousel-item. but only width is working for me. Even tried to change the image styles.
.carousel-inner > .carousel-item > img {
width: 100% !important;
height: 100% !important;
}
I don't know why, somebody suggest a solutions. Thanks in advance.
you are overriding your img height by 10% in this style
.carousel-inner > .carousel-item > img {
width: 100% !important;
height: 10% !important;
}
change it to 100%.

Made carrousel responsive in all devices

I can't fix my carousel images for any devices. Here is my code:
div.c-wrapper {
height: 406px;
width: 940px;
/* use this, or not */
margin: auto;
}
.img-responsive {
max-width: 100%;
display: block;
height: auto;
}
<div class="container">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="c-wrapper">
<div id="carousel-example-generic" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="Images/carrousel11.jpg" class="img-responsive" alt="">
</div>
<div class="item">
<img src="Images/carrousel5.jpg" class="img-responsive" alt="">
</div>
<div class="item">
<img src="Images/carrousel6.jpg" class="img-responsive" alt="">
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="icon-next"></span>
</a>
</div>
</div>
</div>
</div>
Thank you guys if can help me out!
Even though I'd highly recommend using a library like Slick, the exercise of creating a slider from scratch is a worth while one to consider, if for no other reason than to better understand web technologies.
Here are a few things to consider. In order to make a proper carousel you'll want to use JavaScript to manage the click events for next, previous and clicking on the indicators. You had a number of issues with your mark up and CSS that I've done my best to match what I believe was your original intention but if anything is off let me know and we can refine from here.
Hide the inactive image
In order to give the appearance of sliding you need to hide all but the one active slides. Then on click you simply hide the active item by remove the .active class then add that class to the next element - in this case by stepping through your data-slide-to attribute.
Positioning
The best way that I've found to position your previous and next buttons is to use position: absolute. In order for this to work you need to have a relatively positioned container around it. I did this on .carousel.
Extraneous markup
I didn't remove all of the unneccessary markup but you'll find that several of the divs in your example are not neccessary especially at the top level. I left those in just in case you had some other reason for that.
Images
Quick tip, if you're going to use relative images in your SO posts, try to swap those for Placehold.it images as they won't render on SO.
.carousel-wrapper {
width: 500px;
margin: auto;
}
.carousel-wrapper:after {
content: "";
display: table;
clear: both;
}
.carousel {
position: relative;
}
.left, .right {
position: absolute;
top: 50%;
}
.left {
left: -50px;
}
.right {
right: -50px;
}
.img-responsive {
max-width: 100%;
display: block;
}
.carousel-indicators {
display: block;
height: auto;
padding: 0;
margin: 0;
text-align: center;
}
.carousel-indicators li {
width: 15px;
height: 15px;
background: #ccc;
margin: 0 5px;
display: inline-block;
list-style: none;
border-radius: 50%;
}
.item {
display: none;
}
.active {
display: block;
}
<div class="container">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-wrapper">
<div id="carousel-example-generic" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<img src="https://placehold.it/500x250" class="item active img-responsive" alt="">
<img src="https://placehold.it/500x250" class="item img-responsive" alt="">
<img src="https://placehold.it/500x250" class="item img-responsive" alt="">
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="icon-prev">Prev</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="icon-next">Next</span>
</a>
</div>
</div>
</div>
</div>

Putting Bootstrap Carousel indicator vertically at the right of the Carousel

I am trying to change the Bootstrap Carousel indicator align to vertical and locate them in the right of the page.
As you can see at following demo (the demo is on Bootply, I am not sure why the indicators are still looks like horizontal at JS Fiddle).
Working Demo
As you can see from the demo I have set the right: 5%; on .carousel-indicators but thy are rendering almost at the middle of the Carousel! What am I doing wrong?
.carousel-indicators {
background-color:#000;
position: absolute;
bottom: 200px;
z-index: 15;
width: 30px;
margin-left: 20px;
list-style: none;
text-align: center;
right: 5%;
}
.carousel-indicators li{
display: block;
width: 10px;
height: 10px;
margin-bottom: 10px;
}
.carousel-indicators .active {
width: 12px;
height: 12px;
margin-bottom: 10px;
background-color: #fff;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://placehold.it/1920x400/333/333" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="http://placehold.it/1920x400/333333/333333" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="http://placehold.it/1920x400/333/333" alt="...">
<div class="carousel-caption">
...
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" 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-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Left component is set to 50% in bootstrap css. you need to overrride it.
give your indicators left 95% that should fix your problem.
left:95%
set left:inherit because the lib has a default setting you must override.

Moving Element more to the left without moving the element through resizes

Attempting to resize the browser and i cannot seem to keep the div "stickyslider" within the page when i shrink past the edge of the "green".
yes i know its the padding, but is there anyway to put the slider in that position without it resizing it until both elements (menu and slider) are the full width
I am new to this so my code is fairly disgusting.
but as you can tell the slider, drops down.
any critique on how i'm doing things is much appreciated.
a{
color: black;
}
.menu{
display: inline-table;
padding-top: 15%;
max-width: 150px;
}
.stickyslider{
padding-top: 15%;
padding-right: 25%;
padding-bottom: 15%;
float: right;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<div class="container">
<nav class="menu">
<a><u>name</u></a><br>
<a>123 fake street</a><br>
<a>+61 4 00000000</a><br>
<br>
<br>
<a></a><br>
<a></a><br>
<a></a><br>
<br>
<a>Example1</a><br>
<a>Example2</a><br>
<a>Example3</a><br>
<br>
<br>
<a>Example4</a><br>
<a>Example5</a><br>
<a>Example6</a><br>
<a>Example7</a><br>
<a>Example8</a><br>
<a>Example9</a><br>
</nav>
<div class="stickyslider">
<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>
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://www.dailymobile.net/wp-content/uploads/wallpapers/android-640x480-wallpapers/android-640x480-wallpaper-4582.jpg" alt="architecture">
</div>
<div class="item">
<img src="http://www.dailymobile.net/wp-content/uploads/wallpapers/android-640x480-wallpapers/android-640x480-wallpaper-4582.jpg" alt="more architecture">
</div>
<div class="item">
<img src="http://www.dailymobile.net/wp-content/uploads/wallpapers/android-640x480-wallpapers/android-640x480-wallpaper-4582.jpg" alt="heaps architecture">
</div>
<div class="item">
<img src="http://www.dailymobile.net/wp-content/uploads/wallpapers/android-640x480-wallpapers/android-640x480-wallpaper-4582.jpg" alt="architecture">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
</body>
</html>
.stickyslider{
padding-top: 15%;
padding-right: 25%;
padding-bottom: 15%;
max-width: 20%;
float: right;
}
Adding a max width is what worked for this code block.

Resources