html - vertically-center floated blocks using css without using tables or absolute positioning -


i trying vertically center images in header.

http://jsfiddle.net/falven/qbcswo0g/1/

<header>     <div class="centered">         <nav>             <ul>                 <li><a href=""><img src="http://dapper-apps.com/media/nav/atfranconav.png" alt="at franco"></a></li>                 <li><a href=""><img src="http://dapper-apps.com/media/nav/kamisnightmarenav.png" alt="kami's nightmare"></a></li>             </ul>         </nav>         <h1><a href="/"><img src="http://dapper-apps.com/media/logo.svg" alt="dapper apps"></a></h1>         <nav>             <ul>                 <li><a href=""><img src="" alt="spotter"></a></li>                 <li><a href=""><img src="http://dapper-apps.com/media/nav/dapperappsnav.png" alt="about"></a></li>             </ul>         </nav>     </div> </header>  .centered {     margin: 0 10% 0 10%; }  header {     background-color: #fff;     width: 100%;     z-index: 2;     position: fixed;     transition: 0.15s linear;     border-bottom: 1px solid #d6d6d6; }  header > div {     overflow: hidden; }  header > div > h1 {     width: 50%;     float: left;     overflow: hidden; }  header > div > h1 > > img {     width: 100%; }  header > div > nav {     width: 25%;     float: left;     text-align: center; }  header > div > nav > ul {     list-style-type: none;     margin: 0;     padding: 0; }  header > div > nav > ul > li {     display: inline;     width: 50%; }  header > div > nav > ul > li > > img {     width: 25%;     max-width: 50px; } 

all of answers have found involve using semantically-incorrect table layouts , absolute positioning not work in case because header fixed. in essence, able keep adding list items navigation links in header , have header grow vertically automatically does, keep nav , h1 elements centered vertically , occupying entire height of header.

you use inline block vertical align property. make sure remove float properties nav , h1.

http://jsfiddle.net/qbcswo0g/3/

header > div {     font-size: 0; /* fix white space */ }  header > div > nav, header > div > h1 {     display: inline-block;     vertical-align: middle;     font-size: 16px; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -