ul li:nth-child(odd){
color:#c0122f;
float:left;
width:48%;
line-height:30px;
font-size:15px;
}
ul li:nth-child(even){
color:#c0122f;
width:48%;
float:right;
line-height:30px;
font-size:15px;
}
there is six li item on my page and i want give 3 shold be left side and 3 should be right side for that i have used nth-child(odd)/ even which i show in my code its working fine in chrome, mozilla and ie9 but it create a problem in ie8 /7
http://caniuse.com/#search=nth-child
They don't support nth-child. You'll need to implement a javascript solution for those browsers, unfortunately.
Sorry nth-child aren't supported in those versions of IE. It included support for these properties later! Not in those versions.
However, here is an alternate way!
Use this script: http://selectivizr.com/ it would enable some CSS properties.
Note: You should always try to search for browser compatibility and some script which would help you use CSS in older versions of IE!
As the other answers mentioned, nth child is not supported in older versions of IE. You could add fallback classes to IE versions if you add IE conditionals to your html tag. Then just do some basic jQuery to add classes.
html
<!--[if lt IE 7]> <html lang="en-us" class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html lang="en-us" class="no-js lt-ie9 lt-ie8 ie7"> <![endif]-->
<!--[if IE 8]> <html lang="en-us" class="no-js lt-ie9 ie8"> <![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-us" class="no-js"> <!--<![endif]-->
jquery
$('.lt-ie9 li:nth-child(odd)').addClass('odd');
$('.lt-ie9 li:nth-child(even)').addClass('even');
css
li.odd,
li:nth-child(odd) {
color: #c0122f;
}
Related
I'm on the hunt for a bulletproof workflow for select menus. I have conditional comments for ie 10+
<!--[if lt IE 7]> <html class="ie ie6 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 7]> <html class="ie ie7 lte9 lte8 lte7"> <![endif]-->
<!--[if IE 8]> <html class="ie ie8 lte9 lte8"> <![endif]-->
<!--[if IE 9]> <html class="ie ie9 lte9"> <![endif]-->
<!--[if gt IE 9]> <html class="gt9"> <![endif]-->
<!--[if !IE]><!--> <html> <!--<![endif]-->
And Chrome does just fine when it comes to hiding/showing select arrows with:
-webkit-appearance: none;
However when it comes to Firefox:
-moz-appearance:none;
Works for versions 35+. This means that FF<35 will display both my custom background-image arrow and its default on select menus. So hiding the dropdown arrow for these legacy browsers is the final hurdle to a cross browser solution.
How do I target background-image for Firefox browsers older than version 35?
I know modernizer or other libraries may be able to do so but that's overkill to add a class name to < html> or a vendor specific pseudo element I don't know about. Thanks in advance.
You could use JavaScript to detect the version.
var frags = navigator.userAgent.split('/');
if ((frags[frags.length - 2].indexOf('Firefox') > -1) && (parseFloat(frags[frags.length - 1]) < 35)) {
alert('You are on Firefox version < 35')
}
I have style sheet file and would like to disable some css tags in it for IE7 and IE8 browsers, how to do that? I do not want to put these tabs in separated css file I would like to keep then in one file.
I'd recommend the approach taken by the HTML5 boilerplate, outlined here by Paul Irish. Basically, set up your document like this:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
You now have classes in place to accurately target only certain versions of IE. Your css will look like this:
.element { margin-bottom: 20px; }
.lt-ie8 .element { margin-bottom: 10px; }
You then avoid CSS hacks, and can keep everything in a single stylesheet.
As #Daniel states, this is not disabling styles, but over-riding them. If for some reason you want to send styles to only modern browsers and newer IE, you could add another class to the final html tag above, and use that.
If you try to have specific style-sheets only for IE it goes like this:
<!--[if IE 8]><link rel="stylesheet" href="css/ie8.css" type="text/css" media="screen"><![endif]-->
<!--[if IE 7]><link rel="stylesheet" href="css/ie7.css" type="text/css" media="screen"><![endif]-->
<!--[if IE]><link rel="stylesheet" href="css/ie.css" type="text/css" media="screen"><![endif]-->
More about this here: How To Create an IE-Only Stylesheet
.element {
margin-bottom: 20px;
margin-bottom: 10px\9;
}
Info from here: http://www.impressivewebs.com/ie7-ie8-css-hacks/
You cannot disable them, but you can override them
I've a test.css file with the following styles:
....
#body
{
font-family:Verdana, sans-serif;
font-size:10pt;
margin:0;
padding:0;
}
div#inscreenalertcontainer
{
margin:32px;
padding:16px;
width:100%;
}
....
For IE the attribute width:100%; is necessary in div#inscreenalertcontainer.
For other browsers this attribute is not required.
Is there any way to do this in test.css with some conditional operators?
Since there are around 100 css files, I dont want to create another 100 css files, specific to IE, just to change one property.
Or is it possible to change in JSP itself.
Here is my JSP code:
<body>
<div id="InScreenAlertContainer">
<table class="inScreenAlert">
<tr valign="top">
....
....
</body>
Use Conditional Comments:
<!--[if IE]>
<style>
div#inscreenalertcontainer
{
margin:32px;
padding:16px;
width:100%;
/*plus other IE specific rules*/
}
</style>
<![endif]-->
This is programmed into all versions of Internet Explorer to serve specific instructions for these browsers. No other browser will pick up on it, it's the best way to tell IE to do something else than what's in the original CSS.
If the parameter doesn't hurt the other browsers you can leave it there.
Or use this to apply it to IE only:
http://css-tricks.com/how-to-create-an-ie-only-stylesheet/
You can choose for the stylesheet hack or conditional comment (html) to target IE and add a
<style>div#inscreenalertcontainer {width:100%}</style>
in your head tags
add this one to your webpage's header section.
and here is a very good link to see more http://www.quirksmode.org/css/condcom.html
<!--[if IE]>
div#inscreenalertcontainer
{
margin:32px;
padding:16px;
width:100%;
}
<![endif]-->
A common way to target IE is to change your html markup to this :
<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html class=""> <!--<![endif]-->
And then in your css you can just write :
.ie #inscreenalertcontainer {
width: 100%;
}
This technique will allow you to keep your code readable and tidy.
Without:
adding any markup element there;
without using display: inline-block;
without knowing the div width;
no hacks. the code should validate.
How can we center those three divs horizontally, but making them INLINE ?
http://jsfiddle.net/mMPMh/
Please note:
The reason that I'm avoiding inline-block, lies on the fact that IE7 should behave.
Other rules that don't work on IE 7 should also be disregarded.
Is it possible ?
Like this - http://jsfiddle.net/mMPMh/10/
Or this - http://jsfiddle.net/mMPMh/14/ ?
This one works with IE7
As for hacks, it can be served using conditional statement like
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="ie7-and-down.css" />
<![endif]-->
Or using this on your HTML (from HTML5BP)
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
And serve the style like this :
.lt-ie8 #one,
.lt-ie8 #two,
.lt-ie8 #three {
display:inline;
zoom:1;
}
No hacks
UPD:
After you update your questionyou can use for IE display:inline;, maybe it will resolve your issue?
Like this - http://jsfiddle.net/mMPMh/4/ ?
remove float, set clear, and give if you need height and width.
I have two tables that need to line up side by side. In order to achieve this I have to specify a td height.
In IE the height should be 2.1em. In Mozilla it needs to be 1.76em.
There does not appear to be a
-moz-height:1.76em;
Any idea how I can achieve my goal?
You can put the IE height into a separate stylesheet and load it after the default one, using IE-conditional comments so the other browsers ignore it. Otherwise, you can use jQuery to change the height after it's loaded (if ($.browser.msie))
Yes it is. For Fire Fox do this:
#-moz-document url-prefix() {
//Your css here
#my-id { font-size: 100%; }
}
For IE you can do something like this:
[if IE 8]><link rel="stylesheet" href="DefaultSTyleForIE8.css" type="text/css" media="screen, projection"/><![endif]
This css will only work for IE 8
in mozilla it is possible to change the height for mozilla by height: -moz-calc(470px);
and auto height by height: -moz-available;
I would recommend the html5 boilerplate method,
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
then you can target ie in your css like,
.oldie #myel{
height: 2.1
}
I would shamelessly use IE conditional comments:
<style>
td {
height: 1.76em;
}
</style>
<!-- [if IE]>
<style>
td {
height: 2.1em;
}
<style>
<!endif-->
Here's a list of CSS filters by browser:
http://en.wikipedia.org/wiki/CSS_filter
Browser detect IE using IE's conditional comments and write out separate BODY tags:
<!--[if IE]><body class="ie"><!--<![endif]-->
<!--[if !IE]><!--><body><!--<![endif]-->
Then whenever you have a style, you can be more specific by adding the ie class to over-ride only IE:
.mystyle {styles for good browsers}
.ie .mystyle {styles for IE}