Problem: the middle bar is a pixel taller than the other bars. This is not because I got the css wrong, it's because browsers align the edges of rectangles to the pixel grid.
I've tried a few different ways of making a hamburger icon:
absolutely position a few divs with background-colors.
inline svg tag
svg as a background image
single div with top/bottom border and background-color for the bars, and padding and
background-clip: content-box;
for the spaces.
All of these methods have the same problem:
At some zoom-levels/sizes, the icon looks bad because the three rectangles aren't all the same size. They're different sizes sometimes because browsers like to align the edges of rectangles with the pixel grid.
I of course want the two spaces between the rectangles to be the same thickness too.
I get that this comes with the compromise that the icon must be a multiple of 5px tall. Or, if you can expand the spaces by one pixel at alternating breakpoints than when you expand the bars, then it can be 2X or 3X as many different sizes.
So what's the trick?
Can a webfont use hinting to make it so all three rectangles get the same number of pixels of thickness regardless of size/resolution/zoom?
Is there some sort of CSS math I can do?
I'm really hoping I don't have to have JavaScript that tries to detect changes in the zoom level.
EDIT: LIVE DEMO
var hamburgerIconEl = document.getElementById('hamburgerIcon');
var fontSizeEl = document.getElementById('fontSize');
fontSizeEl.addEventListener('input', function (e) {
hamburgerIconEl.style.fontSize = '' + (8 + parseFloat(fontSizeEl.value) / 100) + 'px';
});
.body {
background: white;
}
#hamburgerIcon {
box-sizing: border-box;
display: inline-block;
height: 1.7ex;
width: 2.04ex;
border-width: .34ex 0;
border-style: solid;
border-color: black;
background-clip: content-box;
padding: .34ex 0;
background-color: black;
}
<p>Change the font size, watch the hamburger icon, see how there are a lot of sizes in which the bars don't all have the same thickness and/or spacing.</p>
<div>
<input type="range" id="fontSize" min="0" max="1000" value="0">
<label for="volume">Font Size</label>
</div>
<div>
<div id="hamburgerIcon" style="font-size: 8px"></div> Menu
</div>