Is there a way to control external (third-party) CSS using PHP?

I want to manage CSS for a third-party website using PHP. Let's say I want to change the font size of the website, which I will use as input from the user. Can I do it?

+3
source share
5 answers

You could generate the entire .css file generated by PHP each time, but that lost a bit of the processor. Instead, why not just use the cascading nature of css? Make your PHP output a small piece of CSS on each page to override the font installed in the .css file:

<head>
    <link rel="stylesheet" href="styles.css" type="text/css">
    <style type="text/css">
       #some_element {
          font-size: <?php echo $user_selected_font_size ?>px;
       }
    </style>

    etc...

, .css , , .

+2

css. , 2 CSS , , PHP , . CSS , (, div ..).

CSS file.php:

print "
    <style type=\"text/css\">
      body {
        color: purple;
        background-color: {$color} }
      </style>
";

while $color - , .

+2

- JavaScript " ". jQuery .

( ) CSS PHP ( .php, .css) .

+1

, mystyle.php < link rel= "stylesheet" type = "text/css" href= "[yourdomain]/mystyle.php" >
mystyle.php php :

html, body{
    font-size: <?php mysql_... ... ?>
}

, mod_rewrite .htaccess , 3- mystyle.php mystyle.css( , , , .htaccess)

+1

, css - PHP.

I would recommend that the easiest approach would be to override CSS definitions by manipulating the DOM with Javascript or (even easier!) Including a tag <style>embedded in the page that you are already creating with PHP.

0
source

All Articles