Customization of Bootstrap carousel's width - css

How to customize the width of a carousel via bootstrap or css, please?
I'm currently mainly using this code into my web page:
<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">
<div class="item active">
<img src="..." alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="..." 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>
I've tried to set a width to the body, but it wouldn't work.
Thanks in advance!

You have 2 options to set width of carousel as
set container width and include carousel in that container, this width can be customized as
.container {
width : // here enter your custom width
}
Overwrite this over default bootstrap css/less. And don't forget to add media queries to adjust width since this will apply globally.
secondly you can change carousel items inner width with class as below
.carousel-inner {
width: // here enter your custom width;
}
This will just affect width of carousel

Width is relative to the parent container the carousel is in. So you need to set the width on the ID/class of the div you are wrapping the carousel inside. You could also set it inside a bootstrap container (and change the container width globally) or inside a column for more lax specificity.

Related

Negative top margin + overflow:hidden on Boostrap carousel

I have a generic bootstrap v3.7 carousel and I'm trying to pull it up over the content above it like this
This is done with a margin-top: -50px; on the teal div. However, the hidden overflow property of the carousel is causing the top to be cut off above the top of the div, so I cannot achieve this overlay design. My attempts to modify the CSS have only broken the carousel. Is it possible to do this?
The margin-top should be applied the div containing .carousel, perhaps you are using it on the div with the calls carousel;
Following code snippet is what you're trying to achieve:
.aboveCarousel {
height: 300px;
background: magenta;
}
.container {
margin-top: -50px
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<div class='aboveCarousel'> </div>
<div class="container">
<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>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://www.w3schools.com/bootstrap/la.jpg" alt="Los Angeles" style="width:100%;">
</div>
<div class="item">
<img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago" style="width:100%;">
</div>
<div class="item">
<img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="New york" style="width:100%;">
</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>
</div>

Why is Bootstrap 3 carousel ignoring "data-interval" attribute in Rails app?

The question was asked before on Stackoverflow here: Bootstrap carousel ignoring data-interval attribute
But the answer was not relevant in my case.
As stated in the title the data-interval attribute does not change the time each slide lingers in the carousel. at the moment it is too fast. I have searched for where this is coming from in the CSS, but I cannot see anything related to the interval time. Here is my HTML:
<!-- Header Carousel -->
<header id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="3000">
<!-- 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">
<div class="fill"><%= image_tag "Acu.png"%></div>
<div class="carousel-caption">
<h2>Caption 1</h2>
</div>
</div>
<div class="item">
<div class="fill" ><%= image_tag "terapia-nut.png"%></div>
<div class="carousel-caption">
<h2>Caption 2</h2>
</div>
</div>
<div class="item">
<div class="fill" ></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>
</header>
<!-- Page Content -->
<div class="container">
.
.
.
.
.
.
<!-- /.container -->
<!-- Script to Activate the Carousel -->
<script>
$(document).on('ready', function () {
$('.carousel').carousel({
interval: 1000 //changes the speed
})
});
</script>
CSS for carousel
/* Home Page Carousel */
header.carousel {
height: 50%;
}
header.carousel .item,
header.carousel .item.active,
header.carousel .carousel-inner {
height: 100%;
}
header.carousel .fill {
width: 100%;
height: 100%;
background-position: center;
background-size: cover;
}
What other possible causes of this could there be?
Where can I see the raw bootstrap 3 CSS files in order to know what classes are controlling what attributes? Because they are hidden I often find it hard to know which classes and which attributes to change in order to control the CSS.

Carousel ok in Site.Master, but not inside Content element

My carousel picture show works well when placed inside Site.Master, but the same markup inside the Content element of an .aspx file that uses Site.Master (without the carousel snippet) displays only the alt text for each image that it cycles through.
Environment: Win10 Pro, Visual Studio 2017 Community 15.4.4, bootstrap 3.0.0
Here is the carousel snippet:
<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>
</ol>
<!-- Images-->
<div class="carousel-inner" role="listbox">
<div class="item carousel-item active">
<img src="1945_DeHavilland_Canada_DH-98_Mosquito_FBMK26.jpg" alt="Slide #1">
</div>
<div class="item carousel-item">
<img src="1969_Aerovodochody_L-29_DELFIN.jpg" alt="Slide #2">
</div>
<div class="item carousel-item">
<img src="737BahamasAir.jpg" alt="Slide #3">
</div>
</div>
<!-- Left Right Arrows -->
<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>
If the file you are using the display the carousel is inside of a subfolder, example:
/wwwroot/Content/file.aspx
Then you would have to set the image source to ../example_image.jpg (or wherever the image is stored, in this case, the image is in your web root folder.

image background in full slider bootstrap

I am using the Full Slider bootstrap here and when I replace the image url by a image in a folder it does not work.
image:url('http://placehold.it/1900x1080&... One')
by
<img class="fill" src="background:url(./img/header.jpg)"></img>
On the bootstrap page, some guys had the same issues even if I tried different solution ../img or /img, it does not work.
Someone has a idea ?
thank you
here is the source code from Bootstrap, I changed
<div class="fill" style="background-image:url('http://placehold.it/1900x1080&text=Slide One');"></div>
by
<div class="fill" src="img/header.jpg"></div>
<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=""></div>
<div class="fill" src="img/header.jpg"></div>
<div class="carousel-caption">
<h2>Caption 1</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>
Got it to work on local with this:
<div class="fill" style="background-image: url('img/picture.jpg')"></div>
Inside the wrapper DIV
<!-- 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('img/picture.jpg')"></div>
<div class="carousel-caption">
<h2>Caption 1</h2>
</div>
</div>
try this.
src = "img/header.jpg"

Bootstrap slider image getting stretched in responsive view

is there any solution for bootstrap slider image stretch problem for responsive view ? I don't want to set height default
http://getbootstrap.com/examples/carousel/
I tried with the above slider which is an default slider given in twitter bootstrap. when I included images in that slider it was stretching. If anyone faced this issue let me know the solution
I'm not sure if you already looking for this, but Bootstrap also provides a class for responsive images. Just added it to the img-tag.
HTML
<div class="slider">
<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">
<div class="item active">
<img src="http://dreamatico.com/data_images/cat/cat-6.jpg" class="img-responsive" alt="Slider 1">
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<img src="http://dreamatico.com/data_images/cat/cat-6.jpg" class="img-responsive" alt="Slider 2">
<div class="carousel-caption">
<h3>Caption Text</h3>
</div>
</div>
<div class="item">
<img src="http://dreamatico.com/data_images/cat/cat-6.jpg" class="img-responsive" alt="Slider 3">
<div class="carousel-caption">
<h3>Caption Text</h3>
</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> <!-- Carousel -->
</div>
JavaScript
$('.carousel').carousel({
interval: 3000
})
See it also on jsfiddle.

Resources