resource / Front-End-Standards

Front-end development standards for Resource.
MIT License
23 stars 1 forks source link

Use preferred-child instead of descendant selectors. #71

Closed nicetransition closed 10 years ago

nicetransition commented 11 years ago

I would recommend removing "Use preferred-child instead of descendant selectors.", there are many cases to use this.

Quick example is a basic horizontal list element where I don't want a sub list to be horizontal:

<ul class="selector-name">
    <li>
        <a href="#">Link</a>
        <ul>
            <li>
                <a href="#">Link</a>
           </li>
            <li>
                <a href="#">Link</a>
           </li>
        </ul>
   </li>
    <li>
        <a href="#">Link</a>
   </li>
</ul>
.selector {
   background-color: red;
}
.selector > li {
   display: inline-block;
}

This is fundamental (syntax) of CSS not a standard.

A better suggestion would be something like "Use absolute path selectors only when needed"

LukeAskew commented 10 years ago

Isn't that what the standard suggests. According to the example:

/* bad */
.selector p {
    ...
}

/* good */
.selector > p {
    ...
}

The styling is only applied to the first level p, not all child p elements.

apartyka commented 10 years ago

I like @kevinmack18 's suggestion, "Use absolute path selectors only when needed". I can't think of a reason why you would completely avoid descendant selectors.

If you want all anchor elements to display a different way within a specific parent, a descendant selector would be fine.