LTech LTech - 1 month ago 4
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


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.