Last active
February 11, 2024 11:27
-
-
Save koentjuh1/c8cd3ce69d2368cf642b to your computer and use it in GitHub Desktop.
Bootstrap Carousel images as CSS: background-images:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.slider-block{ | |
height:350px; | |
display:inline-block; | |
} | |
#carousel { | |
height:100%; | |
} | |
#carousel .carousel-inner{ | |
height:100%; | |
} | |
#carousel .item{ | |
background-repeat:no-repeat; | |
background-size:cover; | |
background-position:center center; | |
width:100%; | |
height:100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="slider-block"> | |
<div id="carousel" class="carousel slide" data-ride="carousel"> | |
<!-- Indicators --> | |
<ol class="carousel-indicators"> | |
</ol> | |
<!-- Wrapper for slides --> | |
<div class="carousel-inner" role="listbox"> | |
<div class="item active"> | |
<img src="images/slider1.jpg" class="img-responsive" alt=""> | |
</div> | |
<div class="item"> | |
<img src="images/slider1.jpg" class="img-responsive" alt=""> | |
</div> | |
<div class="item"> | |
<img src="images/slider1.jpg" class="img-responsive" alt=""> | |
</div> | |
</div> | |
<!-- Controls --> | |
<a class="left carousel-control" href="#carousel" 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" role="button" data-slide="next"> | |
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Replace carousel images into background images. | |
$('#carousel .item img').each(function() { | |
var imgSrc = $(this).attr('src'); | |
$(this).parent().css({'background-image': 'url('+imgSrc+')'}); | |
$(this).remove(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.slider-block | |
height: 350px | |
display: inline-block | |
width:100% | |
#carousel | |
height: 100% | |
.carousel-inner | |
height: 100% | |
.item | |
background-repeat: no-repeat | |
background-size: cover | |
background-position: center center | |
width: 100% | |
height: 100% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment