I have images with different widths that need to keep them at the centre of their respective divs.
I need to consider all margins- top, bottom, left, right. They should be at the centre of the divs not top-centre. Therefore class="row text-centre"
and class="center-block"
wont help.
I tried to change the margins but having different width per image made it impossible. I am wondering if there is any way to keep any image with any width at the centre of its div.
DEMO
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<style>
.col-md-3.img-container {
background-color: green;
height: 400px;
display: flex;
-webkit-flex-flow: column;
-ms-flex-flow: column;
flex-flow: column;
margin-right: 2%;
}
.img-div {
-webkit-box-flex: 2;
-webkit-flex: 2;
-ms-flex: 2;
flex: 2;
//position: relative;
margin-left:20%;
margin-right:20%;
// margin:auto;
}
</style>
</head>
<body>
<div id="wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-md-3 img-container">
<div class="img-div">
<a
href="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQiWGXo4U6CCvNItlDYFgEQz4d3T-YjLj13nqUZ-crpAr3qMPx-"
title="" data-gallery rel="nofollow"> <img
src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQiWGXo4U6CCvNItlDYFgEQz4d3T-YjLj13nqUZ-crpAr3qMPx-"
width="20%" class="img-thumbnail img-responsive img-adv" />
</a>
</div>
</div>
<div class="col-md-3 img-container">
<div class="img-div">
<a
href="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSqUIWjfSNC02M5Yjo-7nLBoeSJSEcOZCy0uRdF7Z8HgZRxGWB_Lg"
title="" data-gallery rel="nofollow"> <img
src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSqUIWjfSNC02M5Yjo-7nLBoeSJSEcOZCy0uRdF7Z8HgZRxGWB_Lg"
width="40%" class="img-thumbnail img-responsive img-adv" />
</a>
</div>
</div>
<div class="col-md-3 img-container">
<div class="img-div">
<a
href="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTP96P2l57b9znJ60v1gYS695LfH9K0bt8lB38Yi0McCdtq_dtC"
title="" data-gallery rel="nofollow"> <img
src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTP96P2l57b9znJ60v1gYS695LfH9K0bt8lB38Yi0McCdtq_dtC"
width="80%" class="img-thumbnail img-responsive img-adv" />
</a>
</div>
</div>
<div class="col-md-3 img-container">
<div class="img-div">
<a
href="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQYUsrUfG7vmoT61NjkXL1o-Xk-I032GQI1wuZ_QIcen399srHimA"
title="" data-gallery rel="nofollow"> <img
src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQYUsrUfG7vmoT61NjkXL1o-Xk-I032GQI1wuZ_QIcen399srHimA"
width="90%" class="img-thumbnail img-responsive img-adv" />
</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>