/    Sign up×
Community /Pin to ProfileBookmark

class and style both

doubts on CSS

if there is both [I]class[/I] and [I]style[/I] attribute present in a html element , what will happen ?

with both of them work ? only the [I]class[/I] will work but not the [I]style[/I] ?

I just want to know the consequences .

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@BigMoosieOct 14.2009 — CSS stands for "Cascading Style Sheets". The word "cascading" is particularly relevant to your question, it stands for the order of preference with regard to styling.

In your case, if you have class and style attributes and they do not conflict (eg. one of them defines color and the other defines size), then both of them will apply. If there is a conflict then the 'style' attribute has precedence over the specified class.

Basically the order of precedence is:

1. "style"

2. "class"

3. "id"

4. element (defined in a css file)

There are also more complicated rules for element selectors like "div .myclass:first-child" but it sounds like that is beyond the scope of your question.
Copy linkTweet thisAlerts:
@cofactorauthorOct 14.2009 — CSS stands for "Cascading Style Sheets". The word "cascading" is particularly relevant to your question, it stands for the order of preference with regard to styling.

In your case, if you have class and style attributes and they do not conflict (eg. one of them defines color and the other defines size), then both of them will apply. If there is a conflict then the 'style' attribute has precedence over the specified class.

Basically the order of precedence is:

1. "style"

2. "class"

3. "id"

4. element (defined in a css file)

There are also more complicated rules for element selectors like "div .myclass:first-child" but it sounds like that is beyond the scope of your question.[/QUOTE]


glad to know this concept.

I though they will follow the placement order ! like , for example if there is class="abc" style="abc" for the same color say ......I assumed as class is at the beginning so class will be loaded and style be ignored.

But from your comment , it feels to me that they have to follow as per the order you mentioned ALWAYS.

why its like that way ? any specific reasons ? or its just the rules i have to memorize ? ....i am tired of rules ...rules ...rules
Copy linkTweet thisAlerts:
@BigMoosieOct 14.2009 — The order of HTML attributes has no ramifications, ever.

Note: I can see a potential pitfall in interperating my previous post, note that the conflict resolution is re-evaluated for ever single css attribute, i.e. if there is a conflict with 'color' then it is resolved, if there is a conflict with 'border' it is resolved following the rules again, etc.

These rules may sound just like boring old rules, but they are extremely logical, and become more and more efficient and beneficial the larger and more sophisticated your project becomes.
×

Success!

Help @cofactor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...