1

Situation: I created a full screen layover navigation for a html5 webpage including links displayed as images. I used images because of the special hover effect, which is not possible in code. This means that my links such as Home, About, Portfolio, Contact are made out of images (and not text) and displayed in a list.

I created two images per link: 1 for normal state and 1 for hover state. I used the replacing img technique shown here:

.foo img:last-child{display:none}
.foo:hover img:first-child{display:none}
.foo:hover img:last-child{display:inline-block}

Issue: The navigation works well on a large screen, but the trouble starts when scaling-down the viewport. The images controlled by max-width behave separate from each other and do not scale at a similar rate when scaling down the screen. Of course this relates to the biggest image (which hits the viewport border) to scale first and the smaller later. In my case: the Portfolio image will scale earlier than the Home image. This results in a strange looking navigation, as the images differ in size at some point.

Some other elements I considered:

  • I can make smaller images for smaller screens, but that would make a lot of images too load.

  • I can make all images the same size as the biggest image. But it means the smaller word will have empty spaces on the left and right of the word. This empty space will also activate the hover state, which makes it look strange (hover state activates while I'm not on the link itself (visually, not technically).

Question: How can I use an image-based navigation and scale down the navigation links/images equally when scaling down the viewport?

I made a JSFiddle for testing: DEMO

Thanks in advance.

WPasman
  • 25
  • 6

1 Answers1

0

I've been looking at this for a while and I'm beginning to think this isn't possible. The root of the problem is that each image would need to be aware of the largest image, or at least each of the <li>s would need to be aware of the other ones' dynamic height, which isn't possible with some sort of DOM manipulation. Even with flexbox I'm unable to make this work.

My advice would be to create each image the same width, using PNG transparency, then simply use an image map to activate the hover state over only the button area of each image. It's a bit of work but I can't think of a better way. See this StackOverflow question for ways to make the image maps.

Community
  • 1
  • 1
ian m
  • 504
  • 3
  • 7
  • thanks, yeah I was thinking about a set of rules like js: If the viewport touches the largest image all images start to shrink down, else nothing happens... something like that. But I'm unfamiliar with writing this code (if it is even possible). I will look into the image maps and otherwise switch to a different navigation all together. – WPasman May 03 '16 at 01:02