Navigation items padding: Firefox vs. Chrome&IE11 - html

I got strange problem with different rendering of one simple nav/menu. Here is code:
HTML:
<nav id="navigation">
<ul>
<li class="active">HOME<br><span>What we do</span></li>
<li>ABOUT<br> <span>Our expertise</span></li>
<li>SERVICES<br><span>Our products</span></li>
<li>WHY CHOOSE US<br><span>Our promise</span></li>
<li>NEWS<br><span>Updates</span></li>
<li>OUR CHOSEN CHARITY<br><span>Great Ormond Street</span> </li>
<li>CONTACT US<br><span>Get in touch</span> </li>
</ul>
</nav>
Relevant CSS:
#navigation {
width:100%;
clear:both;
background-color:#a9218e;
height:72px;
}
#navigation ul {
width:894px;
height:72px;
list-style-type:none;
margin:0 auto;
padding:0;
box-sizing:border-box;
}
#navigation ul li {
display:block;
float:left;
text-align:center;
padding:10px 22px 0 22px;
margin:0;
height:72px;
box-sizing:border-box;
}
#navigation ul li:last-child {
padding:10px 20px 0 19px;
}
#navigation ul li a {
color:#fff;
text-decoration:none;
width:100%;
height:72px;
font-size:15px;
font-weight:400;
}
#navigation ul li.active {
background-color:#00837e;
}
Test link: http://bybyweb.com/hygeineco/
Well... In Firefox, menu is perfect, it fits container's size (894px). However, in Chrome and IE11 (and i guess lower IE versions), one item is pushed down. So, i guess that there is no space for that item (contact) because of paddings. I've tried to resize container, or to reduce padding, and rendering difference is ~2px, between Chrome and Firefox... With container width of 896px - all is working fine in Chrome, in IE11, anyway, container width should be at least 903px?! What causes these strange differences? I guess that chosen google font rendering is different in every browser. How to solve this issue?

Add This Code Where Ever You Used box-sizing:border-box; :
box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-ms-box-sizing:border-box;
-o-box-sizing:border-box;
-webkit- is for Safari And Chrome
-moz- is for Mozila (but in your case , the browser could understand it without -moz- )
-o- for Opera and -ms- for IE ;

Almost solved it by using display:table for ul, and display:table-cell for li elements... However, now i just have to remove margin/padding at the bottom.... :)
EDIT: background image position was in question... so, now is perfect. Good old tables - still the best solution for some things. :)
EDIT2: I would remove this question, but i am sure it will help to someone who have similar situation. Conclusion -> when you have menu with different widths of/for every menu item, BUT if you want to place that menu inside fixed width container, setting of right/left padding to li elements (menu items) is obviously not the best solution. Display: table, and display:table-cell is the best (and maybe only?) possible solution.

Related

Am I messing with specificity ? What's going on?

I will short and clear. I have this html code snippet.
<nav>
<span class="heading">CodingHero</span>
<ul>
<li>Home</li>
<li>About</li>
<li>Services</li>
<li>Contact</li>
</ul>
</nav>
Now I have this CSS part
nav ul li a {
font-family:'Poppins', sans-serif;
font-size:20px;
color:white;
opacity:0.8;
margin:0px 20px;
}
This is also okay. But I found this weird behavior while dealing inside media queries.
nav ul a {
font-size:44px;
background-color:yellow;
margin:0px;
}
My background color works yellow fine.
But my font-size and margin doesn't work.
As soon as I provide specificity as I originally used in CSS part,
nav ul li a {
font-size:44px;
background-color:yellow;
margin:0px;
}
This works, my font-size and margin also comes into effect.
Can someone explain why I have to use the original selector that I first used to get all properties to act?
Why my font-size and margin were not applied when background color in same part is applied.
What's going on here? Any resources to clear my head.
Any response is appreciated.
Thanks !
background-color:yellow; was applied because the other selector with higher specificity (nav ul li a) doesn't contain a background-color property, so nothing overrides it.
If you were to add one like
nav ul li a {
font-family:'Poppins', sans-serif;
font-size:20px;
color:white;
opacity:0.8;
margin:0px 20px;
background-color: red; /* added */
}
then it'll override background-color:yellow, just like it override margin and font-size

