Bootstrap carousel controls not reflecting the styles - html

I want my carousel controls to be something like this(Link at the end). and they should be outside the carousel. but when I tried to add styles, nothing seems to reflect, is there anything I am missing. Please help me out.
Thanks in advance.
Expected carousel control- left
.carousel-control .glyphicon-chevron-left, .carousel-control .glyphicon-chevron-right, .carousel-control .icon-next, .carousel-control .icon-prev {
position: absolute;
top: 83% !important;
z-index: 5;
display: inline-block;
margin-top: -10px;
}
h4 {
margin: 20px 10px 10px;
}
p {
margin: 10px;
}
#carousel-example-generic {
margin: 20px auto;
width: 400px;
}
#carousel-custom {
margin: 20px auto;
width: 400px;
}
#carousel-custom .carousel-indicators {
margin: 10px 0 0;
overflow: auto;
position: static;
text-align: left;
white-space: nowrap;
width: 100%;
}
#carousel-custom .carousel-indicators li {
background-color: transparent;
-webkit-border-radius: 0;
border-radius: 0;
display: inline-block;
height: auto;
margin: 0 !important;
width: auto;
}
#carousel-custom .carousel-indicators li img {
display: block;
opacity: 0.5;
}
#carousel-custom .carousel-indicators li.active img {
opacity: 1;
}
#carousel-custom .carousel-indicators li:hover img {
opacity: 0.75;
}
#carousel-custom .carousel-outer {
position: relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw==" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A==" crossorigin="anonymous"></script>
<div id='carousel-custom' class='carousel slide' data-ride='carousel'>
<div class='carousel-outer'>
<!-- Wrapper for slides -->
<div class='carousel-inner'>
<div class='item active'>
<img src='http://placehold.it/400x200&text=slide1' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide2' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide3' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide4' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide5' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide6' alt='' />
</div>
</div>
</div>
<!-- Controls -->
<a class='left carousel-control' href='#carousel-custom' data-slide='prev'>
<span class='glyphicon glyphicon-chevron-left'></span>
</a>
<a class='right carousel-control' href='#carousel-custom' data-slide='next'>
<span class='glyphicon glyphicon-chevron-right'></span>
</a>
<!-- Indicators -->
<ol class='carousel-indicators'>
<li data-target='#carousel-custom' data-slide-to='0' class='active'><img src='http://placehold.it/100x50&text=slide1' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='1'><img src='http://placehold.it/100x50&text=slide2' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='2'><img src='http://placehold.it/100x50&text=slide3' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='3'><img src='http://placehold.it/100x50&text=slide4' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='4'><img src='http://placehold.it/100x50&text=slide5' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='5'><img src='http://placehold.it/100x50&text=slide6' alt='' /></li>
</ol>
</div>
I want my carousel controls to be something like this(Link at the end). and they should be outside the carousel. but when I tried to add styles, nothing seems to reflect, is there anything I am missing. Please help me out.

