LTech LTech - 1 year ago 78
HTML Question

when to use div#idname or #idname for css

To style the code:

<div id="top-header">
<div id="logo">
<a href=">logo link</a>


When does one use

and when does one use

Answer Source

div#logo will only apply to elements with the id of logo that are divs, whereas just #logo will apply to any element with the id of logo. However, given that you shouldn't have elements with the same id on the same page, this particular occasion should not make any difference.

It's much more useful when styling by class instead of id, for example:

<div class="top-header">
    <div class="logo">
        <a href=">logo link</a>

    <span class="logo">Hello</span>

Here div.logo{} will not apply the style to the span.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download