IE7 first floating div sits higher than the rest, rest aligned fine

I have an issue where I have a set of href's floating next to each other. This looks fine in all browsers except the old IE versions in which the first link sits higher than all the other links.
CSS:
.google_pager
{
width:500px;
white-space:normal;
padding:20px 0 10px 0;
font-weight:bold;
font-size:1.1em;
overflow:auto;
}
.google_pager span
{
background-color:#6699C9 !important;
padding: 2px 6px;
color:#FFFFFF !important;
float:left;
height:0;
}
.google_pager a
{
padding: 2px 6px;
text-decoration:none;
float:left;
height:0;
}
A selected pager link becomes a span instead of a link.
All help is welcome!
I had this problem as well with PHP generated lists. Not sure if this is your exact problem, but ensure that your closing ul tag is on a new line. For example I used this line of code for my last li,
echo "<li><a href='#'>link</a></li>\n";
Sounds weird, but my problem looked the exact same as the example image you provided.
(P.S.) I realise this question was asked 6 months or so ago, but hopefully someone else will find this useful, as it was rather frustrating for me until I stumbled on the solution by accident!
Though I couldn't reproduce the issue without having your HTML, try applying display: block to .google_pager span and .google_pager a.
P.S. Also, any particular reason you are specifying zero height?
This is the best (being semantic) pattern for link lists. Follow this and they will work fine:
<div class="pages">
<ul>
<li>First</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>Last</li>
</ul>
</div>
CSS:
.pages ul, .pages li {
list-style=type:none;
padding:0;
margin:0
}
.pages li {
display:inline-block
}

I can't click the links in Firefox and Chrome (they work in IE7)

Its the weirdest thing I've ever seen. I can't click the last 3 links in the following code (when I use FF or Chrome):
HTML:
<div id="leftmanulist">
<div class="abouttop">
<ul class="aboutlist">
<li class="index"><a>成立宗旨</a></li>
<li>樂器編制</li>
<li>演奏曲目</li>
<li>服裝介紹</li>
<li>關於法輪大法</li>
<li>各界褒獎</li>
</ul>
</div>
<div class="aboutbutton"></div>
</div>
CSS:
#leftmanulist{ background:url("images/abouttop.gif") no-repeat;
float: left;
margin: 2px 2px 5px 30px;
padding:39px 0 0 0;
width:237px;}
#leftmanulist ul li{line-height:35px;text-align:left; text-decoration:none;}
#leftmanulist ul li a{ text-decoration:none;}
#leftmanulist ul li:hover{ color:#0068FF;}
#leftmanulist ul li a:hover{ color:#0068FF;}
#leftmanulist ul li.index{ color:#0068FF;}
#leftmanulist ul li.index a{ color:#0068FF;}
.abouttop{background:url("images/leftmanulist_z.gif") repeat-y ;
padding:0 6px; position:relative; z-index:0;
width:237px;}
.aboutlist{position:relative;left:28px;}
.aboutbutton{background:url("images/leftmanulist_b.gif") no-repeat;
width:237px; height:20px; position:relative; top:-17px; z-index:2;}
Works for me, but then I might not have the complete HTML/CSS.
If I had to make a guess I'd say your aboutbutton element is probably overlapping the bottom links (as you're positioning it top: -17px; and it has a higher z-index than abouttop). Give abouttop a higher z-index and see if that helps.
Something is most likely overlapping those elements in Firefox/Chrome. In Chrome, right click and inspect element. This will take you to the element that's overlapping in the tools panel, then....can't help you any further without more information, but if you update the question with that info we can.
Hopefully just identifying the overlapping element is an "ahhhhh that damn thing" moment and problem solved :)
For some reason I changed the z-index to 2 and worked.

CSS - :hover is slow/laggy in IE7

