IE8 css selector

后端 未结 14 1856
臣服心动
臣服心动 2020-11-30 22:44

To target elements only in IE browsers i\'ll use

IE6:

* html #nav li ul {
    left: -39px !important;
    border: 1px solid red;
}

相关标签:
14条回答
  • 2020-11-30 22:52

    OK so, it isn't css hack, but out of frustration for not being able to find ways to target ie8 from css, and due to policy of not having ie specific css files, I had to do following, which I assume someone else might find useful:

    if (jQuery.browser.version==8.0) {
       $(results).css({
             'left':'23px',
             'top':'-253px'
          });
    }
    
    0 讨论(0)
  • 2020-11-30 22:55

    I have a solution that I use only when I have to, after I build my html & css valid and working in most browsers, I do the occasional hack with this amazing piece of javascript from Rafael Lima. http://rafael.adm.br/css_browser_selector/

    It keeps my CSS & HTML valid and clean, I know it's not the ideal solution, using javascript to fix hacks, but as long as your code is originally as close as possible (silly IE just breaks things sometimes) then moving something a few px with javascript isn't as big of a deal as some people think. Plus for time/cost reasons is a quick & easy fix.

    0 讨论(0)
  • 2020-11-30 22:56

    I'm not going to get in a debate about whether or not this method should be used, but this will let you set specific css attributes for IE8-9 only (note: it is not a selector, so a bit different than what you asked):

    Use '\0/' after each css declaration, so:

    #nav li ul  {
      left: -39px\0/ !important;
    }
    

    And to build off another answer, you can do this to assign variou styles to IE6, IE7, and IE8:

    #nav li ul  {
       *left: -7px    !important; /* IE 7 (IE6 also uses this, so put it first) */
       _left: -6px    !important; /* IE 6 */
        left: -8px\0/ !important; /* IE 8-9 */
    }
    

    source: http://dimox.net/personal-css-hacks-for-ie6-ie7-ie8/

    0 讨论(0)
  • 2020-11-30 22:57

    CSS style only for IE8:

    .divLogRight{color:Blue; color:Red\9; *color:Blue;}
    

    Only IE8 will be Red.

    first Blue: for all browsers.

    Red: IE6,7,8 Only

    Second Blue: IE6,7 Only


    So Red = for IE8 only.

    For a very complete summary of browser hacks (including Internet Explorer (IE), Safari, Chrome, iPhone, and Opera) visit this link: http://paulirish.com/2009/browser-specific-css-hacks/

    0 讨论(0)
  • 2020-11-30 23:03

    In the ASP.NET world, I've tended to use the built-in BrowserCaps feature to write out a set of classes onto the body tag that enable you to target any combination of browser and platform.

    So in pre-render, I would run something like this code (assuming you give your tag an ID and make it runat the server):

    HtmlGenericControl _body = (HtmlGenericControl)this.FindControl("pageBody");
    _body.Attributes.Add("class", Request.Browser.Platform + " " + Request.Browser.Browser + Request.Browser.MajorVersion);
    

    This code enables you to then target a specific browser in your CSS like this:

    .IE8 #nav ul li { .... }
    .IE7 #nav ul li { .... }
    .MacPPC.Firefox #nav ul li { .... }
    

    We create a sub-class of System.Web.UI.MasterPage and make sure all of our master pages inherit from our specialised MasterPage so that every page gets these classes added on for free.

    If you're not in an ASP.NET environment, you could use jQuery which has a browser plugin that dynamically adds similar class names on page-load.

    This method has the benefit of removing conditional comments from your markup, and also of keeping both your main styles and your browser-specific styles in roughly the same place in your CSS files. It also means your CSS is more future-proof (since it doesn't rely on bugs that may be fixed) and helps your CSS code make much more sense since you only have to see

    .IE8 #container { .... }
    

    Instead of

    * html #container { .... }
    

    or worse!

    0 讨论(0)
  • 2020-11-30 23:05

    In the light of the evolving thread, see below for a more complete answer:

    IE 6

    * html .ie6 {property:value;}
    

    or

    .ie6 { _property:value;}
    

    IE 7

    *+html .ie7 {property:value;}
    

    or

    *:first-child+html .ie7 {property:value;}
    

    IE 6 and 7

    @media screen\9 {
        .ie67 {property:value;}
    }
    

    or

    .ie67 { *property:value;}
    

    or

    .ie67 { #property:value;}
    

    IE 6, 7 and 8

    @media \0screen\,screen\9 {
        .ie678 {property:value;}
    }
    

    IE 8

    html>/**/body .ie8 {property:value;}
    

    or

    @media \0screen {
        .ie8 {property:value;}
    }
    

    IE 8 Standards Mode Only

    .ie8 { property /*\**/: value\9 }
    

    IE 8,9 and 10

    @media screen\0 {
        .ie8910 {property:value;}
    }
    

    IE 9 only

    @media screen and (min-width:0) and (min-resolution: .001dpcm) { 
     // IE9 CSS
     .ie9{property:value;}
    }
    

    IE 9 and above

    @media screen and (min-width:0) and (min-resolution: +72dpi) {
      // IE9+ CSS
      .ie9up{property:value;}
    }
    

    IE 9 and 10

    @media screen and (min-width:0) {
        .ie910{property:value;}
    }
    

    IE 10 only

    _:-ms-lang(x), .ie10 { property:value\9; }
    

    IE 10 and above

    _:-ms-lang(x), .ie10up { property:value; }
    

    or

    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
       .ie10up{property:value;}
    }
    

    IE 11 (and above..)

    _:-ms-fullscreen, :root .ie11up { property:value; }
    

    Javascript alternatives

    Modernizr

    Modernizr runs quickly on page load to detect features; it then creates a JavaScript object with the results, and adds classes to the html element

    User agent selection

    The Javascript:

    var b = document.documentElement;
            b.setAttribute('data-useragent',  navigator.userAgent);
            b.setAttribute('data-platform', navigator.platform );
            b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');
    

    Adds (e.g) the below to the html element:

    data-useragent='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)'
    data-platform='Win32'
    

    Allowing very targetted CSS selectors, e.g.:

    html[data-useragent*='Chrome/13.0'] .nav{
        background:url(img/radial_grad.png) center bottom no-repeat;
    }
    

    Footnote

    If possible, avoid browser targeting. Identify and fix any issue(s) you identify. Support progressive enhancement and graceful degradation. With that in mind, this is an 'ideal world' scenario not always obtainable in a production environment, as such- the above should help provide some good options.


    Attribution / Essential Reading

    • Keith Clarke
    • Paul Irish
    • Web Devout
    • The Spanner
    0 讨论(0)
提交回复
热议问题