This question needs a little explanation. Please feel free to:
A few months ago, I created a three-part heading for a section on a website. On the left side of this heading is a Heading, the contents of which may change. On the right side is the logo, which will always have a width of 150 pixels and a height of 60 pixels. Between them there is a set of double lines. Something like that:
[THIS TITLE] ====================================== [Logo Here]
This site is responsive, so the overall width of the header is variable.
The title should always be on the same line. In order to fill the gap between the title and the logo, the div holding the double lines must be resized.
I initially set it up so that the lines change using media queries and calc (); function. However, the website should be fully compatible with IE 8, so I wrote some JS to get it working.
Here is a JS fiddle that essentially reflects 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 problem is that the script takes a long time to load slow connections, and therefore the logo hangs in a strange place for some time. As a result, I try to find a purely CSS / HTML solution to do the same thing as my script.
There are related questions here, but none of them seem to apply. I can’t put the width in either the header or the lines, because they are both dynamic.
The tables seem to work fine, but if I set width: auto; on two of tds, everything fails.
Here is an example of a suitable table layout that I 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 tried to put the position: absolute; and top / left or top / right logo and title, but I can’t get this middle div to resize correctly.
So: if someone did this here: Any ideas on how I can get this to work without JS? Or maybe a way to remove my JS so that it works faster?
Thanks!