user5638822
user5638822

Reputation:

As I can align text vertically within each caption?

As I can align text vertically within each caption?

Basically, I would like to align vertically the text and

which are within each caption, independently if it has 1 or 2 lines. ATM they look as if are align on the top.

I have read different post on this site, and I have tried to used its solutions, but they didn't work in my project.

Please find below the code (html and css) and also an image where you can see what I would like to do.

.thumbnail {
    position: relative !important;
    padding: 0px !important;
    margin-bottom: 0px !important;
	border-radius:0px !important;
	border-right: 1px solid #ddd !important;
	border-top: 1px solid #ddd !important;
	border-bottom: 1px solid #ddd !important;
	border-left: 0px solid #ddd !important;
	
}

.thumbnail img {
    width: 100% !important;
}

.thumbnail .caption {
    background-color: #333;
    color: #fff !important;
    padding: 9px;
	padding-top:15px;
	height: 100% !important; 
}




.hovereffect {
width:100%;
height:100%;
float:left;
overflow:hidden;
position:relative;
text-align:center;
cursor:default;
}

.hovereffect .overlay {
width:100%;
height:100%;
position:absolute;
overflow:hidden;
top:0;
left:0;
opacity:0;
background-color:rgba(0,0,0,0.5);
-webkit-transition:all .4s ease-in-out;
transition:all .4s ease-in-out
}

.hovereffect img {
display:block;
position:relative;
-webkit-transition:all .4s linear;
transition:all .4s linear;
}

.hovereffect:hover img {
-ms-transform:scale(1.2);
-webkit-transform:scale(1.2);
transform:scale(1.2);
}

.hovereffect:hover .overlay {
opacity:1;
filter:alpha(opacity=100);
}

