I'm want my carousel to be a certain size (not sure what size until I play about, but certainly not width: 100%) and also to be centred horizontally in the page.
My new CSS rule has made the carousel smaller and central, but now the slides do not move automatically. The ol with class "carousel-indicators" works fine, so I can select and successfully move to each slide manually.
This same CSS has seemingly removed the click functionality of my next/prev arrows. Even stranger, when I click my next arrow, the page 'smooth-scrolls' down the page a little. Thanks in advance :)
Here is the code....
HTML:
<div id="event-carousel" class="carousel slide" data-right="carousel">
<ol class="carousel-indicators">
<li data-target="#event-carousel" data-slide-to="0"></li>
<li data-target="#event-carousel" data-slide-to="1"></li>
<li data-target="#event-carousel" data-slide-to="2"></li>
<li data-target="#event-carousel" data-slide-to="3"></li>
<li data-target="#event-carousel" data-slide-to="4"></li>
</ol>
<div class="carousel-inner" roll="listbox">
<div class="carousel-item active">
<img class="d-block w-100" src="./recources/images/pioneeringSpirit.png" alt="Temporary structures built on the Pioneering Spirit catamaran">
<div class="carousel-caption">
<h3>Pioneering Spirit</h3>
<p>Weeks at sea produced thousands of square meters of temporary hospitality structures.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/rugbyWorldCup.png" alt="Main structure for England's Rugby World Cup.">
<div class="carousel-caption">
<h3>Rugby World Cup</h3>
<p>Twickenham is part of the White Rose Crew calander, but this year was special.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/thales.png" alt="A three story structure for Farnborough Airshow.">
<div class="carousel-caption">
<h3>Thales</h3>
<p>Our favourite biannual build of the worlds largest airshow.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/masterpiece.png" alt="Masterpiece Arts Fair, Chelsea.">
<div class="carousel-caption">
<h3>Masterpiece</h3>
<p>We are proud to be an integral part of this incredible transformation year in, year out.</p>
</div>
</div>
<div class="carousel-item">
<img class="d-block w-100" src="./recources/images/fieldHospital.jpg" alt="Emergancy hospital built in the Pricipality Stadium.">
<div class="carousel-caption">
<h3>Emergancy Covid-19 Field Hospital</h3>
<p>Helping turn The Pricipality Stadium into Wales largest hospital in just 10 days.</p>
</div>
</div>
<a class="carousel-control-prev" href="#event-carousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#event-carousel" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">next</span>
</a>
</div>
</div>
CSS:
.carousel-inner {
margin: auto;
width: 55%;
height: auto;
}
JS:
$(document).ready(() => {
$('#event-carousel').carousel({
interval: 8000
});
$('#event-carousel').carousel('cycle');
});
Related
I am using Bootstrap 4.0 and the carousel class. I have a caption for each image that is part of the carousel, and would like to decrease the width of the background of the caption since it is wider than the text. (see yellow arrows below) I have used different bootstrap classes such as d-md-flex, but it moves the entire text box to the left.
How can I decrease the width of the background? The text is not dynamic, so although it would be preferable to have a flex option, I can use a fixed or maximum width. It needs to be centered though.
Thanks!
<div class="carousel-item">
<img class="d-block w-100" src="img/t/flowers.svg" alt="Creativity">
<div class="carousel-caption d-none d-md-block text-dark">
<h1 style="background-color: rgba(250, 250, 250,0.5);">Everyday Creativity</h1>
</div>
</div>
so we need to align text to center and width to be only as per the width of the content...
working snippet below:
.carousel-inner img {
width: 100%;
height: 100%;
}
.carousel-caption h1 {
width: fit-content;
margin: auto;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<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>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="https://www.w3schools.com/bootstrap4/la.jpg" alt="Los Angeles" width="1100" height="500">
<div class="carousel-caption d-none d-md-block text-dark">
<h1 style="background-color: rgba(250, 250, 250,0.5);">Everyday</h1>
</div>
</div>
<div class="carousel-item">
<img src="https://www.w3schools.com/bootstrap4/chicago.jpg" alt="Chicago" width="1100" height="500">
<div class="carousel-caption d-none d-md-block text-dark">
<h1 style="background-color: rgba(250, 250, 250,0.5);">Everyday Creativity</h1>
</div>
</div>
<div class="carousel-item">
<img src="https://www.w3schools.com/bootstrap4/ny.jpg" alt="New York" width="1100" height="500">
<div class="carousel-caption d-none d-md-block text-dark">
<h1 style="background-color: rgba(250, 250, 250,0.5);">Everyday Creativity, Everyday </h1>
</div>
</div>
</div>
<!-- Left and right controls -->
<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>
you can decrease the width of h1 to its content via max-content or display:table; for older browsers :
body {background:tomato;}
<code>max-content</code><h1 style="background-color: rgba(250, 250, 250,0.5);margin:1em auto;width:max-content;">Everyday Creativity</h1>
<code>display:table;</code><h1 style="background-color: rgba(250, 250, 250,0.5);margin:1em auto;display:table;">Everyday Creativity</h1>
infos :
https://developer.mozilla.org/en-US/docs/Web/CSS/width#max-content
https://developer.mozilla.org/en-US/docs/Web/CSS/display
I'm trying to setup a CSS carousel, when I wrote the code the automatic sliding seems to work okay, although it seems little buggy. However the main issue is the prev and next controls don't work properly. Every time you click one of them they always start you from the active-item image so you can never fully click through the images.
<body>
<div class="container">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div id="my-slider" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="images/parvazlogo.jpg" alt="program" />
<div class="carousel-caption">
<h1></h1>
</div>
</div>
<div class="item">
<img src="images/program1.jpg" alt="programming image" />
<div class="carousel-caption">
<h1>ParwazTech Will Bring your Ideas To Life!</h1>
</div>
</div>
<div class="item">
<img src="images/innovation.jpg" alt="innovation" />
<div class="carousel-caption">
<h1>Learn More about Us</h1>
</div>
</div>
<div class="item">
<img src="images/office.jpg" alt="deal struck" />
<div class="carousel-caption">
<h1>Start looking at deals now!</h1>
</div>
</div>
<a class="left carousel-control" href="#my-slider" 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="#my-slider" 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>
</div>
</body>
#MatiasFernandezMartinez
https://youtu.be/7Hr-EBEpVJ0 this is a video of the problem just to prove it is happening. As you can see the bottom three buttons work fine but the two left and right buttons bring up the problem I described
I'm assuming the problem is with my bootstrap or my jquery since the code does not bring you all problems
am trying to have a carousel where each slide is linked to a different page.
My code for the base carousel is
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<a href="about.html">
<img src="img//tshirts/large/slide1.png" alt="" >
</div>
<div class="item">
<a href="tshirts.html">
<img src="img//tshirts/large/slide2.png" alt="">
</div>
<div class="item">
<a href="sublimation.html">
<img src="img//tshirts/large/slide3.png" alt="">
</div>
<div class="item">
<a href="sweatshirts.html">
<img src="img//tshirts/large/slide4.png" alt="">
</div>
</div>
This works perfect and shows all 4 slides one after another then back to beginning
So I wanted to add the hyperlinks as follows
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<a href="about.html">
<img src="img//tshirts/large/slide1.png" alt="" >
</div>
<div class="item">
<a href="tshirts.html">
<img src="img//tshirts/large/slide2.png" alt="">
</div>
<div class="item">
<a href="sublimation.html">
<img src="img//tshirts/large/slide3.png" alt="">
</div>
<div class="item">
<a href="sweatshirts.html">
<img src="img//tshirts/large/slide4.png" alt="">
</div>
</div>
Now when I run the second code the first slide is perfect and when clicked goes to the page but as soon as it slides to the next slide no slide is shown and none are clickable and it doesn't go back to the first slide
Please close hyper link tag, Like
<div class="item active">
<a href="about.html">
<img src="img//tshirts/large/slide1.png" alt="" >
</a>
</div>
I'm working on a project in Bootstrap and I have added a simple image carousel with controls but the problem is that the controls does not work.. See my site here
As you can see you can not press on next and previous buttons to see other images. Here's my code:
<div class="row">
<div class="container">
<div class="col-md-3">
</div>
<div class="col-md-6">
<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="images/slideshow/1.jpg" alt="Los Angeles" style="width:100%;">
<div class="carousel-caption">
<h3>Los Angeles</h3>
<p>LA is always so much fun!</p>
</div>
</div>
<div class="item">
<img src="images/slideshow/2.jpg" alt="Chicago" style="width:100%;">
<div class="carousel-caption">
<h3>Chicago</h3>
<p>Thank you, Chicago!</p>
</div>
</div>
<div class="item">
<img src="images/slideshow/3.jpg" alt="New York" style="width:100%;">
<div class="carousel-caption">
<h3>New York</h3>
<p>We love the Big Apple!</p>
</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>
</div>
<div class="col-md-3">
</div>
</div>
</div>
Basically I have not found any kind of mistake in this code ,so if you know what is going wrong please let me know... thanks!
Your code has no problem. But You have used a older version of jQuery. Please update with newer version.
http://take.ms/Rbwmf
You can use this version. It is working perfectly with your code.
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
Thanks
You use the id="myCarousel" several time on this page.
You can only have ONE UNIQUE id per page. Removing the other id="myCarousel" fixes your issue.
Some additional info on IDs:
IDs are here in order for Javascript to target element quite easily. But while they make targeting element with JS easy, they need to be unique otherwise, the script won't be able to know which ID to target. There are many other way to target element with JS but this one stay one of the easiest one.
Small advice: even if you can, don't create IDs for CSS since they are not meant for that. Leave the IDs for use in JS. That will help to keep your code clean consistent.
I'm learning build website using react and bootstrap css,
i have carousel, and separated navigation.
below example code of my carousel
class Home extends React.Component {
mousehover() {
... ???? .....
};
render() { return (
<div className="row">
<div id="carouselExampleIndicators" className="carousel slide col-9" data-ride="carousel">
<div className="carousel-inner" role="listbox">
<div className="carousel-item active">
<img className="d-block img-fluid" src="http://northdelawhere.happeningmag.com/wp-content/uploads/banner_sample300x300.jpg"
alt="First slide" />
</div>
<div className="carousel-item">
<img className="d-block img-fluid" src="http://www.raymiller.cc/thumbnail/exterior-beadboard-paneling-4-texture-plus-indoor-outdoor-siding-panel-beadboard-oak-sample-300-x-300.jpg"
alt="Second slide" />
</div>
<div className="carousel-item">
<img className="d-block img-fluid" src="..." alt="Third slide" />
</div>
</div>
<a className="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span className="carousel-control-prev-icon" aria-hidden="true"></span>
<span className="sr-only">Previous</span>
</a>
<a className="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span className="carousel-control-next-icon" aria-hidden="true"></span>
<span className="sr-only">Next</span>
</a>
</div>
<div className="col-3">
<ul className="flex-column">
<li data-target="#carouselExampleIndicators" data-slide-to="0" onmouseover={this.mousehover}>one</li>
<li data-target="#carouselExampleIndicators" data-slide-to="1">two</li>
<li data-target="#carouselExampleIndicators" data-slide-to="2">three</li>
</ul>
</div>
</div>
)}
}
React.render(<Home />, document.getElementById('root'));
i'm trying create event for my list using onmousehover, but failed.
anyone can help me for give clue / example for onmousehover event which will slide to target carousel (data-slide-to) ?
thank you very much.
Have a look at the SyntheticEvent section of the React docs, it explains how to use events like onMouseEnter and onMouseLeave in React:
Your event handlers will be passed instances of SyntheticEvent, a
cross-browser wrapper around the browser's native event. It has the
same interface as the browser's native event, including
stopPropagation() and preventDefault(), except the events work
identically across all browsers.
That said, depending on your use case, you be better off implementing the hover effect using CSS's :hover pseudo-class.