0

I need to vertically align the banner in middle based on the height of the container div. I tried but it is not aligning

<div id="left-ad">
    <div id="sidebar"> <a href="#"><img src="sidewall.png" alt="LEft Banner" ></a>

    </div>
</div>
<div class="right-ad"> <a href="#"><img src="wad.jpg" alt="Right Banner" style="border-width: 0px" ></a>

</div>
<div class=wrapper>//center body part</div>

Fiddle: http://fiddle.jshell.net/6w7dvbzd/

Learning
  • 19,469
  • 39
  • 180
  • 373

3 Answers3

2

An option is applying display:table to container, and display:table-cell and vertical-align:middle to child, like so:

HTML:

<div class=wrapper>
    <div class="content">Content</div>
</div>

CSS:

.wrapper {
    display: table;
}

.wrapper .content {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

Updated JS Fiddle:

http://fiddle.jshell.net/6w7dvbzd/1/

Amar Syla
  • 3,523
  • 3
  • 29
  • 69
1

add to .wrapper a line-height and text-align like that :

the line-height based on wrapper height

.wrapper {
    width:200px;
    margin:0 auto;
    background-color:blue;
    height:150px;
    line-height:150px;
    text-align:center; }

JS FIDDLE

https://jsfiddle.net/aypye6g3/

IMAGE

enter image description here

dardar.moh
  • 5,987
  • 3
  • 24
  • 33
0

HTML:

<div class="wraper">
  <img src=image src"/>
</div>

CSS:

.wraper{  
    position: relative
    height: 160px;
    width: 160px;
    }
img {  
    max-height: 100%;  
    max-width: 100%; 
    width: auto;
    height: auto;
    position: absolute;  
    top: 0;  
    bottom: 0;  
    left: 0;  
    right: 0;  
    margin: auto
}
sanoj lawrence
  • 951
  • 5
  • 29
  • 69