Working Demo below: added the pic you give just customize the pic and upadte the image url.
.carousel-control img{
z-index: 5;
display: inline-block;
margin-top: 100%;
position:relative;
}
h4 {
margin: 20px 10px 10px;
}
p {
margin: 10px;
}
#carousel-example-generic {
margin: 20px auto;
width: 400px;
}
#carousel-custom {
margin: 20px auto;
width: 400px;
}
#carousel-custom .carousel-indicators {
margin: 10px 0 0;
overflow: auto;
position: static;
text-align: left;
white-space: nowrap;
width: 100%;
}
#carousel-custom .carousel-indicators li {
background-color: transparent;
-webkit-border-radius: 0;
border-radius: 0;
display: inline-block;
height: auto;
margin: 0 !important;
width: auto;
}
#carousel-custom .carousel-indicators li img {
display: block;
opacity: 0.5;
}
#carousel-custom .carousel-indicators li.active img {
opacity: 1;
}
#carousel-custom .carousel-indicators li:hover img {
opacity: 0.75;
}
#carousel-custom .carousel-outer {
position: relative;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha256-7s5uDGW3AHqw6xtJmNNtr+OBRJUlgkNJEo78P4b0yRw= sha512-nNo+yCHEyn0smMxSswnf/OnX6/KwJuZTlNZBjauKhTK0c+zT+q5JOCx0UFhXQ6rJR9jg6Es8gPuD2uZcYDLqSw=="
crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha256-KXn5puMvxCw+dAYznun+drMdG1IFl3agK0p/pqT9KAo= sha512-2e8qq0ETcfWRI4HJBzQiA3UoyFk6tbNyG+qSaIBZLyW9Xf3sWZHN/lxe9fTh1U45DpPf07yj94KsUHHWe4Yk1A==" crossorigin="anonymous"></script>
<a class='left carousel-control' href='#carousel-custom' data-slide='prev'>
<img src="https://i.stack.imgur.com/4HGNH.jpg" />
</a>
<a class='right carousel-control' href='#carousel-custom' data-slide='next'>
<img src="https://i.stack.imgur.com/4HGNH.jpg" />
</a>
<div id='carousel-custom' class='carousel slide' data-ride='carousel'>
<div class='carousel-outer'>
<!-- Wrapper for slides -->
<div class='carousel-inner'>
<div class='item active'>
<img src='http://placehold.it/400x200&text=slide1' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide2' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide3' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide4' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide5' alt='' />
</div>
<div class='item'>
<img src='http://placehold.it/400x200&text=slide6' alt='' />
</div>
</div>
</div>
<!-- Controls -->
<!-- Indicators -->
<ol class='carousel-indicators'>
<li data-target='#carousel-custom' data-slide-to='0' class='active'><img src='http://placehold.it/100x50&text=slide1' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='1'><img src='http://placehold.it/100x50&text=slide2' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='2'><img src='http://placehold.it/100x50&text=slide3' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='3'><img src='http://placehold.it/100x50&text=slide4' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='4'><img src='http://placehold.it/100x50&text=slide5' alt='' /></li>
<li data-target='#carousel-custom' data-slide-to='5'><img src='http://placehold.it/100x50&text=slide6' alt='' /></li>
</ol>
</div>

Related

2 div inline too big to fit

I got 2 main div that i'm trying to make appear on the same line. I'm struggling with the CSS to get what I want.
First div is a kind of menu, displaying categories. I can have more or less of them (should be dynamic). Second div is displaying main buttons/shortcuts and is static.
Goal:
both div on same line
second div (button-container) taking 25% of the page on the right
first div (category-container) taking whatever is left, on the left of the page. Overflow hidden, size of each indivual cells will be adjusted with javascript so everything can fit.
section.home {
white-space: nowrap;
}
section.home > div.category-container {
width: 75%;
overflow: hidden;
display: inline;
}
section.home > div.buttons-container {
width: 25%;
height: 300px;
display: inline-block;
background-color: #EEEEEE;
}
section.home > div.category-container > ul > li {
padding-right: 15px;
padding-left: 15px;
padding-bottom: 15px;
display: inline-block;
}
div.category {
width: 200px;
height: 300px;
text-align: center;
box-shadow: 0 3px 5px #aaa;
background: White none repeat scroll 0 0;
border: 1px solid #ccc;
overflow: hidden;
}
div.category > div.category-title {
padding: 5px;
background-color: #EEEEEE;
color: rgb(254, 107, 3);
font-weight: bold;
}
div.category > a > img {
width: 200px;
}
div.category_content {
padding-top: 10px;
padding-bottom: 10px;
}
<section class="home">
<div class="category-container">
<ul>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 1</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 2</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 3</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
</ul>
</div>
<div class="buttons-container">
Buttons container
</div>
</section>
By adding float: left; to the .category-container you are able to format the div's side-by-side.
section.home>div.category-container {
width: 75%;
overflow: hidden;
display: inline;
float: left; /* Float left is what you need */
}
I've updated your HTML & CSS with this edit:
section.home {
white-space: nowrap;
}
section.home > div.category-container {
width: 75%;
overflow: hidden;
display: inline;
float: left;
}
section.home > div.buttons-container {
width: 25%;
height: 300px;
display: inline-block;
background-color: #EEEEEE;
}
section.home > div.category-container > ul > li {
padding-right: 15px;
padding-left: 15px;
padding-bottom: 15px;
display: inline-block;
}
div.category {
width: 200px;
height: 300px;
text-align: center;
box-shadow: 0 3px 5px #aaa;
background: White none repeat scroll 0 0;
border: 1px solid #ccc;
overflow: hidden;
}
div.category > div.category-title {
padding: 5px;
background-color: #EEEEEE;
color: rgb(254, 107, 3);
font-weight: bold;
}
div.category > a > img {
width: 200px;
}
div.category_content {
padding-top: 10px;
padding-bottom: 10px;
}
<section class="home">
<div class="category-container">
<ul>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 1</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 2</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 3</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1
<br/>subcategory2
<br/>subcategory 3
</div>
</div>
</li>
</ul>
</div>
<div class="buttons-container">
Buttons container
</div>
</section>
The problem is your ul, setting it to inline-block does the trick.
It crashed for small windows, because .category has a fixed width.
section.home > div.category-container UL {
display: inline-block;
}
section.home {
white-space:nowrap;
}
section.home > div.category-container {
width:70%;
overflow:hidden;
display:inline;
}
section.home > div.category-container UL {
display: inline-block;
}
section.home > div.buttons-container {
width:25%;
height:300px;
display:inline;
background-color:#EEEEEE;
}
section.home > div.category-container > ul > li {
padding-right:15px;
padding-left:15px;
padding-bottom:15px;
display:inline-block;
}
div.category {
width:200px;
height:300px;
text-align:center;
box-shadow:0 3px 5px #aaa;
background:White none repeat scroll 0 0;
border:1px solid #ccc;
overflow:hidden;
}
div.category > div.category-title {
padding:5px;
background-color:#EEEEEE;
color:rgb(254,107,3);
font-weight:bold;
}
div.category > a > img {
width:200px;
}
div.category_content {
padding-top:10px;
padding-bottom:10px;
}
<section class="home">
<div class="category-container">
<ul>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 1</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1<br/>
subcategory2<br/>
subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 2</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1<br/>
subcategory2<br/>
subcategory 3
</div>
</div>
</li>
<li>
<div class="category">
<div class="category-title">
<span class="font_16">Title 3</span>
</div>
<a href="#">
<img src="#" />
</a>
<div class="category-content">
sutcategory1<br/>
subcategory2<br/>
subcategory 3
</div>
</div>
</li>
</ul>
</div>
<div class="buttons-container">
Buttons container
</div>
</section>

