CSS removing border on tabbed navigation menu - css

I'm trying to create a simple tabbed navigation menu in CSS. I am having a hard time getting the bottom border to go away on the active tab. Normally this would not be hard to do, but I also want a line height set.. so I'm using inline-block with various IE and FF fixes. This makes it display the way I want, with the exception of the bottom border.
I have tried numerous methods for getting this to work, including setting up some operators.. but I don't know enough about CSS to determine if I was using them correctly.
Here is my jsfiddle.
(Obviously my CSS skills need work and I could probably simplify the code greatly as well.)
Code:
#tab_menu {
width: 100%;
overflow: hidden;
color: #000000;
border-bottom: #dddddd solid 1px;
}
#tab_menu ul {
padding: 0px;
margin: 0px;
}
#tab_menu li {
list-style: none;
line-height: 42px;
padding-left: 15px;
padding-right: 15px;
font-size: 14px;
font-family: Arial, Helvetica, sans-serif;
display: -moz-inline-stack;
/* Firefox Fix */
display: inline-block;
/* Normal Function */
zoom: 1;
/* IE Fix */
*display: inline;
/* IE Fix */
}
.tab_menu_active {
color: #000000;
border-bottom: none;
border-left: #dddddd solid 1px;
border-right: #dddddd solid 1px;
border-top: #dddddd solid 1px;
}
.tab_menu_active a {
color: #000000;
text-decoration: none;
}
.tab_menu_not_active {
}
.tab_menu_not_active a {
color:#52a4d4;
text-decoration: none;
}
.tab_menu_not_active:hover {
background: #eeeeee;
}
HTML:
<div id="tab_menu">
<ul>
<li class="tab_menu_not_active"> Link 1
</li>
<li class="tab_menu_active"> Link 2
</li>
<li class="tab_menu_not_active"> Link 3
</li>
<li class="tab_menu_not_active"> Link 4
</li>
<li class="tab_menu_not_active"> Link 5
</li>
</ul>
</div>

DEMO
for the #tab_menu I removed the overflow:hidden;
#tab_menu {
/*overflow: hidden;*/
}
to the .tab_menu_active I have added this styles, that will add border bottom white and with position manipulation will overidre the gray border color.
.tab_menu_active {
border-bottom:solid 1px #fff;
position:relative;
top:1px;
}
.tab_menu_active a {
position:relative;
top:-1px;
}

The problem you have is your entire #tab_menu has a bottom border. There are a couple ways you could solve this, but first I'll give you some details about how to simplify your css.
Give the li's the class tab, that means that every tab you have will all get the same css. On the active one, give it a second class, active. In your css definitions, define that all tab's should have the same css (instead of having duplicate css in tab_menu_active and tab_menu_not_active).
I would recommend giving them all a border on the bottom, and then removing that border in the active one.
Here's a forked jsfiddle.

Related

Why is my a:hover css working differently in Firefox?

