Centering button over Bootstrap 3 carousel - html

I'm trying to center a button over a bootstrap 3 carousel, this button is hovering above the carousel.
I tried to wrap the button in a div class and center it with either text-align: center; or margin: 0 auto; without succes.
I can manually set margin-left of the .hover-class; this will work, but it's not perfectly centered. How to center my button?
This is my code:
HTML:
<!--The slider-->
<section>
<div class="hover-slide">
Let's go
</div>
<div id="slider-top" class="carousel slide" data-ride="carousel">
<!--Indicators-->
<ol class="carousel-indicators">
<li data-target="#slider-top" data-slide-to="0" class="active"></li>
<li data-target="#slider-top" data-slide-to="1"></li>
<!--<li data-target="#slider-top" data-slide-to="2"></li>-->
</ol>
<!--Wrapper for the the slide-->
<div class="carousel-inner">
<!--specify first slide-->
<div class="item active">
<img src="img/01.jpg" alt="Foto1">
<div class="carousel-caption">
<h3>TEST</h3>
</div>
</div>
<!--specify second slide-->
<div class="item">
<img src="img/02.jpg" alt="Foto2">
<div class="carousel-caption">
<!--Let's go-->
<h3>TEST SLIDE 2</h3>
</div>
</div>
</div>
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
My CSS:
.hover-slide {
position: absolute;
/*margin-left: 30%;*/
z-index: 10;
}
.carousel .item {
width: 100%;
height: 100%;
}
.carousel .item img {
width: 100%;
height: 100%;
}
.btn.start-me {margin: 0 auto;}

You need to wrap in column and add text-center class :
Fiddle : http://bootply.com/112692
Extract :
<section>
<div class="col-md-12 hover-slide text-center"> // <------ HERE
Let's go
</div>
<div id="slider-top" class="carousel slide col-md-12" data-ride="carousel"> // <------ HERE
<ol class="carousel-indicators">
<li data-target="#slider-top" data-slide-to="0" class="active"></li>
<li data-target="#slider-top" data-slide-to="1"></li>
<!--<li data-target="#slider-top" data-slide-to="2"></li>-->
</ol>

Related

Setting the width of a carousel using html

I have tried to reduce the width of my carousel so that it doesn't take up the whole width of the page but it doesn't seem to be working. I would like the width to only span over 8 columns and to be centred. I have tried changing the CSS code so that the width was 50% and not 100% but this did not work.
.item {
height: 300px;
}
.item,
img {
height: 500px !important;
width: 100% !important;
}
.item h3 {
font-family: 'Anton', sans-serif;
font-size: 48px;
color: cornsilk;
}
.item p {
font-family: 'Anton', sans-serif;
font-size: 18px;
color: cornsilk;
}
<!--Start of carousel-->
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<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>
<div class="carousel-inner">
<div class="item active">
<img src="images/c1.jpg" alt="First slide" />
<div class="carousel-caption">
<h3>Welcome to my amazing website</h3>
<p3>Hope you enjoy!</p3>
</div>
</div>
<div class="item">
<img src="images/c2.jpg" alt="Second slide" />
</div>
<div class="item">
<img src="images/c3.jpg" alt="Third slide" />
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
</div>
Why wouldn't you work with the upper level, i.e. with the outer div element (id="carousel-example-generic" class="carousel slide")?
E.g.
.carousel{
width: 50%;
margin: 0 auto;
}
With bootstrap you could also use the bootstrap-grid including offsets: https://getbootstrap.com/docs/4.0/layout/grid/

Unable to position carousel next to aside

