Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

how to generate a dynamic css file using php or codeigniter

I want to develop a project with dynamic css file ,i mean i want to apply styles dynamically with out using static css file. I want to apply styles like colors, borders, width, heights etc..from one form fields and those are stored in database and i want to get values from database and apply changes dynamically in css file(styles), project css applied as dynamically.How can i write code in this scenario

.css file

#border
{
  border: 30px;
}
#color
{
  color: red;
}

like this... php form view

     <h1 id='color'>hello world</h1>
     <input type='text' id='border' value='hello'/>

i want my .css file like this

  #border
{
  border: <?= $settings[0]->border ?>;
}
#color
{
  color: <?= $settings[0]->color ?>;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do it using create a .php file.

Add logic to it, make it a CSS file (with .php extension).

Add header parameters in (start of file) PHP file to tell Server that this is a CSS file.

<?php
header('Content-Type: text/css');
?>

Now, include the the file as a CSS file.

e.g.

<link rel="stylesheet" href="CUSTOM_STYLES.PHP"/>

This inclusion of PHP file with CSS body in it will work as a dynamic CSS file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...