css - How to vertical align h2 tag in a div -


i have html code:

<div class="news_item">         <div class="featured_leftpart">         <img src="" width="48" height="48" />     </div>     <div class="featured_rightpart">         <div class="news_content">             <h2 class="entry-title"><a href="" >text </a></h2>         </div>     </div> </div> 

and using css:

.news_item {     width:300px;     position:relative;     padding:10px;     height:100px;     margin:10px;     border:1px solid #e8e8e8; }  div.featured_leftpart {     position:relative;     float:left;     width:64px;     height:100%; }  div.featured_leftpart img{     position:absolute;     background-color:#ff00ff;     top:0;     bottom:0;     left:0;     right:0;     margin:auto; }  div.featured_rightpart {     background-color:#ff0000;         float:left;     width:180px;     padding-left:10px;     height:100%; }  .news_content {     background-color:#00ff00;     position:relative; }  .news_content h2 {     vertical-align:middle; } 

what i'm trying vertical align h2 tag. tag contain post title, single line, multiline. <div class="news_content"> attempt make work. if there solution without div, can remove it.

here jsfiddle link code above.

extending comment:

no need add .news_content, tell browser how high line , vertical-align work:

http://jsfiddle.net/cjasl/17/

<div class="featured_rightpart">     <h2 class="entry-title"><a href="" >text </a></h2> </div> 
div.featured_rightpart {     line-height:100px; /* calculated .news_item */ } .featured_rightpart h2 {     vertical-align:middle;     margin-top:0px; /* need clear default margin */     margin-bottom:0px; } 

beware, though, solution works if there's 1 line in title.

edit:

in case multiline not avoidable, wrapper seems not avoidable too:

http://jsfiddle.net/cjasl/18/

<div class="featured_rightpart">     <div class="title_wrapper">         <h2 class="entry-title"><a href="" >text<br />multi<br />line </a></h2>     </div> </div> 
div.title_wrapper {     display:inline-block;     vertical-align:middle;     line-height:1.25em; /* can adjust nice */ } 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -