css variables with values coming from the database

Asked

Viewed 333 times

1

I’m developing a website where I saw myself in need to bring the style(colors) of the database elements. This would be a piece of cake if it were a page because (by relaxo) could write the css in the head document and bring the variables with the values of the database. But the website is large and need to use a file css separate and link the pages that will use these styles, because for performance reasons I do not like to think about writing the same style sheet on head of each page.

I did some research on the subject and saw names of pre-processors like: PostCSS, SASS, LESS, etc..

As I’ve never seen anything on the subject so I wanted to know if there is any way to make the variables from the bank work (the language I use is the classic Asp), or if it is only possible with these such preprocessors, and if, only work with them wanted them to tell me which one would be good to use and if they allow to bring the values of the database.

If you do not understand my question or think that it is not complete just ask that I am in the waiting to ask the questions. Thanks in advance.

1 answer

2


Just import css as php

<link rel="stylesheet" href="estilo.php" type="text/css" />

In php add

<?php
header("Content-type: text/css");

//configura as variáveis

?>

//Saida Css

body {
background: <?php echo $cor_fundo; ?>;
}
  • Good Felipe liked your idea, you know tell me if the content-type works on Asp?

  • No need more found here on the net, I did not know that the @import picked up files like this. I will test here and if it works I put your answer as sure ok.

  • until I got confused kk, you’re using Asp, but it’s basically the same thing

  • Dude you saved me brother kkk was thinking it was going to be a 7-head bikini and you come show me one of these, what I needed was for Sp but as the concept is the same for any language I’ll leave your answer anyway. For those who want in Asp the content-type is like this Response.ContentType = "text/css", the rest is equal.

  • hehe, then yes, sometimes we find problems where there is no

Browser other questions tagged

You are not signed in. Login or sign up in order to post.