.caption h4 {color:#fff !important; text-align:center; min-height: 55px; line-height:1.3em;}
.caption-2-line {text-align:center; margin-top:15px !important; min-height:50px; line-height:1.5em}
.caption-3-line {letter-spacing:1px; text-align:center; font-weight:600; margin-top:0px !important; margin-bottom:0px !important; line-height:1.3em !important; padding-bottom:30px; min-height:50px !important; font-size:112%; padding-left:0px !important; padding-right:0px !important}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="Keywords" content="">
<link rel="stylesheet" href="animate.min.css">
<style type="text/css">
body,td,th {
	font-family: Open Sans !important;
	font-size: 16px !important;
	color: #666666 !important;
	padding-top:54px
}


</style>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>
<body>


<!--projects-->
<div>
<div class="container-fluid">
<div style="display: flex;" class="row"> <!--remove flex for XS-->


 <!--pro4--><div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
           <div class="thumbnail hovereffect">
            <img src="http://placehold.it/500x300" alt="">
                <div class="caption">
                <h4>LIFE INSURANCE LANDINGPAGE</h4>
<p class="caption-2-line">Responsive Development / Bootstrap</p>
                <br><p class="caption-3-line c0fcfd1">WEB DESIGN</p>
                <div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a></div>
            </div>
          </div>
        </div>    
 <!--pro5--><div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
           <div class="thumbnail hovereffect">
            <img src="http://placehold.it/500x300" alt="">
                <div class="caption">
                <h4>BUSINESS CARD</h4>
<p class="caption-2-line">Personalized Design / Print</p>
                <br><p class="caption-3-line c0fcfd1">BRANDING</p>
                <div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a></div>
            </div>
          </div>
        </div>     
              

 </div>           
</div>
</div>

  
  </body>
  </html>

I have attached to this post an image as it look like atm and what I would like to do. enter image description here

I have tried to use some of these answers but they didn't work enter link description here

Upvotes: 1

Views: 70

Answers (2)

CFA Digital
CFA Digital

Reputation: 31

Chris Coyier over at css-tricks.com has a handy little article that covers multiple methods of centering with CSS.

Centering with CSS Complete Guide

Upvotes: 0

ketan
ketan

Reputation: 19341

Here display:flex can do the trick.

Use:

display: flex; 
align-items: center; 
justify-content: center;

You edited code:

.thumbnail {
  position: relative !important;
  padding: 0px !important;
  margin-bottom: 0px !important;
  border-radius: 0px !important;
  border-right: 1px solid #ddd !important;
  border-top: 1px solid #ddd !important;
  border-bottom: 1px solid #ddd !important;
  border-left: 0px solid #ddd !important;
}
.thumbnail img {
  width: 100% !important;
}
.thumbnail .caption {
  background-color: #333;
  color: #fff !important;
  padding: 9px;
  padding-top: 15px;
  height: 100% !important;
}
.hovereffect {
  width: 100%;
  height: 100%;
  float: left;
  overflow: hidden;
  position: relative;
  text-align: center;
  cursor: default;
}
.hovereffect .overlay {
  width: 100%;
  height: 100%;
  position: absolute;
  overflow: hidden;
  top: 0;
  left: 0;
  opacity: 0;
  background-color: rgba(0, 0, 0, 0.5);
  -webkit-transition: all .4s ease-in-out;
  transition: all .4s ease-in-out
}
.hovereffect img {
  display: block;
  position: relative;
  -webkit-transition: all .4s linear;
  transition: all .4s linear;
}
.hovereffect:hover img {
  -ms-transform: scale(1.2);
  -webkit-transform: scale(1.2);
  transform: scale(1.2);
}
.hovereffect:hover .overlay {
  opacity: 1;
  filter: alpha(opacity=100);
}
.caption h4 {
  color: #fff !important;
  text-align: center;
  min-height: 55px;
  line-height: 1.3em;
  display: flex;
  align-items: center;
  justify-content: center;
}
.caption-2-line {
  text-align: center;
  margin-top: 15px !important;
  min-height: 50px;
  line-height: 1.5em;
  display: flex;
  align-items: center;
  justify-content: center;
}
.caption-3-line {
  letter-spacing: 1px;
  text-align: center;
  font-weight: 600;
  margin-top: 0px !important;
  margin-bottom: 0px !important;
  line-height: 1.3em !important;
  padding-bottom: 30px;
  min-height: 50px !important;
  font-size: 112%;
  padding-left: 0px !important;
  padding-right: 0px !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="">
  <meta name="Keywords" content="">
  <link rel="stylesheet" href="animate.min.css">
  <style type="text/css">
    body,
    td,
    th {
      font-family: Open Sans !important;
      font-size: 16px !important;
      color: #666666 !important;
      padding-top: 54px
    }
  </style>

  <!-- Latest compiled and minified CSS -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

</head>

<body>


  <!--projects-->
  <div>
    <div class="container-fluid">
      <div style="display: flex;" class="row">
        <!--remove flex for XS-->


        <!--pro4-->
        <div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
          <div class="thumbnail hovereffect">
            <img src="http://placehold.it/500x300" alt="">
            <div class="caption">
              <h4>LIFE INSURANCE LANDINGPAGE</h4>
              <p class="caption-2-line">Responsive Development / Bootstrap</p>
              <br>
              <p class="caption-3-line c0fcfd1">WEB DESIGN</p>
              <div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a>
              </div>
            </div>
          </div>
        </div>
        <!--pro5-->
        <div style="padding-left:0 !important; padding-right:0px !important; " class="col-lg-2 col-md-3">
          <div class="thumbnail hovereffect">
            <img src="http://placehold.it/500x300" alt="">
            <div class="caption">
              <h4>BUSINESS CARD</h4>
              <p class="caption-2-line">Personalized Design / Print</p>
              <br>
              <p class="caption-3-line c0fcfd1">BRANDING</p>
              <div class="overlay"><a href="#" class="btn btn-info btn-xs" role="button">CHECK OUT</a>
              </div>
            </div>
          </div>
        </div>


      </div>
    </div>
  </div>


</body>

</html>

Upvotes: 1

Related Questions