I cannot figure this out. I HAVE DONE RESEARCH so please, no comments about me doing more research. Also, I am a noob, so be nice ;)
Here's my site: http://library.skybundle.com/
Hover your mouse over the two black rectangles in the main blue nav bar (header area). The a:hover should make the color change to a gray. The ISSUE is that in Chrome, this looks perfect. But, in Firefox, the padding-right isn't long enough or something, so there is always a small black rectangle at the far right side of the "Educational Courses" button (this will only be visible when hovering your cursor over the button). In other words, the gray box doesn't go all the way to the right-side end of the button area upon mouse hover. I just don't understand why this looks and works great in Chrome, but bugs out in Firefox...
Believe me when I say I have tried everything I can to fix it using Firebug in Firefox. If you play around with it using an editor in your browser, you will see that if you try to make the padding longer for Firefox, it pops the whole button down onto a new line. So to fix THAT problem, you must make the container wider, but then the original problem comes back. It's a circle of problems and I'm sure one of you geniuses out there will see a simple solution that I am missing.
Please help. Thanks!
EDIT :
Here's my JSFiddle and code. Notice how it looks great in Chrome but not in Firefox?
http://jsfiddle.net/S4st8/
HTML:
<div id="navigation">
<div id="navigation-inner">
<div id="page-nav">
<div id="primary-nav">
<ul id="top-menu">
<li id="li-left">Product Training Videos</li>
<li id="li-right">Educational Courses</li>
</ul>
</div>
</div>
</div>
</div>
CSS:
#navigation {
background: url(http://library.skybundle.com/wp-content/themes/business-services/library/styles/colour-images/mu-nav.jpg) repeat-x;
margin: 0px;
padding: 0px;
height: 40px;
width: 100%;
}
#navigation-inner {
margin: 0px auto;
padding: 0px;
height: 48px;
width: 960px;
}
#page-nav {
margin: 0px;
padding: 0px;
height: 40px;
width: 960px;
}
div#primary-nav {
position: relative;
display: block;
float: left;
margin: 0;
padding: 0;
}
ul#top-menu {
margin: -5px 0.325em 0 0.325em;
position: absolute;
padding: 0;
z-index: 100;
top: 0;
left: 3em;
width: 367px;
}
ul#top-menu li {
line-height: 3em;
list-style-type: none;
height: 49px;
background-color: #2C2C2C;
float: left;
}
li#li-right {
list-style-position: inside;
border-left: 2px solid #5E5E5E;
}
ul#top-menu li a {
font-weight: bold;
font-size: 11pt;
text-decoration: none;
padding: 15px 10px 16px 10px;
color: #ffffff;
}
ul#top-menu li a:hover {
text-decoration: none;
width: auto;
color: #ffffff;
background-color: #505354;
padding: 15px 10px 17px 10px;
}
its because a tags (anchor tags) have a default display property of inline
due to CSS Box Model you would need to adjust your padding and set the anchor tags display property to display:block;
the display block allows the anchor tag to fill the whole space of the LI tag
change ul#top-menu li a to this:
ul#top-menu li a{
color: #FFFFFF;
font-size: 11pt;
font-weight: bold;
display: block; /* add this */
padding: 0 10px; /* add this */
}
the CSS Box Model adds the content + padding + border + margin
https://developer.mozilla.org/en-US/docs/Web/CSS/box_model
Take a look at this CSS rule:
li#li-right {
border-left: 2px solid #5E5E5E;
list-style-position: inside;
}
Dropping list-style-position: inside seems to fix your issue in Firefox (and still works in Chrome), but I haven't tested the implications in other browsers. The CSS rule is documented here.
The reason why : browsers apply their own css if you don't specify it. Firefox added the space for your bullet (somehow)
FF :
list-style-image none
list-style-position outside
list-style-type disc
GooChrome :
list-style-image: none;
list-style-position: inside;
list-style-type: none;
User JasonSperske gave you a fixing solution,
i invite you to RESET your css.
PS. in the meantime, you are invited to see : https://stackoverflow.com/help AND http://sscce.org/
Reading and understanding those pages will give you few reputations points

Problems with rounded horizontal CSS navigation menu

I'm designing a navigation menu for a website.
The menu must have rounded corners, I've done this using 'border-radius'.
I've set the width as 800px as that's the rough width the menu needs to be, if I remove the width or put width: auto the width goes to 100%.
There is a gap before the first button and after the last button in my navigation menu and what I need to get rid of this gap without losing the curved edges.
How can I make the first and last buttons maintain rounded outside corners and remove the gap between each side of the navigation.
CSS:
/* CSS MENU */
#menu {
/* DISPLAY SETTINGS */
text-align: center;
height: 40px;
width: 800px;
margin: 0;
padding: 0;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
/* APPEARANCE SETTINGS */
border-top: 2px solid #356AA0;
border-left: 2px solid #356AA0;
border-bottom: 2px solid #204061;
border-right: 2px solid #204061;
background: #628ddb;
/* FONT SETTINGS */
color: #15387a;
font-family: Arial, sans-serif;
font-weight: bold;
text-transform: uppercase;
font-size: 12px;
}
/* LIST SETTINGS */
#menu li {
display: inline-block;
}
/* HYPERLINK SETTINGS */
#menu li a {
text-decoration: none;
display: block;
padding: 0 15px;
line-height: 40px;
}
/* HOVER AND ACTIVE BUTTON SETTINGS */
#menu li a:hover, #menu li.active a {
color: #15387a; background: #3D7BBB; border-bottom: 2px solid #204061
}
HTML
<ul id="menu">
<li class="active end">Home</li>
<li>Our Services</li>
<li>Testimonials</li>
<li>Get A Quote</li>
<li>Drive For Us</li>
<li>Terms & Conditions</li>
<li class="end">Contact Us</li>
</ul>
So there are several things that need to happen in order to maintain your design:
1.) The UL tag needs to have display: table
2.) Like what #Netsurfer You'll need to set the LI to have display: table-cell so that the list items flush to the edges
3.) Now that UL has rounded corners, any child elements with squared corners will stick out. You can either:
a.) Resolve this by applying overflow: hidden to both the UL and LI or
b.) Apply the rounded corners to the LI and A tags.
4.) Your :hover & active state applies a bottom border -- the table-cell will cause this to look strange. It might be better to remove it altogether.
You can check out the code here: http://jsfiddle.net/vuAVV/
Remove text-align: center; from #menu.
You might also want to include padding-left: 10px; to make sure when the first link is highlighted it does not overlap with the rounded corner of the menu.
See this working jsFiddle.
Change the display setting for the LIs to display: table-cell.
By doing so you are also not "trapped" by the white-space issues when using display: inline-block.
See jsFiddle
PS: Forgot the rounded corners ..., now also included. ;-)

Unordered list item background image scaling down in Safari but not Chrome

My problem is that background images to list items ("li") in an unordered list ("ul") are behaving wildly different across browsers. I am not sure how to best approach the problem. The code renders nicely in Apple-WebKit browsers, but images don't scale down properly to the "li" bounds in Chrome or Firefox.
I realize I could scale the images to the "correct" resolution but then I'd have to implement all that user ID 2x swapping for retina and high DPI displays, which will really be a maintenance hassle as this icon grid will regularly change over time.
The CSS is structured the way it is with id wildcards because I'll eventually be having different characteristics for each "li." Styles in this example are coded inline with the page's header.
I'm hoping that I am missing something simple and elegant like perhaps defining a div somehow within or around a "li" but I think I may have tried that already with confoundingly mixed results.
Thanks very much for the advice.
The example page is here:
https://dl.dropboxusercontent.com/u/35370696/iframes/FrontGrid.html
Style extract:
ul[id="GridBox"]
{
position:relative;
list-style: none;
margin-left:auto;
margin-right:auto;
width: 940px;
height: 370px;
}
li[id^="Cell"]
{
color: #FFFFFF;
float:left;
background-color:green;
position:relative;
max-height:70px;
max-width:70px;
height:70px;
width:70px;
background-size:70px 70px;
margin-top: 12px;
margin-left: 12px;
margin-bottom: 12px;
margin-right: 12px;
line-height: 20px;
display: block;
font-family: abel, sans-serif;
font-size: 10px;
font-weight: 400;
text-align:right;
box-shadow: 3px 3px 3px #888888;
}
li[id="Cell1"]
{
background: url(images/Sears.png);
}
li[id="Cell1"]:hover
{
background: url(images/SearsReverse.png);
color: black;
}
li[id="Cell1"]:active
{
box-shadow: 3px 3px 3px transparent;
color:#7BB1FF;
}
Content extract:
<ul class="Icons" id="GridBox">
<a href="http://www.diacritica.pe">
<li id="Cell1">ALWB  </li></a>
<li id="Cell2">ALWB  </li>
<li id="Cell3">ALWB  </li>
<li id="Cell4">ALWB  </li>
<li id="Cell5">ALWB  </li>
<li id="Cell6">ALWB  </li>
<li id="Cell7">ALWB  </li>
<li id="Cell8">ALWB  </li>
[etc…]
By using the shorthand background property, you're overwriting all of the previously set background styles. If you only want to change the background image, you'll want to use background-image instead.
li[id="Cell1"] {
background-image: url(images/Sears.png);
}
li[id="Cell1"]:hover {
background-image: url(images/SearsReverse.png);
color: black;
}
Alternately, you could redefine the other styles.

appendChild probably keeps hover css state in IE9

