My issue is an expansion of a previous problem I mentioned in another question, which can be found here Vertically align sans-serif font precisely using jquery/css.
To summarize: I am aiming to align two divs containing text, with one positioned above the other, so that the beginning of the letter A (specifically the lower left point) always aligns with the vertical line of H. Here's an example of what I'm trying to achieve:
The top div has a variable font-size and I want the bottom div to adjust its alignment according to that font size. This adjustment is necessary as I scale my font size based on the window's dimensions.
Check out this demo on jsfiddle.
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
}
JAVASCRIPT
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
});
}
Test resizing your browser window. The alignment issues become more evident at smaller font sizes.