Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"chevron" style nav bar in CSS & browser scaling problems

Tags:

html

css

I've been experimenting with making a HTML/CSS navigation bar with chevron-shaped list items. I've made my code available here: https://github.com/twslankard/css-chevron-bar/blob/master/index.html

Since my question is fairly specific, I'm offering up the code as public domain in the off chance that one of you CSS wizards will help me. :)

Now for my question. I've been trying to design the bar so that it scales properly, e.g. when someone modifies the font-size property of ul.chevronbar li or when the user hits Control+ or Control- in the browser.

I tried using two different CSS resets, both Eric Meyers Reset CSS 2.0 and YUI 3. However, in Firefox the scaling/zooming "mostly" works, and in Chrome it does not work (especially when zooming in). If possible, I'd like some advice on how to get this to work better in Chrome.

Here's an image illustrating the issue. Your help is greatly appreciated.

enter image description here

EDIT: this is what I ended up with eventually. Pardon the messy CSS. I'll get around to cleaning it up later.

https://github.com/twslankard/css-chevron-bar-2

EDIT 2: Another person generously provided their solution to this problem here: http://jsfiddle.net/pXBTK/3/

like image 824
Tom Avatar asked Aug 03 '12 18:08

Tom


People also ask

What is nav bar in CSS?

A navigation bar (also called a Navbar) is a user interface element within a webpage that contains links to other sections of the website. In most cases, the navigation bar is part of the main website template, which means it is displayed on most, if not all, of the pages within the website.

What is Navigation CSS?

A Navigation bar or navigation system comes under GUI that helps the visitors in accessing information. It is the UI element on a webpage that includes links for the other sections of the website. A navigation bar is mostly displayed on the top of the page in the form of a horizontal list of links.


1 Answers

Effectively, the trick is how to make the height of the pointy parts match the height of the menu item it follows, thus avoiding the jagged look.

I am guessing that something like this causes the problem:

  • Calculated menu item height is 5 physical screen pixels
  • Each of the top and bottom borders that produce the arrow must be 50% of 5
  • Since you cannot display a half pixel, both round off, say to 3 pixels
  • Add together and the arrow becomes 6 pixels tall but menu item is only 5

It seems clear then that the fix is to simply hide the overflow as stated. The only change really necessary to the original is:

ul.chevronbar {
  ...
  overflow: hidden; /* Add this line */
}

It would also need resizing to get closer to the original look, but works without that. Fixed height is not actually necessary.

This simplified example illustrates the arrow concept with highlighting for parts of the arrow:

<head><style type="text/css">
ul {
  background-color: lightgray;
  font-size: xx-large;
  overflow: hidden;
  position: relative;
}
li {
  display: inline-block;
  background-color: gray;
  margin-right: 1.5em;
}
li:after {
  content: '';
  border: 0.85em solid blue;
  border-left-color: red;
  border-right-color: red;
  height: 0;
  position: absolute;
  top: -0.2em;
}
</style></head>
<body><ul>
  <li>Lorem Ipsum</li> <li>Foobar</li>
</ul></body>
like image 192
ulfers Avatar answered Oct 11 '22 06:10

ulfers