technology_dreamer technology_dreamer - 2 months ago 7
HTML Question

Vertical align and height inside float div issue

We have reviewed a tone of questions here in Stackoverflow about vertical align and height 100% issues like:

http://stackoverflow.com/questions/6743208/css-why-vertical-align-middle-does-not-work

Fill height of a floating nested div

css div 100% height issue

And more similar links, but none of them has helped us.




JSfiddle code: http://jsfiddle.net/cD6nd/1/

HTML code:

<div id="header">
<div id="logo_container">
<a href="main-catalog"><img src="img/logo-finder.png" alt="Logo Example"></a>
</div><!--Logo container-->
<a href="main-catalog" id="aplication_lookup_button" class="button_link">Search by application</a>
<a href="search-product-catalog" id="search_product_button" class="button_link">Search by part number</a>
</div><!-- Main header where logo and buttons are showed it -->


CSS code:

#header
{
width:100%;
background: #000;
float:left;
}

#logo_container
{
width: 14.0056%;
text-align: center;
float: left;
}

#logo_container img
{
max-width: 50%;
height: auto;
}

.button_link{
text-align: center;
color: white;
text-decoration:none;
text-transform: uppercase;
width: 25%;
height: 4.1em;
float: left;
}

#aplication_lookup_button
{
background: #424242;
border-bottom: 4px solid #2eaeb8
}

#search_product_button:hover
{
color: #2eaeb8;
font-weight: bold;
}


Here's a snapshot of how it looks at this moment:

enter image description here




We want that a-href texts be in the middle of the container and we would like to use
height:100%
instead of use
em
's that we are using currently.

Answer

you could use pseudo-element and inline-block property :

.button_link:before {
        content:'';
    display:inline-block;
    height:100%;
    vertical-align:middle;
    }

http://jsfiddle.net/cD6nd/5/

This technique can be useful if you want to wrap text in an inline-block element and display more than one line http://jsfiddle.net/cD6nd/6/

Comments