html - Vertically align text divs with responsive font-size within a div -
i have div :
and tried making font-size of text responsive using code :
font-size:calc(xx + 1.5vw);
if make screen smaller headers not vertically aligned :
html :
<div id="topsection"> <div id="header1">header 1</div> <div id="header2">header 2</div> </div>
css :
#header1 { margin-left:220px; font-size:calc(20px + 1.5vw); color:#fff; } #header2 { color: #fff; margin-left:220px; font-size:calc(9px + 1.5vw); } #topsection { background-color:#222939; width:100%; height:75px; z-index:1; position:absolute; top:10px; left:0; color:white; }
i tried changing css headers :
#header1 { display: inline-block; vertical-align: middle; margin-left:220px; font-size:calc(20px + 1.5vw); color:#fff; } #header2 { display: inline-block; vertical-align: middle; margin-left:220px; font-size:calc(9px + 1.3vw); color: #fff; }
but looks :
you need content div center in middle. see example below. have tested in chrome.
.toolbar{ background-color:#222939; width:100%; height:195px; line-height:195px; z-index:1; position:absolute; top:0; left:0; color:white; } .toolbar .content{ display:inline-block; vertical-align: middle; } .toolbar .title { line-height:1; font-size:calc(20px + 1.5vw); color:#fff; } .toolbar .subtitle { line-height:1; font-size:calc(9px + 1.5vw); color: #fff; }
<div class="toolbar"> <div class="content"> <div class="title">header 1</div> <div class="subtitle">header 2</div> </div> </div>
final code
<!doctype html> <html> <head> <style> .toolbar{ background-color:#222939; width:100%; height:195px; line-height:195px; z-index:1; position:absolute; top:0; left:0; color:white; } .toolbar .content{ display:inline-block; vertical-align: middle; } .toolbar .title { line-height:1; font-size:calc(20px + 1.5vw); color:#fff; } .toolbar .subtitle { line-height:1; font-size:calc(9px + 1.5vw); color: #fff; } </style> </head> <body> <div class="toolbar"> <div class="content"> <div class="title">header 1</div> <div class="subtitle">header 2</div> </div> </div> </body> </html>
Comments
Post a Comment