Here's my scenario. I have a list of items, and I'm using CSS to turn them into a simple horizontal menu (see here to explain). To the right of each item, I want a vertical bar (like a |) but properly aligned, and not on the last item. So, I used the following css, putting a right-hand border on all but the last element:
ul.menu {
float: left;
padding: 0;
margin: 0;
list-style: none;
}
ul.menu li {
float: left;
position: relative;
padding: 0px 5px;
border-right: 1px solid #E00000;
}
ul.menu li:last-child {
border-right: 0;
}...
<ul class="menu">
<li>First Menu Item</li>
<li>Second</li>
<li>Etc..</li>
</ul>
The results: perfect in Firefox, not so in IE6: the last item in the list still has a border, because the :last-child pseudo-element isn't supported.
So, instead, I'm using the following javascript (this won't work without Prototype):
document.getElementsByClassName('menu').each(function(menu) {
$($(menu.immediateDescendants()).last()).setStyle({borderRight: '0'});
});Bingo! No border-right on the last menu item, in IE or Firefox. Yay!
hi, congratulation for the post. i'm facing a problem related and i hope u could help me. i've tried to use the code u posted and he prototype.js but the right border of my horzontal menu its still there.heres a fragment of my code:
ReplyDelete==language="JavaScript"==
document.getElementByID('HouseMenuNavList').each(function(HouseMenuNavList) {
$($(HouseMenuNavList.immediateDescendants()).last()).setStyle({ borderRight: '0' });
});
====================
div id="HouseMenuNav"
ul id="HouseMenuNavList"
li id="item1" li
li id="item2" li
li id="item3" li
ul
div
obs: i removed the open and close tag character because they are not allowed here in blogger.
can u help me?? whats wrong in my code??
any help or tip is welcome! :)