Centering link below images

How to center link below my images, I tried everything. When I use clear:both this helped me, but then my images are in one column and I do not want that. So basically I want bellow every picture centered link/text. I know that this HTML/CSS does not contains links that I wanted to put below images, I deleted everything that can be confusing.
Thanks.
* {
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
}
html {
height: 100%;
background-color: #F0FFF0;
}
body {
height: 100%;
width: 100%;
font-size: 100%;
margin: 0;
}
.container {
display: box;
width: 100%;
height: 100%;
margin: 5%;
padding: 0%;
clear: both;
}
.products img {
width: 31%;
height: 31%;
position: relative;
float: left;
display: inline;
margin: 0 2% 3% 0%;
}
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Products</title>
<link rel="stylesheet" type="text/css" href="css/products.css" />
</head>
<body>
<div class="container">
<div class="products">
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
<a href="#">
<img src="images/tunel.jpg" alt="Product name">
</a>
</div>
</div>
</body>
</html>
Here you go:
Don't float the images, float the links.
Make the images display:block and add text-align:center to the links.
* {
margin: 0;
padding: 0;
text-decoration: none;
list-style: none;
}
html {
height: 100%;
background-color: #F0FFF0;
}
body {
height: 100%;
width: 100%;
font-size: 100%;
margin: 0;
}
.container {
display: box;
width: 100%;
height: 100%;
margin: 5%;
padding: 0%;
clear: both;
}
.products a {
width: 31%;
height: 31%;
position: relative;
float: left;
margin: 0 2% 3% 0%;
text-align: center
}
.products a img {
display: block;
margin: auto;
}
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Products</title>
<link rel="stylesheet" type="text/css" href="css/products.css" />
</head>
<body>
<div class="container">
<div class="products">
<a href="#">
<img src="http://www.fillmurray.com/g/140/100" alt="Product name">Link Text
</a>
<a href="#">
<img src="http://www.fillmurray.com/g/140/100" alt="Product name">Link Text
</a>
<a href="#">
<img src="http://www.fillmurray.com/g/140/100" alt="Product name">Link Text
</a>
</div>
</div>
</body>
</html>

CSS :target on hover not on click