I am currently trying to create side bar next to my carousel, However for some reason, I can't get the carousel to center on the page while the aside is next to it. I tried using margin:auto auto but had no luck. I also tried using Justify-content:center. Anyone know why it won't move?
html:
<section id="carouselSlides" class="carousel slide container" data-ride="carousel" style="background:#979BAF; ">
<!--Indicators-->
<ol class="carousel-indicators">
<li data-target="#carouselSlides" data-slide-to="0" class="active"></li>
<li data-target="#carouselSlides" data-slide-to="1"></li>
</ol>
<!--The slideshow-->
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="slideshow/sunglasses.jpg" alt="sunglasses">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="slideshow/lady.jpeg" alt="women">
</div>
<!--<div class="carousel-item">
<img src="" alt>
</div>-->
<!--Left and right controls-->
<a class="carousel-control-prev" href="#carouselSlides" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#carouselSlides" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</section>
<aside class="rightSideSection container clearfix">
<header style="background: #2A2A36;"><h1 class="bold">Whats popular</h1></header><br>
<ul class="popularList">
<li>example1</li>
<li>example2</li>
<li>example3</li>
</ul>
</aside>
CSS:
#carouselSlides{
display: inline-block;
width: 700px;
justify-content: center;
}
.carousel-inner img{
}
/*right side bar*/
.rightSideSection{
background: #ffffff;
width: 280px;
float: right;
margin-top: 40px;
}
.rightSideSection h1{
font-size: 30px;
}
.popularList li{
margin-left: 20px;
}
maybe this can work for you, to align the carousel to center:
<div style="text-align: center; text-align: -webkit-center;">
<section id="carouselSlides" class="carousel slide container" data-ride="carousel" style="background:#979BAF; ">
<!--Indicators-->
<ol class="carousel-indicators">
<li data-target="#carouselSlides" data-slide-to="0" class="active"></li>
<li data-target="#carouselSlides" data-slide-to="1"></li>
</ol>
<!--The slideshow-->
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="slideshow/sunglasses.jpg" alt="sunglasses">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="slideshow/lady.jpeg" alt="women">
</div>
<!--<div class="carousel-item">
<img src="" alt>
</div>-->
<!--Left and right controls-->
<a class="carousel-control-prev" href="#carouselSlides" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#carouselSlides" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
</section>
<div>
Here basically the "carouselSlides" is contained in a div
providing the div styles as:
div{
text-align: center;
text-align: -webkit-center;
}

Image won't fill complete width of container

My image slider isn't quite the way I want it.
The image won't fill the full width of the container unless my browser window is small. When my window is larger the right side of the image has a white space instead of the image filling the whole width.
Here is my code:
<div class="bs-example">
<div id="myCarousel" class="carousel slide" data-interval="6500" data-ride="carousel">
<!-- 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>
</ol>
<div class="fill">
<div class="carousel-inner">
<div class="active item carousel-fade">
<img src="EvanHeathYellowGreen.jpg" alt="Evan&MEKiss" >
</div>
<div class="item carousel-fade">
<img src="EvanCrossStreet.jpg" alt="Evan&MEKiss" >
</div>
<div class="item carousel-fade">
<img src="EvanMeLook.jpg" alt="Evan&MEKiss" >
</div>
</div>
</div>
<!-- Carousel nav -->
<a class="carousel-control left" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="carousel-control right" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
and the CSS:
.fill {
overflow: hidden;
background-size: cover;
background-position: center;
background-image:"path/to/image.jpg";
}
.carousel-inner{
margin-left: auto;
}
.carousel{
margin-top: 20px;
border-top: 2px solid black;
border-bottom: 2px solid black;
}
Which is the image you are trying to fill?
If they are the ones with alt="Evan&MEKiss" then you can try Alberto Rubio's answer:
.item img {
width: 100%;
}
If you are trying to fill the background-image, you can try tweaking background-image to use url:
background-image:url("path/to/image.jpg");
Here's a codepen example with placeholder images: http://codepen.io/fawyna/pen/VaOmqX

adjust carousel height to image height (responsive)

I am using the bootstrap caroussel template.
There is 4 images, all four in 1330*500px. By default image stretches on window resizing. I managed to keep the original image ratio with a CSS width:100% , height:auto setting for the image. Problem is carousel container won't adjust (and I see a gray gap instead)... How can I adjust carrousel height to image height within (tried to adjust carousel height in % or using padding-bottom in % too, but doesn't work) ?
Thanks.
html :
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="false">
<!-- 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">
<div class="item active">
<img src="#" alt="First slide">
<div class="container">
<div class="carousel-caption">
<img src="#">
</div>
</div>
</div>
css:
/* Carousel base class */
.carousel
{
height: 500px;
margin-bottom: 10px;
}
/* Since positioning the image, we need to help out the caption */
.carousel-caption
{
}
/* Declare heights because of positioning of img element */
.carousel .item
{
height: 500px;
background-color: #777;
margin-top: 0px;
}
.carousel-inner > .item > img
{
position: relative;
top: 0;
left: 0;
min-width: 100%;
height: auto;
}
By overwriting bootstrap's css and adding height:500px to the carousel class, you seem to be be breaking the slider. I created a simple carousel in bootply and left out all of your Css. And now everything works as expected and the height adjust itself correctly without any grey gap. I also added Bootstrap's container, row and column divs. I don't know if you had them setup, but I recommend you do. I used images with the same dimensions you specified.
Here is the BOOTPLY EXAMPLE. Click on the desktop and mobile icon situed on the top-right to see how it will look on different resolution.
Hope this helps
Html:
<div class="container">
<div class="row">
<div class="col-lg-12">
<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>
<li data-target="#carousel-example-generic" data-slide-to="3"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="images/img-1.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="images/img-2.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="images/img-3.jpg" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="images/img-4.jpg" 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"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
</div>

