Css problem with IE/FF compatibility - css

I have some CSS that doesn't behave correctly with IE8. It works fine with FF3, but in IE8 there are white boxes in between the list items and the whole thing is buggy.
here is the css in question
#golist {
width:900px;
margin-top:20px;
margin-right:auto;
margin-left:auto;
}
#listing {
list-style:none;
margin:0;
padding:0;
}
#listing li {
float:left;
display:block;
width:128px;
background:#fff;
border:1px solid #000000;
height:96px;
}
#listing li a {
border:none;
}
#listing p {
margin-bottom:0;
}
/* ---- show-hide elements ---- */
#listing li .show{
display:block;
width:128px;
height:96px;
}
#listing li .hide {
color:#121212;
text-align: left;
height: 0;
overflow: hidden;
background-image:url(bghover.png);
}
#listing li:hover .hide, #listing li.over .hide {
cursor: pointer;
height: 96px;
width:128px;
text-align:center;
}
#listing li:hover .show, #listing li.over .show {
height: 0;
overflow: hidden;
}
#listing li a, #listing li a:visited, #listing li a:active {
color:#121212;
font-size:12px;
text-decoration:none;
}
#listing li a:hover {
color:#121212;
text-decoration:none;
}
And here is the code itself:
<div id=golist>
<ul id=listing>
<li class=show>
<a href=#>
<img src=images/image.jpg height=96px width=128px border=0>
</a>
<div class=hide>
<a href=link.html>Link</a>
<p>Some info</p>
</div>
</li>
</ul>
</div>
The idea is to have a 128x96 box with an image. On mouseover, a layer pops up over it with some text.

Here you can found about this: http://webdesign.about.com/od/internetexplorer/a/aa082906.htm
This is a part of the article:
It's actually really easy to hide styles from IE 6 but make them visible to standards compliant browsers. Use child selectors.
In one design I built, I created a two column layout that required margins and padding. This meant that I was hitting the box model differences when I viewed the page in IE 6. My first CSS style sheet for Firefox included a line like this:
div#nav { width: 150px; margin-left: 20px; }
This made the page line up perfectly in Firefox and Safari, but in IE the nav column was pushed over to the right too far.
So, I converted the line to use child selectors. The #nav div is a child of the body tag, so I changed the line to read:
body > div#nav { width: 150px; margin-left: 20px; }
Of course, doing this made the #nav div lose all it's properties in IE, so I needed to add in some IE styles to get IE 6 looking okay. I added this line to the CSS:
#nav { width: 150px; margin-left: 10px; }
The placement of this line of CSS is important if my page is still to look good in Firefox and Safari. The IE line needs to come first. Firefox and Safari will read that line and then it will be over-ridden by the body > div#nav selector lower in the document. IE 6 will read the first line and set the styles. It will then ignore the child selector, as it doesn't recognize them. When IE 7 comes along, it will act like Firefox and Safari.
By designing for a standards-compliant browser first, and then modifying your CSS to support IE's quirks, you spend a lot less time fiddling with the design and a lot more time actually designing.

Start by clearing all of the default padding and margins in your css file using:
* { padding: 0; margin: 0 }
Then you'll have to adjust your code accordingly as every browser adds its own padding and margins to all attributes.
Once you get it to the point where you're happy with it in Firefox and Safari, use conditional statements to pull in the appropriate IE stylesheet:
<!--[if IE 6]><link href="css/CSSName_IE6.css" rel="stylesheet" type="text/css"><![endif]-->
<!--[if IE 7]><link href="css/CSSName_IE7.css" rel="stylesheet" type="text/css"><![endif]-->
<!--[if IE 8]><link href="css/CSSName_IE8.css" rel="stylesheet" type="text/css"><![endif]-->
In your stylesheets only override what needs overriding:
Master CSS
.iframestyle { float: left; margin-right: 3px; width: 305px; }
IE 6
.iframestyle { width: 309px; height: 263px; }
IE 7
.iframestyle { width: 309px; margin-top: 0px; }
IE 8
.iframestyle { width: 305px; margin-top: 0px; }
(For whatever reason IE 8 may need a redeclaration of width.)

Related

Why isn't my CSS working in IE 8 and IE 7?