I've got a slider, and it's working great. BUT, I've got one little problem. I want to change the slider image when I hover over one of the <li>s, and not when I click on them.
Is this possible? I've found this link, but maybe there's some new style available already?
.slide {
position: absolute;
display: none;
left: -150;
}
.next {
font-size: 50px;
height: 50px;
line-height: 50px;
position: absolute;
top: calc(50% - 25px);
right: 0;
}
.prev {
font-size: 50px;
height: 50px;
line-height: 50px;
position: absolute;
top: calc(50% - 25px);
}
.slider .slide:target {
transition: 1s;
left: 0;
z-index: 999;
display: block;
}
ul {
padding-top: 250px
}
ul li:hover>a:target {
left: 0;
transition: 1s;
z-index: 9999;
}
<div class='slider'>
<div class='slide' id="slide1" style="display: block;">
<a class="prev" href="#slide4"><</a>
<img src="http://pic.1fotonin.com/data/wallpapers/9/WDF_576006.jpg" width="450" height="150" />
<a class="next" href="#slide2">></a>
</div>
<div class='slide' id="slide2">
<a class="prev" href="#slide1"><</a>
<img src="http://pic.1fotonin.com/data/wallpapers/9/WDF_575498.jpg" width="450" height="150" />
<a class="next" href="#slide3">></a>
</div>
<div class='slide' id="slide3">
<a class="prev" href="#slide1"><</a>
<img src="http://pic.1fotonin.com/data/wallpapers/9/WDF_576753.jpg" width="450" height="150" />
<a class="next" href="#slide4">></a>
</div>
<div class='slide' id="slide4">
<a class="prev" href="#slide3"><</a>
<img src="http://pic.1fotonin.com/data/wallpapers/9/WDF_575922.jpg" width="450" height="150" />
<a class="next" href="#slide1">></a>
</div>
</div>
<ul>
<li>Slide 1</li>
<li>Slide 2</li>
<li>Slide 3</li>
<li>Slide 4</li>
</ul>
Do you need to use :target? Please check out my Fiddle.
.slide
{
position: absolute;
display: none;
left:0;
}
ul
{
padding-top: 50px;
list-style:none;
}
ul li
{
display:inline-block;
}
ul li a
{
position:relative;
top:-50px;
left:0;
}
ul li a:hover + .slide
{
transition: 1s;
z-index: 9999;
display: block;
}
<div class='slider'>
<ul>
<li>
Slide 1
<div class='slide' id="slide1" style="display: block;">
<img src="https://i.picsum.photos/id/591/450/150.jpg" width="450" height="150" />
</div>
</li>
<li>
Slide 2
<div class='slide' id="slide2">
<img src="https://i.picsum.photos/id/402/450/150.jpg" width="450" height="150" />
</div>
</li>
<li>
Slide 3
<div class='slide' id="slide3">
<img src="https://i.picsum.photos/id/1067/450/150.jpg" width="450" height="150" />
</div>
</li>
<li>
Slide 4
<div class='slide' id="slide4">
<img src="https://i.picsum.photos/id/382/450/150.jpg" width="450" height="150" />
</div>
</li>
</ul>
</div>
I removed the next and before buttons for convenience, but it would also be simple to include them again.

Removing space between menu and image

Does anyone know how I can remove the space between the top of my menu and the bottom of the image on top of the page. I tried to do it with margin and padding. But that didn't work.
This is a picture of the result I get now
#charset "UTF-8";
body {
background-color: #ADF1F5;
}
html,
body {
margin: 0;
padding: 0;
}
#Anouk {
text-align: center;
margin: 0 auto;
padding: 0;
}
#header {
height: 80px;
background: #000000;
}
li {
display: block;
float: left;
}
li a {
color: #FFFFFF;
height: 80px;
}
#contact {
float: right;
}
<div id="Anouk">
<img src="logo/Hout.png" width="1000px" alt="Logo" />
</div>
<div id="header">
<div id="menu">
<!--Home-->
<li id="home">
<a href="index.html">
<img src="Iconen/Home.png" height="80px" alt="home" onmouseover="this.src='Iconen/Home2.png'" onmouseout="this.src='Iconen/Home.png'" />
</a>
</li>
<!--Over Mij-->
<li id="over">
<a href="over.html">
<img src="Iconen/Over.png" height="80px" alt="home" onmouseover="this.src='Iconen/Over2.png'" onmouseout="this.src='Iconen/Over.png'" />
</a>
</li>
<!--Portfolio-->
<li id="portfolio">
<a href="portfolio.html">
<img src="Iconen/Portfolio.png" height="80px" alt="home" onmouseover="this.src='Iconen/Portfolio2.png'" onmouseout="this.src='Iconen/Portfolio.png'" />
</a>
</li>
<!--Contact-->
<li id="contact">
<a href="contact.html">
<img src="Iconen/Contact.png" height="80px" alt="home" onmouseover="this.src='Iconen/Contact2.png'" onmouseout="this.src='Iconen/Contact.png'" />
</a>
</li>
</div>
</div>
Try to add display:block to your top most image.
#Anouk img{
display: block;
}
Here is a solution: https://jsfiddle.net/egjbmp1u/
For your #header style you need to add:
position: relative;
float: left;
width: 100%;
Also, #Anouk style should look like this:
#Anouk {
display: flex;
text-align: center;
padding: 0;
}
#Anouk img {
margin: 0 auto;
}

