This question takes a bit of explaining. Please bear with me:
A few months ago, I set up a three-part header for a section on a website. On the left side of this header there is a Title, the contents of which can change. To the right side is a Logo, which will always be 150 px wide by 60 px high. Between them are a set of double lines. Something like this:
[THIS IS THE TITLE] ======================================= [Logo Here]
This website is responsive, so the overall width of the header is variable.
The Headline must always be on one line.
The div holding the double lines needs to change size to fill the space between the Title and the Logo.
I initially set it up so that the lines resized using media queries and the calc(); function. However, the website has to be compatible all the way down to IE 8, so I ended up writing some JS to get it to work.
Here is a JS fiddle that's essentially mirroring this behavior: http://jsfiddle.net/55u5mpu2/2/
function sizeLines() {
var logoSize = document.getElementById("the-logo").offsetWidth;
var titleWidth = document.getElementById("the-h2-Title").offsetWidth;
var totalWidth = document.getElementById("entire-Header").offsetWidth;
var offsetWidth = (logoSize + titleWidth);
var linesWidth = (totalWidth - offsetWidth - 20) + "px";
document.querySelector("#the-lines").style.width = linesWidth; }
window.onresize = sizeLines;
#entire-Header{
position: relative;
width: 100%;
height:40px;
}
#the-h2-Title {
position: relative;
float: left;
width: auto;
padding-right: 10px;
}
#the-lines {
border-top: 4px solid #000000 !important;
border-bottom: 4px solid #000000 !important;
height: 1px;
float: left;
margin-top: 23px;
min-width: 40px;
}
#the-logo {
position: relative;
max-width: 160px;
max-height: 50px;
float: right;
width: auto;
height: auto;
top: 0;
}
<div id="entire-Header">
<h2 id="the-h2-Title">
<div id="headlineTextbox">This is a Test Headline</div>
</h2>
<div id="the-lines"> </div>
<img id="the-logo" src="http://placehold.it/150x60">
</div>
The issue is, the script takes a long time to load on slow connections, and so the logo is hanging out in a weird spot for a while. As a result, I'm trying to find a purely CSS/HTML solution to do the same thing that my script is.
There are related questions here, but none of them seems to apply. I can't put a width on either the title or the lines, because they're both dynamic.
Tables seem to be working okay, but if I put width: auto; on two of the tds, things fail.
Here's an example of an okay table layout I've created: http://jsfiddle.net/d40a429s/1/
table {width: 100%;}
#test-title {width:20%;}
#lines-here {width:auto;}
#lines-here > div {border-top:4px solid #2a2a2a; border-bottom:4px solid #2a2a2a;height: 1px;}
#test-logo {width: 160px; padding-left: 10px;}
<div id="test-Section-Header">
<table>
<tbody>
<tr>
<td id="test-title"><h2>Test Title</h2></td>
<td id="lines-here">
<div></div>
</td>
<td id="test-logo">
<img src="http://placehold.it/150x60" alt="150 x 60 placeholder logo image">
</td>
</tr>
</tbody>
</table>
</div>
I've tried putting position: absolute; and a top/left or top/right on the logo and title, but I can't get that middle div to resize properly.
So: if anyone made it down here: Any ideas on how I can get this to work without JS? Or maybe a way to tidy up my JS to make it run faster?
Thanks!