What in this CSS doesn't work in IE8 & IE7?
nav {
position: fixed;
top:60px;
left:30px;
color:black;
float:left;
}
nav div#button {
width:205px;
height:50px;
text-align: center;
padding-top: 5px;
margin-bottom:10px;
font-size: 23px;
}
nav a {
color: #000000;
text-decoration: none;
}
nav div#button:active {
width:250px;
height:65px;
}
nav div#button.home {
background-color: #79b22c;
}
nav div#button.links {
background-color: #3b50cc;
}
nav div#button.aanbod {
background-color: #BA3BCC;
}
nav div#button.forum {
background-color: #1CAEB2;
}
nav div#button.contact {
background-color: #daa520;
}
It works fine in IE9 & IE10. But IE8 & IE7 displays no-styled text.
I have tested with browserstack.
Who can help me please?
<nav> and other HTML5 elements were defined after IE 7 and IE 8 were released, so the browsers aren't aware of how to handle them.
They can, however, be instructed to handle them. And, the html5shiv can help with this:
Include the HTML5 shiv at the top of your <head> in a conditional comment after any stylesheets.
<!--[if lt IE 9]>
<script src="html5shiv.js"></script>
<![endif]-->
Try using:
<!DOCTYPE html>
Also you don't need:
div#menu You need #menu
At the top of your code
Delete color and just use background
Position: fixed not work in ie7. Use should use expression() for this in css and position absolute.

IE8 bug - CSS "a:hover" attribute not working

I have a list of anchor links that have associated :hover attributes - really simple. The CSS works fine in IE7 and all other browsers, but not in IE8.
.header-nav ul li a:hover {
border-bottom: 1px dotted #fff;
}
I tried changing my doctype declaration from HTML5 to HTML4 strict and nothing changed - any ideas?
Thanks!
EDIT: associated HTML:
<ul>
<li>Getting Started
</li><li>Refill
</li><li>Status
</li><li>Services
</li><li>Conditions</li>
</ul>
Regular CSS:
.header-nav ul {
list-style-type:none;
margin:0;
padding-left:25px;
position: absolute;
top: 10px;
*top: 15px;
left: 0;
}
.header-nav ul li {
display: inline-block;
zoom: 1; *display: inline; /* Fix for IE7 */
padding: 0 40px;
}
.header-nav ul li a {
text-decoration: none;
line-height: 23px;
font-size: 18px;
position: relative;
top: 7px;
*top: 2px; /* IE7 */
color: #fff;
}
Again, to be clear, this works in IE7 but NOT in IE8, which is the confusing part...
This issue was due to the position:relative on the .header-nav ul li a tag... I have no idea why IE8 couldn't handle this (and IE7 could!). My fix was to simulate the relative positioning by just making the line-height attribute larger (and adding a *line-height to account for differences in the IE7 rendering).
If anyone has any insight on why this issue was caused I'd love to hear it!
Hope this helps future confused front-end devs that are stuck accounting for older versions of IE...
I has this issue in IE8, and the above solution did not work.
In the end the reason the above did not work is something to do with the fact that I am using datatables and I am using ajax to get the data asynchronously. The hover works fine if I switch the table to using static data, but does not work with ajax.
I am guessing its something to do with IE not being able to apply styles to dynamically added row or something.
It works fine in Chrome...!
Below a 100% working solution.
.navigation li ul { opacity: 0; visibility: hidden; filter: alpha(opacity=0); // for ie8 and lower }
.navigation li:hover ul{ opacity: 1 !important; visibility: visible; filter: none !important; }
you can add following line to the top of your html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

css nav ul not working

I made a new website and my problem is that the menu is ok in FF and other browsers, but not in IE.
The problem is, it wont list the list elements, no hover , no color, and not inline.
here is the code
nav {
margin-top: 15px;
}
nav ul {
position: relative;
left: 297px;
}
nav li {
float: left;
padding: 0 20px;
font-size: 12px;
line-height: 65px;
background: url(images/line.png) no-repeat right 10px;
height: 72px;
text-transform: uppercase;
}
nav li a {
color: #656464;
text-decoration: none;
display: block;
}
nav li:hover {
background: url(images/hover.png) repeat-x 0 35px;
color: #242424;
}
could please someone could give me a hint?
nav is an HTML5 element; old IEs will not recognize it and thus won't apply your styles.
To make IE recognize HTML5 markup, place the HTML5 shiv on your page, then declare a rule for nav and any other HTML5 elements you use, giving them a display: block style, just above the CSS that you have now.
<nav> is fine to use on a page, but you will run into problems with it when you try and style it as many browsers simply skip the tag if they don't understand it.
Wrap the <nav> tag in a wrapper div and style that instead, and strip away any styling from the semantic tags so they are naked.

CSS Roll Over with Sprites & Sliding Door

Trying to find an example that has css rollover using sprites & sliding door techniques combined.
I am not css literate, so a complete example or link to a complete example would be appreciated.
All I am trying to do is to have <a href> buttons that are not fixed width with a nice rollover effect and the possibility to add an icon (similar to web outlook).
The following is based on this article (http://www.filamentgroup.com/lab/update_styling_the_button_element_with_css_sliding_doors_now_with_image_spr/), but adapted for use with the a tag.
It is similar to #xijo 's answer, with a couple of minor tweaks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html>
<head>
<title>Test</title>
<style type="text/css">
/* REQUIRED BUTTON STYLES: */
a {
border: 0;
padding: 0;
display:inline-block;
}
a span {
display: block;
white-space: nowrap;
cursor: hand;
}
/* OPTIONAL BUTTON STYLES for applying custom look and feel: */
a.submitBtn {
padding: 0 15px 0 0;
margin-right:5px;
font-size:2em;
text-align: center;
background: transparent url(btn_blue_sprite.gif) no-repeat right -140px;
}
a.submitBtn span {
padding: 13px 0 0 15px;
height:37px;
background: transparent url(btn_blue_sprite.gif) no-repeat left top;
color:#fff;
}
a.submitBtn:hover, button.submitBtnHover { /* the redundant class is used to apply the hover state with a script */
background-position: right -210px;
}
a.submitBtn:hover span, button.submitBtnHover span {
background-position: 0 -70px;
}
</style>
</head>
<body>
This is a bunch <span>Submit</span> of text.
</body>
</html>
We did something like this and you perhaps could find it useful. In the anchor we used a span and assigned the following css to them:
html:
<span>echo</span>
css:
a, a:visited {
background: url(left.png) no-repeat scroll left;
}
.tabContainer a span {
background: url(right.png) no-repeat scroll right;
margin: 0 0 0 21px;
padding: 0 21px 0 0;
float: left;
}
and then hover them like this:
.a:hover {
background-position: -45px;
}
.a:hover span {
background-position: -45px;
}
The left and right must look proportionataly of course! :)
Hopes this helps you to solve your css issues! ;)
With just CSS there is not real rollover or sliding effect. Basically both of those techiques are based on "background-position".
Maybe this will help you:
http://kailoon.com/css-sliding-door-using-only-1-image/
But with javascript you could achive so much better looking rollover effect... :) Check out my test page and click on "click to show little bit advanced hover ;)" to see it ;)
www.arvag.net/test/jquery/
If you want something like that just say and i will try to explain it.
Well, depending on exactly what you want this is very variable, but say you want a button that changes colour when the mouse is over it, and has a little image that appears next to it, this is the sort of thing you'd need:
HTML:
<ul>
<li>home<img src="sprite.png" width="16px" height="16px" alt="tinypic" /></li>
....
</ul>
CSS:
ul li img {
display: none;
}
ul li {
background: #FFFFFF;
}
ul li:focus, ul li:hover, ul li:active {
background: #000000;
}
ul li:focus li img, ul li:hover li img, ul li:active ul li img{
display: inline;
margin-right: -16px; // should stop the button expanding
}
But as I said, that's a very basic stripped down answer

