javascript - Vertically align sans-serif font precisely at changing font-size -


my problem extension problem stated in earlier problem, see here vertically align sans-serif font precisely using jquery/css.

in nutshell: want align 2 divs text, 1 above other, in order align beginning of (basically lower left point of a) h (the left vertical line of h)? idea of i'm trying achieve:

the top div has varying font-size , want align lower div according font. reason scale font size according window size.

a demo on jfiddle .

html

<div id="hideheader" class="header" style="position: absolute;font-size:40pt;padding:0px;visibility: hidden;width:auto;height:auto;">header</div> <div id="header" class="header">header</div> <div id="menubar" class="menubar">     <div class="menubutton_left"><a href="#" id="workbutton">a</a>     </div>     <div class="menubutton_middle"><a href="#" id="aboutbutton">b</a>     </div>     <div class="menubutton_right"><a href="#" id="contactbutton">c</a>     </div>  <span class="stretch"></span>  </div> 

css

div.header {     font-family:sans-serif;     text-align:justify;     white-space: nowrap; } div.menubar {     text-align: justify;     -ms-text-justify: distribute-all-lines;     text-justify: distribute-all-lines;     margin-bottom: 0px;     position: relative; } div.menubutton_left, div.menubutton_middle, div.menubutton_right {     vertical-align: top;     display: inline-block;     *display: inline;     zoom: 1;     width:60px; } div.menubutton_left {     margin-left:12px; } div.menubutton_middle {     text-align: center; } div.menubutton_right {     text-align: right; } .stretch {     border: 2px dashed #444;     width: 100%;     display: inline-block;     font-size: 0;     line-height: 0 } 

jscript

resizehead("#hideheader", "#header");  $(window).resize(function() {   resizehead("#hideheader", "#header"); });  function resizehead(p1, p2) {     var fontsize = parsefloat($(p1).css("font-size"));     var spacing = parsefloat($(p1).css("letter-spacing"));     var initwidth = $(p1).width();     initwidth = initwidth - spacing;     var outwidth = $(p2).width();      var s = outwidth / initwidth;     s = fontsize * s;     $(p2).css({         "font-size": s     }); } 

try resizing browser window. becomes apparent smaller end of font sizes

i don't know if understand question.. but, due fiddle, think see want. recomend:

1: don't use js set increase font-size. can use variable size units vw, vh or vmin. change it's size according parent container, like: font-size: 20vw.

it lot lighter having javascript trigger on every window resize.

2: have set fixed width divs, whenever becomes smaller 60px layout break. remove it. can set dynamically calculated width, like: width: calc(100% / 3), 3 divs placed accordingly.

3: have set margin-left on first div breaks layout. instead, add margin <a> tag inside div:

div.menubutton_left {     margin-left:12px; } 

here's updated fiddle, changes (and no js \o/): http://jsfiddle.net/ksutq/7/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -