Page CSS style, but where to put the code?

Besides global.css , I include in my header.php , I would also like to load certain styles specific to the content of the page.

But since my <head></head> already closed by my header file, and I don’t want to resort to the built-in lines, what is the best way to place styles on a specific page?

Thanks !: D

+4
source share
2 answers

I would try one of the following:

  • Break header.php in 2 different files so that any pages, including it, add their own link tags
  • At the top of the file, before including header.php, specify an array, for example $ included_css, containing styles (style1.css, style2.css). Then in header.php you can make a simple foreach and include them after global.css (so that they take precedence)
+5
source

in our CMS we have a header folder inside the template directory. If you name the file form.tpl, it should insert it itself only when form.tpl is called (we process this using the smarty template mechanism). I think this is a good practice.

Another solution would be to use classes or identifiers on your body. <body id="suscribeForm"> and use them as a link in your css. (the problem is that CSS is loaded even if you don’t use it, but on the other hand it is already cashed if the user goes to another page).

You can also link different CSS files to the main CSS, but this is not a good practice, because your browser will wait for mains.css to load, and then download the related files.

+3
source

Source: https://habr.com/ru/post/1308438/


All Articles