How to change the bootstrap carousel indicators and controls

I stuck am trying to be able to change the location of bootstrap carousel indicators and controls. Looking like something like this carousel at this website. http://www.mitre10.co.nz/ Were the indicators and controls are at bottom and away from the image.
Here is my live view http://codepen.io/riwakawebsitedesigns/pen/qdiup
<header id="masterhead">
<div class="container">
<div class="slideshow">
<div id="slideshow" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#slideshow" data-slide-to="0" class="active"></li>
<li data-target="#slideshow" data-slide-to="1"></li>
<li data-target="#slideshow" data-slide-to="2"></li>
<li data-target="#slideshow" data-slide-to="3"></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<img src="http://s20.postimg.org/wgz1zd3wd/slide1.jpg" alt="slide"/>
</div>
<div class="item">
<img src="http://s20.postimg.org/l3cio5tdp/slide2.jpg" alt="slide"/>
</div>
<div class="item">
<img src="http://s20.postimg.org/w0ducxg59/slide3.jpg" alt="slide"/>
</div>
<div class="item">
<img src="http://s20.postimg.org/lrld73s3h/slide4.jpg" alt="slide"/>
</div>
</div>
<a class="left carousel-control" href="#slideshow" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#slideshow" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>
</div>
</div>
</header>
I can't open your example site, but you can move those indicators out of their current spot and place them where you wish. I moved them out of the header in your CodePen, wrapped them in a container and added some styles to move them below your images and center them:
<div class="carousel-controls">
<a class="left carousel-control" href="#slideshow" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<ol class="carousel-indicators">
<li data-target="#slideshow" data-slide-to="0" class="active"></li>
<li data-target="#slideshow" data-slide-to="1"></li>
<li data-target="#slideshow" data-slide-to="2"></li>
<li data-target="#slideshow" data-slide-to="3"></li>
</ol>
<a class="right carousel-control" href="#slideshow" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
CSS:
.carousel-controls{
position:relative;
width:300px;
margin:0 auto;
}
.carousel-indicators{
top:0px;
}
ref: http://codepen.io/anon/pen/tayfk/
Here's a template for a carousel, with positionable controls, and a progress navbar at the bottom that tracks the slides.
http://codepen.io/TheNickelDime/
<!-- HTML -->
<div class="Slideshow_carousel-wrapper container-fluid">
<span class="Slideshow-ctl-L" onclick="carousel_left()"></span>
<div class="carousel slide" data-ride="carousel" ... </div>
<span class="Slideshow-ctl-R" onclick="carousel_right()"></span>
</div>
<!-- /HTML -->
<!-- CSS -->
.Slideshow_carousel-wrapper {
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
text-align:center;
width:100%;
}
/* SLIDESHOW CONTROLS LEFT / RIGHT */
.Slideshow-ctl-L {
-webkit-flex: none;
flex: none;
z-index:200;
top:40%;
margin-right:5px;
height:60px;
width:16px;
opacity:0.7;
background-size:15px 60px;
background-repeat:no-repeat;
background-image: url( ... );
}
.Slideshow-ctl-R {
-webkit-flex: none;
flex: none;
top:40%;
margin-left:5px;
height:60px;
width:15px;
opacity:0.7;
background-size:15px 60px;
background-repeat:no-repeat;
background-image: url( ... );
}
<!-- CSS -->
You can edit bootstrap.js to have multiple classes recognized as indicators.
var Carousel = function (element, options) {
this.$element = $(element)
this.$indicators = this.$element.find('.carousel-indicators, .your-class-here')
You can use this JS Code to have multiple classes recognized as indicators. "the new indicators will showing the active slide and adding class active to indicator"
$('.carousel').on('slid.bs.carousel', function() {
$(".carousel-indicators2 li").removeClass("active");
indicators = $(".carousel-indicators li.active").data("slide-to");
a = $(".carousel-indicators2").find("[data-slide-to='" + indicators +
"']").addClass("active");
console.log(indicators); <!-- You can remove this line "This line makes you see the active indicator in the console in the browser" -->
})