I am developing a website for the first time and am get my hands dirty with bootstrap and css. I am using bootstrap carousel and using the basic carousel with 2 slides. However I am not able to style the height of the slides to the height of the screen. I tried adjusting the carousel height to 100% but it is not working right (extends way beyond the screen height). If I give a pixel height, like height: 500px; it works fine. But I want it to fit the entire scree. Any help on how I can achieve this?
HTML:
<div class="container-fluid after-navbar">
<div class="container-fluid ">
<div class="row row-content">
<div class="col-xs-12">
<div id="mycarousel" class="carousel slide carousel-height" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#mycarousel" data-slide-to="0" class="active"></li>
<li data-target="#mycarousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner carousel-height" role="listbox">
<div class="item active carousel-height">
<%= image_tag("bg1.jpg", class: "img-responsive") %>
<div class="carousel-caption">
<h2>BLAH </h2>
</div>
</div>
<div class="item">
<%= image_tag("bg1.jpg", class: "img-responsive") %>
<div class="carousel-caption">
<h2>BLAH</h2>
</div>
</div>
</div>
<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>
</div>
</div>
</div>
CSS:
.carousel {
background: $bgDefault;
}
.carousel .item {
height: 100%;
}
.carousel .item img {
left: 0;
height: 100%;
position: absolute;
top: 0;
}
Maybe put the height of the carousel at 100% height too, and then add 100% height to the body and html element so it would be:
.carousel{
height:100%;
}
body, html{
height:100%;
}
if this doesnt work then may be add:
.container-fluid.after-navbar{
height:100%;
}
.row-content, .row-content > .col-xs-12{
height:100%;
}
Related
I'm trying to make an automatic image slideshow using only html and css. I finally found a simple tutorial on how to make one except i slightly changed the code to make my images move left instead. Right now, the problem I'm facing is that only 1 out of my 2 images is showing up. Why is this?
.maincontainer{
position: relative;
width:100%;
height:500px;
overflow:hidden;
}
.maincontainer > img{
position:absolute;
float: left;
animation: sliding 20s infinite;
left:0;
width: 100%;
height:auto;
}
#keyframes sliding{
0%{left:0px}
10%{left:0px}
20%{left:-700x}
30%{left:-700px}
40%{left:-1200px}
50%{left:-1200px}
60%{left:-1500px}
70%{left:-1500px}
80%{left:-2400px}
90%{left:-2400px}
100%{left:0px}
}
.sliding {width:100%; height:0px; padding-bottom: 50%; overflow:hidden; position:relative; }
<div class="maincontainer">
<img src="pictures/stove.jpg" alt="slide1">
<img src="pictures/hp.jpeg" alt="slide2">
</div>
I faced a similar kind of problem, so I think this code should work according to your problem:
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<div class="carousel-inner" style="border-radius: 5px;">
<div class="item active">
<img src="Images/oneplus-7-pro-hero-image.jpg" alt="" style="width:100%; height: 375px;" class="img-responsive">
</div>
<div class="item">
<img src="Images/huawei-p30-singapore-prices.png" alt="" style="width:100%; height: 375px;" class="img-responsive">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev" style="background: transparent; width: 25px;">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next" style="background: transparent; width: 25px;">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
I am begining in styling shiny apps.
I want to create a create a full screen slider into a tabpanel of my application for my landing page.
According to this snippet, here's my application.
The carousel is empty. How can I solve this issues (perhaps the inline css <div class="item active" style="background-image: url(https://unsplash.it/1600/840?image=697);"> not working?
library(shiny)
ui <- fluidPage(includeCSS("carousel.css"),
navbarPage("project",
collapsible = TRUE,
tabPanel("Home",
tags$div(HTML('<div class="tcb-bs-fullscreen">
<div id="carousel-example-generic" class="carousel slide carousel-bg" 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" style="background-image: url(https://unsplash.it/1600/840?image=697);">
<div class="carousel-caption">
...
</div>
</div>
<div class="item" style="background-image: url(https://unsplash.it/1600/840?image=545);">
<div class="carousel-caption">
...
</div>
</div>
<div class="item" style="background-image: url(https://unsplash.it/1600/840?image=673);">
<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>
</div>')
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {}
# Run the application
shinyApp(ui = ui, server = server)
And the LESS css:
/****************************
TURN BOOTSTRAP CAROUSEL INTO FULL SCREEN SLIDER
*****************************/
html,
body {
height: 100%;
}
.tcb-bs-fullscreen{
height: 100%;
.carousel,
.item,
.active {
height: 100%;
}
.carousel-inner {
height: 100%;
}
}
/****************************
USE BACKGROUND IMAGES IN CAROUSEL SLIDER
*****************************/
.carousel-bg {
.carousel-inner {
.item {
background-color: darkslategrey;
background-size: cover;
background-position: center;
min-height: 360px;
}
}
}
The URL's of the images loaded within your carousel seem dead except for the second or middle URL:
Does not load:
<div class="item active" style="background-image: url(https://unsplash.it/1600/840?image=697);">
Does load:
<div class="item" style="background-image: url(https://unsplash.it/1600/840?image=545);">
Does not load:
<div class="item" style="background-image: url(https://unsplash.it/1600/840?image=673);">
The code is working fine (you might want to fix your CSS however):
html, body {
height: 100%;
}
.tcb-bs-fullscreen {
height: 100%;
}
.carousel, .item, .active {
height: 100%;
}
.carousel-inner {
height: 100%;
}
.carousel-bg .carousel-inner .item {
background-color: #ccc;
background-size: cover;
background-position: center;
min-height: 360px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<div class="tcb-bs-fullscreen">
<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="https://unsplash.it/1600/840?image=697" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="https://unsplash.it/1600/840?image=545" alt="...">
<div class="carousel-caption">
...
</div>
</div>
<div class="item">
<img src="https://unsplash.it/1600/840?image=673" 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>
</div>
JSFiddle
How to change from this
To this?
I want to shorten the width of the image in this carousel, but not the actual red box. How can i do it? I'm at my wits end. I tried every solution on this forum, it doesn't shrink it the way i show it in the picture.
<div class="container box">
<div class="row">
<!-- carousel -->
<div class="col-xs-8">
<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=""
alt="..." />
</div>
<div class="item">
<img src="" alt="..." />
</div>
<div class="item">
<img src="" alt="..." />
</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>
</div>
<div class="col-xs-4"></div>
</div>
</div>
try:
.carousel-inner .item img {
width: 100%; /* or width: 100% !important; */
}
Try this:
.carousel-inner > .item > img {
width:100%; /* Or try to use important */
height:auto;
}
A second way to do this:
.carousel {
width:100%; /* Or try to use important */
height:auto;
}
If don't work let me know so I can help
You can use the following to resize an image in Bootstrap Carousel:
.carousel-inner .item img {
height: 100%;
width: 100% !important;
}
I had a similar problem and I solved it through some inline styling.
<div class="carousel-item">
<img
src="images/image.png"
alt="testImg"
style="height: 537px"
/>
</div>
I just used Google Chrome inspect elements to get the height of an image I was happy with and styled the problem images, as I only had some images in my carousel that didn't work properly.
-Note- styling the images like this did also adjust the positions of the indicators correctly in my testing so this shouldn't be a problem with changing the Width as well as the Height if you need.
I did try the other solutions posted here but none seemed to work. So hopefully this will help someone out.
I am trying to create slider inside an image.
As to the attachment, I want to change the proportion of the background color and then to insert inside this div the slider.
I was using this example:
Fiddle here
The code:
HTML
<div class="col-6 col-md-4">
<img class="temp" src="img/phone.png">
<div class="bg-image">
<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>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="./img/testimonial-bg.jpg" alt="...">
</div>
<div class="item">
<img src="http://www.freedomwallpaper.com/nature-wallpaper/nature-hd-wallpapers-water.jpg" alt="...">
</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>
</div>
</div>
CSS
#application img {
width: 250px;
height: 375px;
position: absolute;
}
.temp {
background: #440;
}
/*Image slider */
.bg-image {
width:250px;
height:350px;
background-repeat:no-repeat;
background-size:100%;
position: relative;
padding: 150px 0 0 0;
z-index: 1;
}
.carousel-inner>.item>a>img,
.carousel-inner>.item>img{
height: 350px;
}
Thank you for your help.
I have a bootstrap carousel with a fixed height. Here is the CSS:
.carousel-custom .carousel-outer {
position: relative;
}
#media(min-width: 992px){
.carousel-custom {
margin-top: 20px;
.carousel-inner {
height: auto;
.item {
height:500px;
line-height:300px;
}
}
}
}
#media(max-width: 991px){
.carousel-custom {
margin-top: 20px;
.carousel-inner {
height: auto;
.item {
height:300px;
line-height:300px;
text-align:center;
}
}
}
}
And here is my markup:
<div id="carousel-custom-1188" class="carousel slide carousel-custom" data-ride="carousel">
<div class="carousel-outer">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459261752/w8edcuvz1yl3uc4g4o34.jpg" alt="Jinallzupvfazqqr67nd">
<div class="carousel-caption"></div>
</div>
<div class="item">
<img class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459175684/w4ueot8o49dh2fyulv0x.jpg" alt="K1yov5hpur8mgsb9r15p">
<div class="carousel-caption"></div>
</div>
<div class="item">
<img class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459178926/fwlmuroj2wlz7czrsha0.jpg" alt="Lqfandhmutdkppjrl932">
<div class="carousel-caption"></div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-custom-1188" 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-custom-1188" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<!-- Indicators -->
<ol class="carousel-indicators mCustomScrollbar">
<li data-target="#carousel-custom-1188" data-slide-to="0" class="active">
<img style="height:50px; width: 50px;" class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459268139/jinallzupvfazqqr67nd.png" alt="Jinallzupvfazqqr67nd">
</li>
<li data-target="#carousel-custom-1188" data-slide-to="1" class="">
<img style="height:50px; width: 50px;" class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459268146/k1yov5hpur8mgsb9r15p.png" alt="K1yov5hpur8mgsb9r15p">
</li>
<li data-target="#carousel-custom-1188" data-slide-to="2" class="">
<img style="height:50px; width: 50px;" class="img-responsive" src="http://res.cloudinary.com/dltbqhact/image/upload/v1459268157/lqfandhmutdkppjrl932.png" alt="Lqfandhmutdkppjrl932">
</li>
</ol>
</div>
</div>
The issue is that I have images that are very wide, others very narrow and high, and others with a good ration height/width in the same carousel.
I'd like to have the wide images centered vertically (with a width of a 100%), high images centered horizontally (with a height of 100%) and "normal" images (with a decent ratio height/width) filling all the carousel.
Here is what I'm trying to do (first image is an example with a very wide image, second image with a very high one, and last one has a "decent" ratio).
How could I achieve this ? I've tried Make Bootstrap's Carousel both center AND responsive? and other tricks found on Google but none did this.
Since the .item elements are relative positioned you could just position the img elements absolutely. Giving the .item elements a fixed height, will help to vertically and horizontally align the images inside.
I'm sure there are lots of different ways to do this, here is one example. Hope it helps.
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css');
body {
background-color: black;
}
.carousel-inner > .item {
height: 100vh;
}
.carousel-inner > .item > img {
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%, -50%);
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
max-height: 800px;
width: auto;
}
.carousel-control.left,
.carousel-control.right {
background-image: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<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>
<!-- inner -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="http://placehold.it/1200x600/2c3e50/000" alt="">
</div>
<div class="item">
<img src="http://placehold.it/600x1200/d35400/000" alt="">
</div>
<div class="item">
<img src="http://placehold.it/600x600/c0392b/000" alt="">
</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>
</div>
Alright, I've been fiddling around for a while now. Ended up with the result below. Hope it helps and answers your question (at least for a small part).
<head>
<title>Bootstrap Carousel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<style>
html,
body {
height: 100%;
}
.carousel,
.item,
.active {
height: 100%;
}
.carousel-inner {
height: 100%;
}
/* Background images are set within the HTML using inline CSS, not here */
.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;
}
.tester {
height: 100%;
}
</style>
</head>
<body>
<div class="tester">
<!-- Full Page Image Background Carousel Header -->
<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('http://res.cloudinary.com/dltbqhact/image/upload/v1459268139/jinallzupvfazqqr67nd.png');"></div>
<div class="carousel-caption">
<h2>Caption 1</h2>
</div>
</div>
<div class="item">
<!-- Set the second background image using inline CSS below. -->
<div class="fill" style="background-image:url('http://res.cloudinary.com/dltbqhact/image/upload/v1459268146/k1yov5hpur8mgsb9r15p.png');"></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('http://res.cloudinary.com/dltbqhact/image/upload/v1459268157/lqfandhmutdkppjrl932.png');"></div>
<div class="carousel-caption">
<h2>Caption 3</h2>
</div>
</div>
</div>
<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>
<script>
$('.carousel').carousel({
interval: 5000 //changes the speed
})
</script>
</div>
</body>
Again, hope it helps!
simply use image on absolute if your slider height is fixed
<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">
<div class="middle">
<img src="http://placehold.it/1920x500">
</div>
</div>
<div class="item">
<div class="middle">
<img src="http://placehold.it/1920x300">
</div>
</div>
<div class="item">
<div class="middle">
<img src="http://placehold.it/600x900">
</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>
css
.carousel {
width: 500px; /*test width*/
height: 300px; /*what ever height */
}
.middle {
position: relative;
height: 300px; /*what ever height */
}
.middle img {
max-width: 100%;
max-height: 100%; /*what ever height */
margin: auto;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
see fiddle
If you try to achieve this in bootstrap carousel, you will end up with black bars in top and bottom...I was stuck with similar problem and ended up using "flickity" js library..it works lot better than tryig to achieve this on something not meant for this....