I am strugling to make a simple function work in IE9. It works perfectly in Chrome and FF.
The purpose is to have 2 "ul" lists and move "li" elements between them, on click.
I would like to have li elements with blue background in the first container (MultiListAvailableElements), changing to green on mouse over. And opposite in the second container (MultiListSelectedElements) - green background, changing to blue on mouse over.
The problem is that in IE9 element's behave like they never loose hover state after I append them to opposite list. I have to move mouse over them (and out) to make them look like they should. So, for example, I click blue element from first container, it moves to second container and is still blue (blue in the second container is only for hover state, it should be green by default as the mouse is no longer over the element because the element has moved to different place). Then I have to move mouse over and out the elements in second container to make them come back to normal (green color).
HTML:
<div style="height: 210px; width: 600px;">
<div class="MultiListAvailableElements">
<ul id="OptionsUL">
<li id="id1" onclick="MLAdd(this)">1</li>
<li id="id2" onclick="MLAdd(this)">2</li>
<li id="id3" onclick="MLAdd(this)">3</li>
<li id="id4" onclick="MLAdd(this)">4</li>
<li id="id5" onclick="MLAdd(this)">5</li>
</ul>
</div>
<div class="MultiListSelectedElements">
<ul id="SelectedUL">
</ul>
</div>
</div>
CSS:
/* ------------------------------------ Available Elements --- */
.MultiListAvailableElements {
overflow-y: scroll;
width: 250px;
height: 200px;
border: 1px solid black;
}
.MultiListAvailableElements ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
.MultiListAvailableElements ul li {
background-color: #e5ecff;
border: 1px solid #c3caff;
width: 180px;
text-align: center;
margin-bottom: 2px;
padding: 2px;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: small;
}
.MultiListAvailableElements ul li:hover {
background-color: #e5ffec;
border: 1px solid #a3ffaa;
}
/* ------------------------------------ Selected Elements --- */
.MultiListSelectedElements {
overflow-y: scroll;
width: 250px;
height: 200px;
border: 1px solid black;
}
.MultiListSelectedElements ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
.MultiListSelectedElements ul li {
background-color: #e5ffec;
border: 1px solid #a3ffaa;
width: 180px;
text-align: center;
margin-bottom: 2px;
padding: 2px;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: small;
}
.MultiListSelectedElements ul li:hover {
background-color: #e5ecff;
border: 1px solid #c3caff;
}
JavaScript:
function MLAdd(Obj) {
document.getElementById("SelectedUL").appendChild(document.getElementById(Obj.id));
document.getElementById(Obj.id).onclick = function () { MLDel(Obj); }
}
function MLDel(Obj) {
document.getElementById("OptionsUL").appendChild(document.getElementById(Obj.id));
document.getElementById(Obj.id).onclick = function () { MLAdd(Obj);
}
You don't actually have to clone. Just remove it and append it elsewhere. Also, you don't have to request the element from the DOM because you are already passing it as an argument to the function (it's coming from the this in the original function call).
function MLAdd(Obj) {
Obj.parentNode.removeChild(Obj);
document.getElementById("SelectedUL").appendChild(Obj);
Obj.onclick = function () { MLDel(Obj); }
}
I'd also cache the results of document.getElementById("SelectedUL") as well by setting it in a variable from within a closure, but I'll leave that for you to figure out.

CSS, menu:active not working

I have a simple menu:
<ul id="menu2">
<li> Home</li>
<li> About us</li>
<li> Contacts</li>
</ul>
And in css file I have:
#menu2 {
background: black;
float: left;
list-style: none;
margin: 0;
padding: 0;
width: 220px;
}
#menu2 li {
margin: 0;
padding: 0;
}
#menu2 a {
background: black;
border-bottom: 1px solid #393939;
color: #ccc;
display: block;
margin: 0;
padding: 9px 16px;
text-decoration: none;
}
#menu2 a:hover {
background: black url("../images/select.png") left center no-repeat;
color: #fff;
padding: 9px 16px;
}
#menu2 a:active {
background: black url("../images/select.png") left center no-repeat;
color: #fff;
padding: 9px 16px;
}
Everything works well except for #menu2 a:active not working at all while #menu2 a:hover (with same rules) works well. What is the problem? Did I miss something?
It is working as expected. I colored the active state red.
Try clicking on en element and hold the button down. The background will be red.
You don't see a change, because you CSS for hover and active are identical!
Sample
http://jsfiddle.net/dqH3F/1/
Sample contains
#menu2 a:active {
background: red url("../images/select.png") left center no-repeat;
color: #fff;
padding: 9px 16px;
}
Can you provide more details of what exactly is not working and/or a demo. Looking at the code it appears to be fine.
The :active state refers to when a link is pressed, so if you press and hold your mouse button down on your menu item it should be working as expected since hover works active has the same properties.
A link with :active will not remain that way when your on the page it links too, it reverts back to a normal link.
Your background for :hover and :active in the code above is the exact same.
Are you trying to set a background x and y position on active?
Without image background and different colors (for testing) your code works fine: see here http://jsfiddle.net/stursby/9Pccb/

Resources