I am using Flickity. I have groupCell true. Now the issue is, I am not able to increase the height of the image or slider height.
Also, I have to display the 1 slider in mobile device.
Would you help me out?
$('.slideset').flickity({
// options
cellAlign: 'left',
wrapAround: true,
contain: true,
//groupCells:'%',
groupCells: true,
prevNextButtons: true
});
.carousel-cell {
width: calc( ( 100% - 10px) / 3);
height: 400px;
margin-right: 10px;
border-radius: 5px;
background-color: #f00;
counter-increment: carousel-cell;
}
.slidesetImg img {
width: 100%;
height: 100%;
border: 1px solid #fff;
box-shadow: 0px 0px 4px rgba(0, 0, 0, 0.18);
padding: 5px;
object-fit: cover;
}
#media ( min-width: 768px ) {
.carousel-cell {
/* 1 cells in group */
width: calc( ( 100% - 20px ) / 1);
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/flickity#2/dist/flickity.min.css">
<section>
<div class="container">
<div class="wrapper">
<div class="main-carousel slideset">
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
<div class="carousel-cell">
<div class="slidesetImg"><img src="https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg" alt=""></div>
</div>
</div>
</div>
</div>
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://unpkg.com/flickity#2/dist/flickity.pkgd.min.js"></script>
Flickity has the option setGallerySize which sets the height of the carousel to the height of the tallest cell. It enables by default.
Use setGallerySize: false if you prefer to size the carousel with CSS, rather than using the size of cells.
$('.slideset').flickity({
// options
setGallerySize: false
cellAlign: 'left',
wrapAround: true,
contain: true,
//groupCells:'%',
groupCells: true,
prevNextButtons: true
});
/* carousel height */
.carousel-cell {
height: SOME HEIGHT;
}
.slidesetImg{
height:100% !important;
}
Hope this is what you are looking for.
Related
I have been working on several things related to this for hours now. I finally got it to work, but somehow it broke again. So here I am.
For my use-case I want to display images with Packery. The images have to sort themselves so that the grid has no gaps. The user will be able to choose the sizing of the images inside the grid, and the grid should sort accordingly.
With every method that I've tried, they display over the rest of the page, or stack on top of each other.
I tested this with Masonry, Packery and Isotope. All give the same results.
My code sample below is of the Packery attempt.
Edit: After more testing, I figured out that this issue only occurs when combining height and width classes. When only one of those is present, no overlapping occurs. I do need this functionality though.
The blue line shows where the images should end.
$(document).ready(function() {
let $grid = $('.grid').imagesLoaded(function() {
// init Packery after all images have loaded
$('.grid').packery({
itemSelector: '.grid-item',
percentPosition: true
});
$grid.packery('layout');
});
// I have also tried this approach
let $grid = $('.grid').packery({
itemSelector: '.grid-item',
percentPosition: true
});
// layout Packery after each image loads
$grid.imagesLoaded().progress(function() {
$grid.packery();
});
});
* {
box-sizing: border-box;
}
/* force scrollbar, prevents initial gap */
html {
overflow-y: scroll;
}
body {
font-family: sans-serif;
}
/* ---- grid ---- */
.grid {
background: #DDD;
}
/* clear fix */
.grid:after {
content: '';
display: block;
clear: both;
}
/* ---- .element-item ---- */
/* 5 columns, percentage width */
.grid-item {
float: left;
width: 16.667%;
height: 200px;
}
.grid-item img {
display: block;
width: 100%;
height: 100%;
}
.grid-item--small-width {
width: 16.667%;
}
/*Small*/
.grid-item--double-small-width {
width: 33.334%;
}
/*Double*/
.grid-item--half-width {
width: 50%;
}
/*Half*/
.grid-item--three-fourth-width {
width: 66.668%;
}
/*Bit More Than Half*/
.grid-item--big-width {
width: 83.335%;
}
/*Big*/
.grid-item--full-width {
width: 100%;
}
/*Full*/
.grid-item--small-height {
height: 16.667%;
}
/*Small*/
.grid-item--double-small-height {
height: 33.334%;
}
/*Double*/
.grid-item--half-height {
height: 50%;
}
/*Half*/
.grid-item--three-fourth-height {
height: 66.668%;
}
/*Bit More Than Half*/
.grid-item--big-height {
height: 83.335%;
}
/*Big*/
.grid-item--full-height {
height: 100%;
}
/*Full*/
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/masonry.classes.css">
<section>
<div class="container-fluid text-center" style="background-color: white; color: black">
<div class="container" style="margin-bottom: 20px">
<div class="row">
<h1>Portfolio</h1>
<div class="col-md-12">
<div class="grid" style="height: 1200px;">
<div class="grid-sizer"></div>
<div class="grid-item grid-item--small-width grid-item--full-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--half-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/project/projectImage_4.png"></div>
<div class="grid-item grid-item--full-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
<div class="grid-item grid-item--small-width grid-item--small-height"><img class="img-responsive" src="http://landstededev.test/storage/projects/projectImage_4.png"></div>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<div class="container-fluid" style="background-color: #f0f0f0; color: #121212">
<div class="container">
<div class="row align-items-center justify-content-center">
<div class="col-4 text-center">
Link To Twitter
<br>
</div>
<div class="col-8" style="border-left: 2px solid #121212">
<h2 class="title">Title</h2>
<p>Some description will go here</p>
</div>
</div>
</div>
</div>
</section>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="https://unpkg.com/packery#2.1.2/dist/packery.pkgd.min.js"></script>
<script src="https://unpkg.com/imagesloaded#4/imagesloaded.pkgd.min.js"></script>
The javascript does not work with or without the $grid.packery('layout'); part. I have this here because it fixed an issue I had before.
After experimenting for a few more hours, I figured out that it is not possible to combine width and height classes that both use percentages.
I now use percentages for width only. Height now uses fixed px values.
I'm trying to achieve an automatic resizing of different brand logos for a company website I'm designing, inside an Own Carousel. The idea is for each logo to be of reasonable size.
Most of the logos are in SVG formats, available at https://wetransfer.com/downloads/44eb123d186e30519edc2d025dafd03420200110231646/112373 (for a week) : as you would see, they have a wide range of height / width ratio, so using a fixed-width and enforcing the correct ratio made some of them (the CNRS and CEA logos) too high.
The goal (taken from a random site):
The goal
What I got:
What I got
My code (HTML, then CSS based on Bootstrap 4, then the JS snippet that uses owl-carousel):
<div class="site-section">
<div class="container">
<div class="row justify-content-center text-center mb-5">
<div class="col-md-5">
<h2 class="section-heading">Ils nous ont fait confiance</h2>
</div>
</div>
<div class="row justify-content-center text-center">
<div class="col">
<div class="owl-carousel clients-carousel">
<img src="./img/clients/airbus-group.svg" class="client-logo limit-width" />
<img src="./img/clients/safran-group.png" class="client-logo limit-width" />
<img src="./img/clients/cnrs-fr.svg" class="client-logo limit-height" />
<img src="./img/clients/cea-fr.svg" class="client-logo limit-height" />
<img src="./img/clients/bic.svg" class="client-logo limit-width" />
<img src="./img/clients/edf.svg" class="client-logo limit-width" />
<img src="./img/clients/horiba.svg" class="client-logo limit-width" />
<img src="./img/clients/jenoptec-group.svg" class="client-logo limit-width" />
<img src="./img/clients/otis.svg" class="client-logo limit-width" />
<img src="./img/clients/thales.svg" class="client-logo limit-width" />
</div>
</div>
</div>
</div>
</div>
.clients-carousel .owl-stage-outer, .clients-carousel .owl-stage, .clients-carousel .owl-item {
display: flex;
}
.clients-carousel .owl-item {
margin-left: 1rem;
margin-right: 1rem;
}
.clients-carousel .owl-item img.client-logo {
width: 15em;
height: auto;
}
var siteOwlCarousel = function() {
$('.clients-carousel').owlCarousel({
center: true,
items: 3,
loop: true,
margin: 0,
autoplay: true,
smartSpeed: 1000,
nav:false,
dots:false,
autoWidth:true,
responsive: {
// breakpoint from 0 up
0 : {
items: 3
},
// breakpoint from 576 up
576 : {
items: 3
},
// breakpoint from 768 up
768 : {
items: 4,
center: false
},
992 : {
items: 4,
center: false
},
1200 : {
items: 4,
center: false
}
}
});
};
siteOwlCarousel();
Would somebody have an idea that relies on Flexbox?
Thanks in advance!
choumat
Change .owl-wrapper display property and owl-item display, float, vertical-align properties and set to max- width & height size.
I hope below snippet will help you lot.
var siteOwlCarousel = function() {
$('.clients-carousel').owlCarousel({
center: true,
items: 3,
loop: true,
margin: 10,
autoplay: true,
smartSpeed: 1000,
nav: false,
dots: false,
autoWidth: true,
responsive: {
0 : {
items: 2
},
576 : {
items: 3
},
768 : {
items: 4
},
992 : {
items: 4
},
1200 : {
items: 4
}
}
});
};
siteOwlCarousel();
.owl-carousel .owl-wrapper {
display: table!important;
}
.owl-carousel .owl-item {
display: table-cell!important;
float: none!important;
vertical-align: middle!important;
}
.clients-carousel .owl-item .item{
text-align: center!important;
padding: 15px 30px!important;
}
.clients-carousel .owl-item img{
max-width: 180px!important;
max-height: 50px!important;
display: inline-block!important;
}
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
<div class="site-section">
<div class="container">
<div class="row justify-content-center text-center mb-5">
<div class="col-md-5">
<h2 class="section-heading">Ils nous ont fait confiance</h2>
</div>
</div>
<div class="row justify-content-center text-center">
<div class="col">
<div class="owl-carousel clients-carousel">
<div class="item"><img src="./img/clients/airbus-group.svg"></div>
<div class="item"><img src="./img/clients/safran-group.png"></div>
<div class="item"><img src="./img/clients/cnrs-fr.svg"></div>
<div class="item"><img src="./img/clients/cea-fr.svg"></div>
<div class="item"><img src="./img/clients/bic.svg"></div>
<div class="item"><img src="./img/clients/edf.svg"></div>
<div class="item"><img src="./img/clients/horiba.svg"></div>
<div class="item"><img src="./img/clients/jenoptec-group.svg"></div>
<div class="item"><img src="./img/clients/otis.svg"></div>
<div class="item"><img src="./img/clients/thales.svg"></div>
</div>
</div>
</div>
</div>
</div>
I'm trying to make a side navbar made up of 7 icon images. I have all of the images wrapped in a div, but I want them to be responsive if the browser window shrinks (height). Here's what I have so far,
HTML:
<body>
<div id="sidenav">
<div id="nav1"><img src="img/menu.png" alt=""></div>
<div id="nav2"><img src="img/icon1.png" alt=""></div>
<div id="nav3"><img src="img/icon2.png" alt=""></div>
<div id="nav4"><img src="img/icon3.png" alt=""></div>
<div id="nav5"><img src="img/icon4.png" alt=""></div>
<div id="nav6"><img src="img/icon5.png" alt=""></div>
<div id="nav7"><img src="img/icon6.png" alt=""></div>
</div>
</body>
CSS:
body {
margin: 0;
padding: 0;
}
body, html {
height: 100%;
}
#nav1 img, #nav2 img, #nav3 img, #nav4 img, #nav5 img, #nav6 img, #nav7 img {
width: 100px;
}
#sidenav {
position: fixed;
}
So basically, whenever the browser is resized vertically, I want all of the images to resize with it, so that all 7 are always equally visible and square. Later, I want to make these images buttons, but firt I need to figure this out. Thanks in advance for the help! :-)
well, i actually have accomplished this on my page (super excited to truly answer my first question).
so what did was divided the screen by the number of icons and got a position for each icon. for mine i have 5 and I also need the top for other things. so after messing with the positioning a bit, i decided i wanted about 17% of vh for each and left room at the top. you have 7, so i would probably start around 14% vh (100/7 = ~14.2)for placing, giving each icon it's own css id, and a class to handle all the images. so for yours I would do about the same thing. to keep it square, you'll have to use vh for both the height and width. (vh stands for viewport height, so it will adjust as the view window does.)
#sidenav img{
height: 14vh;
width: 14vh;
}
#nav1{
position: fixed;
top:0vh;
}
#nav2{
position: fixed;
top:14vh;
}
#nav3{
position: fixed;
top:28vh;
}
#nav4{
position: fixed;
top:42vh;
}
#nav5{
position: fixed;
top:56vh;
}
#nav6{
position: fixed;
top:70vh;
}
#nav7{
position: fixed;
top:84vh;
}
hope that works for you. Hoping to get my first question answer.
As far as I know, this can not be done with css alone.
window.onresize = function() {
var height = document.body.clientHeight;
var nav = document.getElementById('sidenav');
var image = document.getElementsByTagName('img');
nav.setAttribute('style', 'height:' + height + 'px');
for (var i = 0; i < image.length; ++i) {
image[i].setAttribute('style', 'height:' + height / image.length + 'px');
}
};
<div id="sidenav">
<div id="nav1"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
<div id="nav2"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
<div id="nav3"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
<div id="nav4"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
<div id="nav5"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
<div id="nav6"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
<div id="nav7"><img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260" alt=""></div>
</div>
I Suggest you to try bootstrap library, it's a really good responsive library with tons of great goodies.
Here's my code using bootstrap:
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-12">
<img src="https://via.placeholder.com/1000" alt="" class="img-fluid">
</div>
<div class="col-md-12">
<img src="https://via.placeholder.com/1000" alt="" class="img-fluid">
</div>
<div class="col-md-12">
<img src="https://via.placeholder.com/1000" alt="" class="img-fluid">
</div>
<div class="col-md-12">
<img src="https://via.placeholder.com/1000" alt="" class="img-fluid">
</div>
<div class="col-md-12">
<img src="https://via.placeholder.com/1000" alt="" class="img-fluid">
</div>
</div>
</div>
Best Regards,
Khaled.
You can use media breakpoints to style your icons for special window height
#sidenav{
display: flex;
}
.nav-icon img{
max-height: 50px;
}
#media (max-height: 700px){
.nav-icon img{
max-height: 40px;
}
}
#media (max-height: 500px){
.nav-icon img{
max-height: 30px;
}
}
#media (max-height: 300px){
.nav-icon img{
max-height: 20px;
}
}
<body>
<div id="sidenav">
<div id="nav1" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301804.svg" alt=""></div>
<div id="nav2" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301805.svg" alt=""></div>
<div id="nav3" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301814.svg" alt=""></div>
<div id="nav4" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301808.svg" alt=""></div>
<div id="nav5" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301812.svg" alt=""></div>
<div id="nav6" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301809.svg" alt=""></div>
<div id="nav7" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301817.svg" alt=""></div>
</div>
</body>
another way - using vh metrics in css to make height responsive to screen size.
#sidenav{
display: flex;
}
.nav-icon img{
height: 15vh; /* 100vh = size of window */
}
<body>
<div id="sidenav">
<div id="nav1" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301804.svg" alt=""></div>
<div id="nav2" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301805.svg" alt=""></div>
<div id="nav3" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301814.svg" alt=""></div>
<div id="nav4" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301808.svg" alt=""></div>
<div id="nav5" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301812.svg" alt=""></div>
<div id="nav6" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301809.svg" alt=""></div>
<div id="nav7" class="nav-icon"><img src="https://image.flaticon.com/icons/svg/1301/1301817.svg" alt=""></div>
</div>
</body>
My Owl Carousel contains pictures of different width and height. How do I align them in the middle - both horizontally and vertically?
$("#owl-example").owlCarousel({
navigation: true
});
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css">
<div id="owl-example" class="owl-carousel">
<div><img src="https://via.placeholder.com/120x120/69c/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/200x200/c69/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/160x160/9c6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/240x240/fc6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/160x160/9c6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/200x200/c69/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/120x120/69c/fff/" alt=""></div>
</div>
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
With owl carousel version 2.1.1 and CSS3 Flexbox, just add the style:
.owl-carousel .owl-stage {
display: flex;
align-items: center;
}
See the snippet:
$( document ).ready( function() {
$( '.owl-carousel' ).owlCarousel({
autoplay: true,
margin: 2,
loop: true,
responsive: {
0: {
items:1
},
200: {
items:3
},
500: {
items:4
}
}
});
});
.owl-carousel .owl-stage {
display: flex;
align-items: center;
}
.owl-carousel .caption {
text-align: center;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/assets/owl.carousel.min.css" rel="stylesheet"/>
<div class="owl-carousel">
<div class="item">
<img src="https://via.placeholder.com/350x200/?text=1">
<div class="caption">Caption 1</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/255x200/?text=2">
<div class="caption">Caption 2</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/627x200/?text=3">
<div class="caption">Caption 3</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/627x300/?text=4">
<div class="caption">Caption 4</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/627x400/?text=5">
<div class="caption">Caption 5</div>
</div>
<div class="item">
<img src="https://via.placeholder.com/255x200/?text=6">
<div class="caption">Caption 6</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.1/owl.carousel.min.js"></script>
The Owl Carousel creates additional blocks within your layout. To add CSS properties correctly, you need to work with this HTML structure:
<div id="owl-demo" class="owl-carousel owl-theme">
<div class="owl-wrapper-outer">
<div class="owl-wrapper">
<div class="owl-item">
<div>
<img src="" alt="">
</div>
</div>
<div class="owl-item">
<div>
<img src="" alt="">
</div>
</div>
</div>
</div>
</div>
Moreover the carousel adds a style attribute to all blocks. For example, a block with the .owl-wrapper class receives the display property with the value of block. So you have to use an !important declaration in your CSS.
To obtain a horizontal alignment, you can simply add text-align: center; property to each .owl-item > div.
To align vertically, you can turn the carousel items in table cells. But do not forget to cancel the float property for them.
Let us arrange all of the changes as a new .owl-centered class. Please check the result:
Owl Carousel 2.3.4: https://codepen.io/glebkema/pen/vYKMgzj
Owl Carousel 1.3.3: https://codepen.io/glebkema/pen/BzgZxX
$("#owl-example").owlCarousel({
navigation: true
});
#import url('//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css');
#import url('//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css');
.owl-centered .owl-wrapper {
display: table !important;
}
.owl-centered .owl-item {
display: table-cell;
float: none;
vertical-align: middle;
}
.owl-centered .owl-item > div {
text-align: center;
}
<div id="owl-example" class="owl-carousel owl-centered">
<div><img src="https://via.placeholder.com/120x120/69c/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/200x200/c69/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/160x160/9c6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/240x240/fc6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/160x160/9c6/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/200x200/c69/fff/" alt=""></div>
<div><img src="https://via.placeholder.com/120x120/69c/fff/" alt=""></div>
</div>
<script src="//code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
This works for me:
#media (max-width:500px) {
.owl-carousel .owl-item {
text-align:center;
}
.owl-carousel .item {
float: none;
display: inline-block;
}
}
You might adjust it to your HTML though, but the idea is that you text-align a parent, and float:none and display:inline-block the child that holds the content, on mobile:
The solution with display table is OK, but for me the divs on the right and left side slides out from the container. My code is close the same, I changed the table and table-cell to block and inline-block
.owl-stage{
display: block !important;
}
.owl-item{
display: inline-block;
float: none;
vertical-align: middle;
}
.item{
text-align: center;
}
The result (all images has different sizes):
Another solution is to use flexbox with margin.
.owl-stage-outer {
display: flex;
flex-wrap: nowrap;
flex-direction: column;
}
.owl-stage-outer > .owl-stage {
margin:0 auto;
}
I advise this solution:
.owl-carousel .owl-stage {
margin: 0 auto;
}
I want my banner to be centered and the logo above the banner. But as you can see both the logo and banner and not centered. How can I fix this?
HERE IS LIVE VERSION: http://codepen.io/anon/pen/waYBxB
THE HTML
</head>
<body>
<!--
==============================
LOGO HEADER
==============================
-->
<section>
<div class="container">
<div class="row">
<div class="col-md-6"><img src="http://gvsfoundation.org/wp-content/uploads/2013/04/your-logo-here-27.png" class="Logo"></div>
<div class="col-md-6"></div>
</div>
</div>
</section>
<!--==============================
SLIDING BANNEER
==============================-->
<section class="Banner ">
<div class="container midText">
<div class="col-md-12 text-center hidden-xs"><img src="http://oi58.tinypic.com/eb61xd.jpg" class="img-responsive"></div>
</div>
</section>
<!--==============================
MENU BAR
==============================-->
<section>
<div class="container">
<div class="col-md-12">
<nav>
<ul>
<li>Home</li>
<li>Codepen.io</li>
<li>A longer button</li>
<li>This is my really long button</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</nav>
</div>
</section>
<!--==============================
MAIN CONTENT
==============================-->
<section>
<div class="container" id="MainPage">
<div class="row">
<div class="col-md-9 MainContent"><h3>codepen ---- CODING HAS NEVER BEEN SO EASY!</h3><br> Notice how the white is centered but he image and the logo is not. How do I fix this? </div>
<div class="col-md-2">I AM IN THE BANNER SECTION </div>
</div>
</div>
</section>
</body>
</html>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
THE CSS
body {
background-image: url(http://oi60.tinypic.com/2hhnpzn.jpg);
}
nav ul {
list-style: none;
overflow: hidden;
height: 47px;
}
nav ul li a {
color: #F9F7F7;
background-image: linear-gradient(to top, #ff6351, #ffcc6e);
padding: 8px 22px 8px 22px;
display: block;
text-align: center;
font-size: 22px;
float: left;
margin-right: 5px;
color: rgb(255, 255, 255);
background-color: rgb(120, 120, 120);
text-shadow: rgb(79, 79, 79) 1px 1px 3px;
}
.Logo {
margin: 15px;
}
#MainPage
{
background-color: white;
}
.midText
{
text-align:center
}
.MainContent
{
margin: 33px;
}
this would bring the banner image to the center of the page. What you have to do is to add the infront of the image.
<section class="Banner ">
<div class="container midText">
<div class="col-md-12 text-center hidden-xs">
<center>
<img src="http://oi58.tinypic.com/eb61xd.jpg" class="img-responsive">
</center></div>
</div>
</section>
You should take advantage of the column system to help center your divs.
If you know bootstrap rows are 12 column-widths wide, you need a row that = 12 columns.
So...
<section>
<div class="container">
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4"><img src="http://gvsfoundation.org/wp-content/uploads/2013/04/your-logo-here-27.png" class="Logo"></div>
<div class="col-md-4"></div>
</div>
Now you have 4|4|4, but you could also do 3|6|3 or even 2|8|2 or 1|10|1. That should always center your divs. Hope that helped.
In case my mumbling makes no sense, here are pretty pictures with explenation: http://getbootstrap.com/examples/grid/
As you have a number of breakpoints, why not just set the width of the img in pixels? The aspect ratio of the img & the containing div are different, hence why it doesn't fit precisely.
display: block;
max-width: 1024px;
margin: 0px auto;
height: auto;
For the logo...
<div class="col-md-12"><img src="http://gvsfoundation.org/wp-content/uploads/2013/04/your-logo-here-27.png" class="Logo"></div>
.Logo {
display: block;
margin: 15px auto;}
Quick solution for you.