Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there a way to pass inline style rules to all children?

Tags:

html

css

I'm trying to style a post on an internet forum that doesn't allow stylesheets, only inline styles. But it seems that inline styles don't get inherited by children, only the text immediately below (for instance using <h1> will remove the background color from the text). Is there any way to make it pass the styles down without having to add them to every node?

like image 952
Rob F Avatar asked Aug 06 '12 19:08

Rob F


People also ask

Are inline styles inherited?

Yes. If the value of a property is inherit then it will copy the value from the parent element regardless of how it was applied to the parent element.

Why you shouldn't use inline styles?

Inline styles, while they have a purpose, generally are not the best way to maintain your website. They go against every one of the best practices: Inline styles don't separate content from design: Inline styles are exactly the same as embedded font and other clunky design tags that modern developers rail against.

Do inline styles take precedence?

As Inline has the highest priority, any styles that are defined in the internal and external style sheets are overridden by Inline styles. Internal or Embedded stands second in the priority list and overrides the styles in the external style sheet. External style sheets have the least priority.

What are the disadvantages of inline styles?

Disadvantages of Inline CSS:Adding CSS rules to every HTML element is time-consuming and makes your HTML structure messy. Styling multiple elements can affect your page's size and download time.


1 Answers

although @SimeVidas is right, I think his response was a bit quick. Some caution do is required. I updated his fiddle http://jsfiddle.net/fRpQ2/4/ to demonstrate.

If a specific property is declared in the stylesheet for a given tag, that value will NOT be inherited from the parent with the inline style. I guess this is what you are encountering on the forum post you try to style. Nothing to do about this without using style-tags or linked stylesheets. Just a lot of copying required in your case I'm afraid. You could also inspect the site and apply existing classes to your post, but that is only if you want to copy the styling they already apply wich i doubt is the case.

I would advice you to do some reading on the cascading order of styles if you want to learn more.

like image 180
Pevara Avatar answered Oct 31 '22 21:10

Pevara