CSS Creating a menu-div-box?

I am trying to create some simple menu links. I tried something like this:
div.menulinkboxaround
{
height: 25px;
}
a.menulinkbox
{
font-family: Verdana, Helvetica;
padding-left: 50px;
padding-left: 50px;
padding-bottom: 5px;
padding-top: 5px;
background-color: Green;
}
a.menulinkbox:hover
{
background-color: Red;
}
a.menulinkbox:visited
{
background-color: Yellow;
}
<div class="menulinkboxaround">Link 1</div>
<div class="menulinkboxaround">Link 2</div>
<div class="menulinkboxaround">Link 3</div>
<div class="menulinkboxaround">Link 4</div>
What i am trying to accomplish is to create menu elements that has a touch of style to em, so each link should be inside a div box with a padding 50 px on each side.
When i run this, they get clumped up on top of each other. I don't want to specify a width since the text inside the menu box should determine the size of it automatically.
Ex. (50px+text size+50px)
50px space (just green area) | Sample Text | 50px space (just green area)
Maybe this will help (since divs are block displayed elements by default):
div.menulinkboxaround { height: 25px; float: left; }
Try adding this:
a.menulinkbox
{
display: block;
}
Depending on whether you want this menu vertical or horizontal you may also want to add float: left; to div.menulinkboxaround.
As the previous answers suggest, you could put float:left on the menulinkboxaround.
It is difficult to tell from your description the desired effect, I am assuming you want the menu to be horizontal with 50px either side of the links.
With the code you currently have, the hover state only stretches in one direction, also as you are only specifying :hover it is not really as keyboard friendly as it would be if you specified :focus as well.
Also because you are setting the height in px as you increase the font size the text becomes clipped at the bottom. Not specifying the pseudo selectors on the link may also cause you later problems in Internet Explorer.
You could also tidy up the code a little to reduce the unnecessary classes and improve the semantics of the menu.
For example:
<style type="text/css">
ul.menu {
/* removing the browser defaults for margin padding and bullets */
margin: 0;
padding: 0;
list-style-type: none;
/* Now you have a sensible parent it is a good idea to put the font
family here, I have also added a fallback of sans-serif in the rare
case Helvetica and Verdana are not available on the users computer,
it might be best to set this on the body if you are using this font
site-wide
*/
font-family: Verdana, Helvetica, sans-serif;
/* To create symetry I am adding 25px to the right and left of the menu,
this will stay green even if the items inside are not
*/
padding: 0 25px;
background-color: green;
/* increacing the lineheight so the background color of the links does
not overflow the green of the menu behind it, for a simple menu like
this it is fine, a more complex or longer links that need to wrap I
suggest changing the method of implementation from display inline to
floating which is a bit more complex
*/
line-height:1.95;
}
/* because all the list items are inside this parent list you can use
the descendant selector to target them rather than adding a separate
class, you are saying all list items inside the unordered list that
has a class of menu
*/
ul.menu li {
/* telling the list items to behave like inline elements so they are
naturally on one line also removint the browser default margin and
padding
*/
display: inline;
margin: 0;
padding: 0;
}
ul.menu a:link,
ul.menu a:visited,
ul.menu a:hover,
ul.menu a:focus,
ul.menu a:active {
/* you can combine all your padding rules together in the order
Top Right Bottom Left, I remember this like it kinda spells TRouBLe :)
*/
padding: 5px 25px 5px 25px;
background-color: green;
/* setting the color to white because the default link color of blue
is not that visible against green
*/
color: white;
}
/* adding the :focus selector to make this more keyboard accessible */
ul.menu a:hover,
ul.menu a:focus {
background-color: red;
color: black;
}
ul.menu a:visited {
background-color: yellow;
color: black;
}
</style>
</pre>
<ul class="menu">
<!-- Putting these all on one line because we are making
them display:inline so the spaces get counted and there will
be a gap otherwise -->
<li>Link 1</li><li>Link 2</li><li>Link 3</li>
</ul>
I have tested this in recent versions of FF, Opera and Safari, and IE6 IE7 and IE8
<style type="text/css">
ul.menu {
margin: 0;
padding: 0;
list-style-type: none;
font-family: Verdana, Helvetica, sans-serif;
padding: 0 25px;
background-color: green;
/* overflow hidden clears the internal floated links and zoom 1
kicks IE into doing the same, I suggest you move the zoom: 1
into an IE stylesheet using conditional comments
*/
overflow: hidden;
zoom: 1;
}
ul.menu li {
display: inline;
margin: 0;
padding: 0;
}
ul.menu a:link,
ul.menu a:visited,
ul.menu a:hover,
ul.menu a:focus,
ul.menu a:active {
padding: 5px 25px 5px 25px;
background-color: green;
color: white;
/* setting the links to float left and giving them display block as
well explicitly, this is so that the vertical padding of 5px gets
applied, inline elements can only have horizontal margin and padding,
and since we are floating them they now take up 0 vertical height in
the document which is why we needed to clear the float on the
surrounding menu
*/
display: block;
float: left;
}
ul.menu a:hover,
ul.menu a:focus {
background-color: red;
color: black;
}
ul.menu a:visited {
background-color: yellow;
color: black;
}
</style>
<ul class="menu">
<li>Link 1</li><li>Link 2</li><li>Link 3</li>
</ul>
This second method is much more reliable, deals with wrapping links nicer and is generally a better solution but a bit harder to explain.
If you didn't want the menu to fill the full width of the screen just as long as the text takes up, regardless of which method you are using above, I suggest you put float: left and clear: both on the ul.menu which should shrink to the width it needs to take up
I hope this helps
sample code below (credit to other answers)
div.menulinkboxaround
{
height: 25px;
float: left;
}
a.menulinkbox
{
font-family: Verdana, Helvetica;
padding-left: 50px;
padding-right: 50px;
padding-bottom: 5px;
padding-top: 5px;
background-color: Green;
}
a.menulinkbox:hover
{
background-color: Red;
}
a.menulinkbox:visited
{
background-color: Yellow;
}
<div class="menulinkboxaround">Link 1</div>
<div class="menulinkboxaround">Link 2</div>
<div class="menulinkboxaround">Link 3</div>
<div class="menulinkboxaround">Link 4</div>

Resources