views:

41

answers:

1

Hi!

I'm adding a new design to my website. The main menu ul stretches across the screen and the items are demarcated by simple borders. I'm having problems with the left and right borders for my menu items.

What's happening is that I can't properly display the borders on mouseover (a:hover) unless I space the margins so that in the normal state, the right border of Item1 and the left border of item2 "collide" in effect making a 2px wide border. I use the same image for the menu area, the normal buttons and the mouseover effect, but change the background position css uses where needed. No borders were drawn into the image.

<ul class="ServiceMenu">
    <li class="ServiceMenuItem"><a href="Pages/Service1.html>Service1</a></li>
    <li class="ServiceMenuItem"><a href="Pages/Service2.html>Service2</a></li>
    <li class="ServiceMenuItem"><a href="Pages/Service3.html>Service3</a></li>
    <li class="ServiceMenuItem"><a href="Pages/Service4.html>Service4</a></li>
</ul>

.ServiceMenu {
    margin: 0;
    width: 100% !important;
    height: 42px !important;
    display: block;
    border-top: 1px solid #0054a6;
    border-bottom: 1px solid #0054a6;
    background-repeat: repeat-x;
    background: transparent url("Images/ServiceMenuBG.png");
}
.ServiceMenuItem { display: inline-block; text-align: center; }
.ServiceMenuItem a, .ServiceMenuItem a:link, .ServiceMenuItem a:visited {
    color: #ffffff;
    padding: 11px 0 0 0;
    font-weight: bold;
    text-decoration: none;
    margin: -1px -2px;
    display: block;
    height: 31px !important;
    width: 198px !important;
    background-repeat: repeat-x;
    background: transparent url("ServiceMenuBG.png");
}
.ServiceMenuItem a:hover {
    color: #000000;
    background-position: 0 -42px;
    border-color: #999999;
}

I would decrease the margin in the .ServiceMenuItem a... styles, but this results in the right border disappearing on the hover.

So how do I set this up so that I have 1px borders without overlapping or "collision" of the vertical borders?

A: 

first of all your code seems to have errors. The URLs in the unordered list have no closing quotes ("). Then the image you are loading in CSS seems to be the same image yet once from an image folder and the other doesnt have it, that might not be your intention.

Anyway to fix your problem, give ".ServiceMenuItem a" a "border-right" with one pixel and desired color when not hovering. can be same color as image so that it is not visible. Then give the first list item an id. In you CSS add the id and give this a "border-left" which resembles the right borders of the other list items. under the hover, simply change the border-left and the border-right colors to the correct hover color, for top and border borders you can add them to the same ".ServiceMenuItem a" for better control.

Now you have a single border for each item on the right except for the first item which should have two borders, one covering the left side

Steve Obbayi
My code above has errors in it because it's pseudo code. The CSS is actual, but the HTML is fake.
Logan Young
@SteveIt works, but only for the first item. On all the other ones, the left border doesn't change on hover because I don't have a left border for `ServiceMenuItem a` specified.
Logan Young
I basically want to get all 4 borders to change color on hover without it looking like they have 2px side borders.
Logan Young
Oh i get it. Another CSS only way is to use set left-margin on each of the <li> elements except the first one to -1 so it overlaps the previous border. Then give all the <li> four borders and change them on hover this should give the desired effect
Steve Obbayi
Now I'm getting the same problem that I had originally... Now all the items work, except the first one. The problem here is that the mouseover doesn't change the color of the 2nd item's left border
Logan Young
All items need border-top, border-right, border-bottom, border-left, all items except the 1st item should have a margin-left of -1. what this does it makes all border-left lie on top of the border-right thus hiding it. so you may need to check that if not edit your code above and I have another look and see whats i get on my end
Steve Obbayi