Home > Enterprise >  Interpret <P> as <P.SERIF> in all paragraphs of a .Html file
Interpret <P> as <P.SERIF> in all paragraphs of a .Html file

Time:12-18

I have a CSS file that defines a class of paragraph, it's named p.serif.
I have an HTML file that depends on that CSS. For a single paragraph I can set <p >, and it works perfectly. But I want ALL my 400 paragraphs in the html to look as defined in p.serif without changing <p> to <p > 400 times. Of course, I can paste P.Class's characteristics into the head of the html as <style>, but I have many htmls like that, and I simply want to tell every html: 'P here is as defined in p.serif, apply the Serif class to every <p> you see in this html'. How could that be done, please?

CodePudding user response:

HTML has no mechanisms for applying adding a class to an element without actually changing the class attribute on each element you want to change.

You could write some JS to loop over all the paragraphs and modify their class lists, but your approach of adding the style element would be more efficient (and wouldn't break if additional paragraphs were dynamically added to the document).

CodePudding user response:

Simply create a CSS rule for the p tag itself that has the same settings as your .serif class. For example:

p {
  font-family: /* whatever css settings .serif class contains */;
} 
  • Related