This is really strange. I've got this site where I have a list menu with a simple :hover effect on each item in the menu.
http://w3box.com/mat/
In Firefox it works just fine. But i IE7 atleast there's a lag. I haven't tested it in IE8 but my guess is that it's there as well.
Now, I've been trying out veriations to the code to see what might cause the issue. And I've seen alot of posts about similar scenarios. But none of them seemed to apply to my case.
So just now I noticed that in my css stylesheet, I've got this:
li:hover {
background-image: url(img/TopLine.png);
Height:29px;
}
Strange enough, if I remove the height specifications, there is no lag! What could be causing this? Could it be layers of padding and margins to the parent li class? Or the parent class above that one?
This is the code of these items. The rest of the css you can under /main.css of the site
#header {
padding-right:7%;
height: 57px;
background-image:url(img/TopLine.png); }
.header a {
font-family:georgia;
font-size:22px;
color:#ebebeb;
text-decoration:none; }
.header li {
float:right;
list-style: none;
margin-top:10px;
padding-top:18px;
padding-left: 23px;
padding-right: 23px;
height:23px; }
li:hover {
background-image: url(img/TopLine.png);
Height:29px; }
Any ideas on how I can improve this?
I'm not really getting any lag. The first time there is a slight delay though - this is most likely because the background image is loading.
You'd be better off setting a background on the list item proper then changing the background position on hover. (There are plenty of questions on SO about this.)

Hover Over a Menu Item Working in Firefox but not in Internet Explorer

Here is the coding in which hover is working inf firefox but not in IE
.menu
{
margin-top:1px;
display:inline-block;
background-color:#FCFAB4;
color:#000000;
height:30px;
width:121px;
padding-top:10px;
font-size:13px;
font-weight:bold;
font-family:Geneva, Arial, Helvetica, sans-serif;
text-align:center;
}
.menu:hover
{
background-color:#990000;
color:#FFFFFF;
border-bottom:#CC0000;
text-decoration:none;
cursor:pointer;
}
Help me
I don't believe the ':hover' pseudo-class is implemented for anything other than 'a' tags in IE. Try another approach (use 'onmouseover' event).
When you say IE it's better to let us know which (IE6/7/8). IE6 does not support :hover on anything but , IE7/8 do.
If you need this to work in IE6 you have a few options.
Refactor your code to only use 's in your menu.
Use a nice script from Dean Edwards to "upgrade" IE6 and IE7 for several issues such as this one. http://www.charlescooke.me.uk/web/lab_notes/ie7_script.html
You can use a bit of CSS and JS to give IE6 a way to recognise the :hover on other elements
/* Nice work around for IE6 issues with hover only being used on , con is that it needs javascript */
* html li {
behavior: expression(
this.onmouseover = new Function("this.className += ' hover'"),
this.onmouseout = new Function("this.className = this.className.replace(' hover','')"),
this.style.behavior = null
);
}
IE6 aside looking at your code I'm not really seeing how it works now. What you need is to have a menu element with what evers in it set to display:none, also you should position in using position:absolute/relative and top: XXpx/left: XXpx. Then on :hover you change to display: block.
Hope this helps,
Denis
Assuming your menu item is a link a user might select from a horizontal "menu" and looks close to this:
<ul class="menu">
<li>stackoverflow</li>
<li>google</li>
</ul>
Try this CSS:
.menu li{
display:inline;
list-style-type:none
}
.menu li a
{
margin-top:1px;
display:inline-block;
background-color:#FCFAB4;
color:#000000;
height:30px;
width:121px;
padding-top:10px;
font-size:13px;
font-weight:bold;
font-family:Geneva, Arial, Helvetica, sans-serif;
text-align:center;
}
.menu li a:hover
{
background-color:#990000;
color:#FFFFFF;
border-bottom:#CC0000;
text-decoration:none;
cursor:pointer;
}
If you are using an unordered list as a menu, the list items are not the "menu", the unordered list is the "menu", so apply the class there. And apply the CSS to the anchors to achieve hover functions.
If your menu is vertical, ignore display:inline on the .menu li styles.
IE7 supports :hover on anchors, but IE8 will support it on li's.