CSS Precedence: Why Inline Styles Are Overridden
In CSS, styles are applied to elements based on the precedence of their rules. When multiple rules target the same element, the one with the highest precedence will take effect.
In the provided example, you have an inline style that sets padding-left: 10px for td elements within a table with the rightcolumn ID. However, a style from a referenced stylesheet sets margin and padding to 0 for all elements within the .rightColumn class. The issue is that the styles from the referenced stylesheet have higher precedence, causing the inline styles to be overridden.
Calculating Specificity
CSS precedence is determined by the specificity of rules. Specificity is calculated based on the following criteria:
For example, a rule with the selector .rightColumn * has a specificity of 0010 (a = 0, b = 0, c = 1, d = 0), while a rule with the selector td has a specificity of 0001 (a = 0, b = 0, c = 0, d = 1). Since 0010 is greater than 0001, the rule from the referenced stylesheet has higher precedence.
Resolving the Issue
To resolve this issue and apply the inline styles, you have two options:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3