Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When functionalities of html attributes and css styles overlap

Tags:

html

css

1) If inside CSS file we specify the following style:

td
{ text-align:center; }

While in a Html file we have

<td align=”right” … >

then value set in CSS file will take precedence over an inline html attribute and thus elements contained inside <td> cell will be aligned to the center.

a) Is same true for all html attributes? Meaning if a CSS rule and an html attribute functionalities overlap , will the CSS rule always take precedence?

BTW – I know we should usually prefer using CSS rules vs html attributes

thanx

like image 997
AspOnMyNet Avatar asked Dec 21 '25 08:12

AspOnMyNet


1 Answers

Which set of definitions, HTML attributes or CSS properties, take precedence?

The textbook answer:

CSS properties take precedence over HTML attributes. If both are specified, HTML attributes will be displayed in browsers without CSS support but won't have any effect in browsers with CSS support.

(Reference: http://www.hwg.org/resources/faqs/cssFAQ.html)

The real-world answer:

It depends, if you want to be certain for a specific attribute or set of attributes, you will have to create a unit test and apply those tests to the specific browser(s) that you want to verify for compliance with the "textbook" answer, or compliance to your specification for the specific project you are working on.

You already imply that you know certain HTML attributes are deprecated, so I will not belabor that point here.

like image 144
dreftymac Avatar answered Dec 22 '25 23:12

dreftymac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!