tags:

views:

118

answers:

2

upon knowing that parent>div CSS selector is not recognizable in IE, i re-code my CSS styles from this e.g:

div#bodyMain div#paneLeft>div{/*styles here*/}

to this:

div#bodyMain div#paneLeft div[id|="subPane"]{/*styles here*/}

here's my html snippet:

<div id="bodyMain">
     <div id="paneLeft">
      <div id="subPaneCategory">
       <p id="subPaneTitle">Shop Item Categories</p>
       <!--other html here -->
</div></div</div>

The problem is my /styles here/ doesn't work in Mozilla now. are there somethings i need to know in the usage of element[attribute|="value"] ? thanks

A: 

why not just use CSS classes?

<div id="bodyMain">
    <div id="paneLeft">
        <div id="subPaneCategory" class="subpane">
            <p id="subPaneTitle" class="subpane">...</p.
        </div>
    </div>
</div>

And then your CSS is easy and cross-browser:

#paneLeft div.subpane {
    /* whatever */
}

Also note that there's no point in having CSS selectors using 2 ids (unless you need it to increase the specificity). That is: div#bodyMain div#paneLeft could just be rewritten as #paneLeft.

nickf
is it really appropriate/practical to use CSS classes rather than complex selectors?
bgreen1989
@bgreen1989 agree, definitely not. Classes should only be used when they add semantic value to the markup. CSS rules should bend to conform to that markup, not the other way around.
Rex M
Yes it's definitely appropriate to use CSS classes. That's what they're for! Giving the "subPaneCategory" div the class "subpane" definitely adds to the semantics and shows that it is of the same type as anything else with class="subpane".
nickf
+1  A: 

The pipe (|=) is for matching hyphenated values. IE probably ignores the pipe, and in Mozilla your styles no longer work because it respects the pipe, but that does not match your markup (no hyphens).

The ^= operator matches "StartsWith" the value, and $= matches "EndsWith". I'm pretty sure neither of those are recognized by IE either. If you need cross-browser support it's generally safest to stick with:

  • ele
  • #id
  • .class
  • (space) descendant
  • And a few other limited ones like :hover for a

That's pretty much it. Thanks IE :)

Rex M
so, what is the proper css selector for referring to a div with id that starts with subPane?:D?
bgreen1989
@bgreen1989 ^= is for StartsWith, $= is for EndsWith
Rex M
@bgreen1989 and I'm pretty sure neither of those work in IE either, so you'd best rethink your overall strategy :\
Rex M
oh..i really hate IE..:\ . nyway, thanks.
bgreen1989
i really need to change the way i design in css. :'( thanks for the help
bgreen1989