Conditional Comments within CSS

后端 未结 3 1081
天涯浪人
天涯浪人 2021-02-10 03:15

I am currently developing a theme for a homepage but ran into a few problems. For whatever reason I have no access to editing the html code itself, and I need to write custom .c

3条回答
  •  一生所求
    2021-02-10 04:00

    For your dual backgrounds problem, you simply need to add another containing element.

    ...

    becomes

    ...

    I'm not sure why you wouldn't be able to manually edit the HTML, but if you have access to a javascript file and you're using jQuery, you can add the class like so:

    $('.element').wrap('
    ');

    You can use CSS hacks to avoid using conditional comments. CSS hacks aren't as commonly used now since the average user uses a browser that doesn't require any hacks to display properly, but it is still a completely valid and reliable way to avoid using HTML conditional statements. Depending on the specificity you want, you have a bunch of different hacks that you can use to only target specific versions of IE:

    * html .element { color: #fff; /* IE6 only */ }
    html .element { _color: #333; /* IE7 only */
    *+html .element { color: #999; /* IE7 only */ }
    html .element { *color: #000; /* IE7 and below */
    html .element { color: #ccc\9; /* IE8 and below */ }
    

    So:

    #container { background: url(img/bg1.png) repeat-y\9; }
    #container #mainframe { 
        background: url('img/bg2.png') no-repeat, url('img/bg1.png') repeat-y !important;
        background: url('img/bg2.png') no-repeat\9; }
    

提交回复
热议问题