Another vertical align issue

37 views Asked by At

JSFIDDLE: https://jsfiddle.net/o6ekutaL/

HTML

<div id="main-body-wrap">
  <div id="main-body">

<div id="home-featured-classes-wrap">

<div class="home-featured-class-A">
<div class="home-featured-class-4"> TEXT
<h6 class="products">TEXT

</div>

<div class="home-featured-class-3">THIS DIV NEEDS TO BE IN THE MIDDLE OF THIS PINK DIV, NOT AT THE TOP</div>

<div class="clear"></div>
</div>

</div>

<div class="clear"></div>

      </div></div>

CSS

/* MAIN BODY */
#main-body-wrap{
    width:100%;
    height:auto;
    margin: 0 auto;
    border-bottom: 1px solid #211c20;
    padding: 30px 0 30px 0;
}
#main-body{
    width:960px;
    height:auto;
    margin: 0 auto;
}

.clear {
  clear: both;
}

.home-featured-class-2{
    width:628px;
    height:auto;
    margin:0 30px 0 0;
    border: 1px solid #211c20;
    float:left;
}
.home-featured-class-3{
    width:628px;
    height:auto;
    margin:0 0 0 30px;
    border: 1px solid #211c20;
    float:left;
}
.home-featured-class-4{
    width:298px;
    height:auto;
    margin:0 0px 0 0;
    border: 1px solid #211c20;
    float:left;
}
.home-featured-class-A{
    width:100%;
    height:auto;
    background:#C3C;
    vertical-align:middle;
}
#home-featured-classes-wrap{
    width:auto;
    height:auto;
    margin: 30px 0 0 0;
}

I'm having more trouble vertically aligning the 'home-featured-class-3' div in the pink 'home-featured-class-A' div. Can someone please help? I can never succeed with vertical alignments

1

There are 1 answers

0
frontend_dev On BEST ANSWER

Try this: http://jsfiddle.net/o6ekutaL/2/

Notes:

  • You can vertically align using vertical-align: middle;
  • But this only works if your divs are set to display: inline-block;
  • By using display: inline-block; you do not need to set floats, it already does float then.
  • I set the widths using percentages, so it's a fluid layout as well.
  • An alternative would be using some display: table-cellhackery, but in general I'd prefer this one.