Declaring a property once instead of 4 seperate times

If one property is used in all the other <div styles=", can I place it with the top div style and it’ll give it to the ones below? So, instead of declaring [cursor: pointer;] to all 4 div styles, you declare it once by putting it in the 1st div style, and that’ll give it to the ones below.

Is this allowed?

<div style="width:266px;cursor: pointer;" onmouseover="myObject=document.getElementById('myObj5h'); 
myObject.style.display='block'; this.style.display='none'">

    <div style="">
    </div>

    <div style="">
    </div>

    <div style="">
    </div>

    <div style="">
    </div></div>

No - you declare everything once in the external stylesheet - having to declare everything over and over is one of the thousands of reasons for not jumbling the CSS in the HTML.

5 Likes

Not allowed, and not possible. And there are lots of things you can’t do at all with inline styles, like setting :hover colors etc.

6 Likes

You should rarely need to declare that. The definition for cursor:pointer is:

The cursor is a pointer that indicates a link.

(see http://tympanus.net/codrops/css_reference/cursor/)

Browsers will automatically render the correct cursor type for a link, so there is no need to specify it. I’m pretty certain I have never needed to use that in all the years I’ve been building sites.

1 Like

The only use I have had for that is on “links” that are not using the <a> tag where it is going to run some JavaScript for those visitors with JavaScript enabled but where it is just text (or not there at all) for those without JavaScript. Part of the class that the JavaScript adds to the tag to make it into a “link”.

2 Likes

This is how you do that:-
HTML

<div class="pointers">
    <div></div>
    <div></div>
    <div></div>
    <div></div>
</div>

CSS

.pointers div {
    cursor: pointer;
    /* + any other common css properties that would otherwise be repeated */
}

You can’t do this with in-line styles.

Among other things.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.