Center list items

I have created a list that contains movie cases and a title beneath each case. However, I can't get the list items to center themselves.
Here's what it looks like:
Here's what I want it to look like:
In the following CSS rules, I have centered #main-container with margin: 0 auto
#main-container {
width: 600px;
margin: 0 auto;
}
However, that just centers #main-container, not the list items.
I think it has something to do with this CSS rule.
.element {
position: relative;
margin: 0;
float: left;
}
JSFiddle
#main-container {
width: 600px;
margin: 0 auto;
}
#movies-container {
padding: 0;
margin: 0;
}
#movies-container li {
list-style: none;
margin-right: 15px;
}
.element {
position: relative;
margin: 0;
float: left;
}
.cover {
background: grey;
width: 90px;
height: 130px;
}
.element img {
width: 90px;
height: 130px;
opacity: 1;
-webkit-transition: opacity 0.2s linear;
}
.element .title {
height: 20px;
margin-top: 5px;
text-align: center;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
background: #fff;
color: #333;
width: 100%;
}
<div id="main-container">
<ul id="movies-container">
<li class="element">
<div class="cover">
<a href="#">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</a>
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
<li class="element">
<div class="cover">
<a href="#">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</a>
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
</ul>
</div>
Working Solution for Internet Explorer too
If you give float it doesn't work out. Check this out:
Preview
Snippet
#main-container {
width: 600px;
margin: 0 auto;
}
#movies-container {
padding: 0;
margin: 0;
text-align: center;
}
#movies-container li {
list-style:none;
margin-right: 15px;
}
.element {
position: relative;
margin: 0;
display: inline-block;
}
.cover {
background: grey;
width: 90px;
height: 130px;
}
.element img {
width: 90px;
height: 130px;
opacity: 1;
-webkit-transition: opacity 0.2s linear;
}
.element .title {
height: 20px;
margin-top: 5px;
text-align: center;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
background: #fff;
color: #333;
width: 100%;
}
<div id="main-container">
<ul id="movies-container">
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li> <li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
</ul>
</div>
Fiddle: https://jsfiddle.net/6qo6zL6f/3/
Flexbox works fine for the solution.
Added CSS
#movies-container {
display: flex;
flex-flow: row wrap; /* Wrap to next line */
justify-content: center; /* Center all rows */
}
Check the Browser compatibility table for Flexbox
#main-container {
width: 600px;
margin: 0 auto;
}
#movies-container {
display: flex;
flex-flow: row wrap;
justify-content: center;
margin: 0;
padding: 0;
}
#movies-container li {
list-style: none;
margin-right: 15px;
}
.element {
position: relative;
margin: 0;
float: left;
}
.cover {
background: grey;
width: 90px;
height: 130px;
}
.element img {
width: 90px;
height: 130px;
opacity: 1;
-webkit-transition: opacity 0.2s linear;
}
.element .title {
height: 20px;
margin-top: 5px;
text-align: center;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
background: #fff;
color: #333;
width: 100%;
}
<div id="main-container">
<ul id="movies-container">
<li class="element">
<div class="cover">
<a href="#">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</a>
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
<li class="element">
<div class="cover">
<a href="#">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</a>
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
</ul>
</div>
This is how I would achieve the effect you're looking for, the main differences are using inline-block on .element and text-align: center on #main-container.
* {
box-sizing: border-box;
}
body {
margin: 0;
}
#main-container {
width: 600px;
margin: 0 auto;
text-align: center;
}
#movies-container,
.element {
margin: 0;
padding: 0;
}
#movies-container {
font-size: 0;
}
.element {
display: inline-block;
list-style: none;
padding: 7.5px;
}
.cover {
background: grey;
width: 90px;
height: 130px;
}
.element img {
width: 90px;
height: 130px;
opacity: 1;
-webkit-transition: opacity 0.2s linear;
}
.element .title {
height: 20px;
margin-top: 5px;
font-size: 13px;
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
background: #fff;
color: #333;
width: 100%;
}
<div id="main-container">
<ul id="movies-container">
<li class="element">
<div class="cover">
<a href="#">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</a>
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
<li class="element">
<div class="cover">
<a href="#">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</a>
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">300</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/12244.jpg" />
</div>
<div class="title">9</div>
</li>
<li class="element">
<div class="cover">
<img src="http://cparliaros.com/imdb/img/thumbnails/1271.jpg" />
</div>
<div class="title">Gladiator</div>
</li>
</ul>
</div>