如何以编程方式修改CSS文件?

时间:2021-07-19 23:52:13

I have a legacy application that I needed to implement a configuration page for to change text colors, fonts, etc.

我有一个遗留应用程序,我需要实现配置页面来更改文本颜色,字体等。

This applications output is also replicated with a PHP web application, where the fonts, colors, etc. are configured in a style sheet.

此应用程序输出还使用PHP Web应用程序进行复制,其中字体,颜色等在样式表中配置。

I've not worked with CSS previously.

我之前没有使用CSS。

Is there a programatic way to modify the CSS and save it without resorting to string parsing or regex?

是否有一种编程方式来修改CSS并保存它而不需要求助于字符串解析或正则表达式?

The application is VB6, but I could write a .net tool that would do the css manipulation if that was the only way.

该应用程序是VB6,但我可以编写一个.net工具,如果这是唯一的方法,它将执行css操作。

8 个解决方案

#1


3  

You don't need to edit the existing one. You could have a new one that overrides the other -- you include this one after the other in your HTML. That's what the "Cascading" means.

您无需编辑现有的。你可以有一个新的覆盖另一个 - 你在HTML中包含这个。这就是“级联”的含义。

#2


2  

It looks like someone's already done a VB.NET CSS parser which is F/OSS, so you could probably adapt it to your needs if you're comfortable with the license.

看起来有人已经完成了一个F / OSS的VB.NET CSS解析器,所以如果你对许可证感到满意,你可以根据自己的需要调整它。

http://vbcssparser.sourceforge.net/

#3


0  

One hack is to create a PHP script that all output is passed through, which then replaces certain parts of CSS with configurable alternatives. If you use .htaccess you can make all output go through the script.

一个hack是创建一个PHP脚本,所有输出都通过,然后用可配置的替代品替换CSS的某些部分。如果使用.htaccess,则可以使所有输出都通过脚本。

#4


0  

the best way i can think of solving this problem is creating an application that will get some values ( through the URL query ) and generate the appropriate css output based on a css templates

我能想到解决这个问题的最好方法是创建一个应用程序来获取一些值(通过URL查询)并根据css模板生成适当的css输出

#5


0  

Check this out, it uses ASP.NET and C#.

检查一下,它使用ASP.NET和C#。

#6


0  

In my work with the IE control (shadocvw.dll), it has an interesting ability to let you easily manage the CSS of a page and show the effects of modified CSS on a page in realtime. I've never dealt with the details of such implementations myself, but I recommend that as a possible solution worth looking at. Seeing as pretty much everyone is on IE 6 or later nowadays, you can skip the explanations about handling those who only have IE 5,4,3 or 2 installed.

在我使用IE控件(shadocvw.dll)的工作中,它具有一种有趣的功能,可以让您轻松管理页面的CSS并实时显示修改后的CSS对页面的影响。我自己从未处理过这些实现的细节,但我建议将其作为一个值得关注的可能解决方案。现在几乎每个人都在使用IE 6或更高版本,你可以跳过关于处理那些只安装了IE 5,4,3或2的人的解释。

#7


0  

Maybe the problem's solution, which is most simple for the programmer and a user is to edit css via html form, maybe. I suppose, to create css-file, which would be "default" or "standart" for this application, and just to read it, for example, by perl script, edit in html and to write it down. Here is just the simple example.

也许问题的解决方案,对于程序员和用户来说最简单的方法是通过html表单编辑css,也许。我想,创建css文件,对于这个应用程序来说是“默认”或“标准”,只是为了阅读它,例如,通过perl脚本,在html中编辑并将其写下来。这是一个简单的例子。

In css-file we have string like:

在css文件中我们有类似的字符串:

border-color: #008a77;

we have to to read this string, split it up, and send to a file, which will write it down. Get something like this in Perl:

我们必须读取这个字符串,将其拆分,然后发送到一个文件,将其写下来。在Perl中得到这样的东西:

tr/ / /s;
($vari, $value) = split(/:/, _$);
# # While you read file, you can just at the time to put this into html form
echo($vari.":<input type = text name = ".$vari." value = ".$value.">");

And here it is, you've got just simple html-form-data, you just shoul overwrite your css-file with new data like this:

在这里,你只有简单的html-form-data,你只需用这样的新数据覆盖你的css文件:

...
print $vari[i].": ".$value.";\n";
...

and voila - you've got programmatical way of changing css. Ofcourse, you have to make it more universal, and more close to your particular problem.

瞧 - 你有改变css的程序化方法。当然,你必须使它更具普遍性,更接近你的特定问题。

#8


0  

Depending on how technically oriented your CSS editors are going to be, you could do it very simply by loading the whole thing up into a TextEdit field to let them edit it - then write it back to the file.

根据CSS编辑器的技术导向程度,你可以非常简单地将整个内容加载到TextEdit字段中让它们编辑它 - 然后将其写回文件。

Parsing and creating an interface for all the possibilities of CSS would be an astronomical pain. :-)

解析和创建CSS的所有可能性的界面将是一个天文数字的痛苦。 :-)

#1


3  

You don't need to edit the existing one. You could have a new one that overrides the other -- you include this one after the other in your HTML. That's what the "Cascading" means.

您无需编辑现有的。你可以有一个新的覆盖另一个 - 你在HTML中包含这个。这就是“级联”的含义。

#2


2  

It looks like someone's already done a VB.NET CSS parser which is F/OSS, so you could probably adapt it to your needs if you're comfortable with the license.

看起来有人已经完成了一个F / OSS的VB.NET CSS解析器,所以如果你对许可证感到满意,你可以根据自己的需要调整它。

http://vbcssparser.sourceforge.net/

#3


0  

One hack is to create a PHP script that all output is passed through, which then replaces certain parts of CSS with configurable alternatives. If you use .htaccess you can make all output go through the script.

一个hack是创建一个PHP脚本,所有输出都通过,然后用可配置的替代品替换CSS的某些部分。如果使用.htaccess,则可以使所有输出都通过脚本。

#4


0  

the best way i can think of solving this problem is creating an application that will get some values ( through the URL query ) and generate the appropriate css output based on a css templates

我能想到解决这个问题的最好方法是创建一个应用程序来获取一些值(通过URL查询)并根据css模板生成适当的css输出

#5


0  

Check this out, it uses ASP.NET and C#.

检查一下,它使用ASP.NET和C#。

#6


0  

In my work with the IE control (shadocvw.dll), it has an interesting ability to let you easily manage the CSS of a page and show the effects of modified CSS on a page in realtime. I've never dealt with the details of such implementations myself, but I recommend that as a possible solution worth looking at. Seeing as pretty much everyone is on IE 6 or later nowadays, you can skip the explanations about handling those who only have IE 5,4,3 or 2 installed.

在我使用IE控件(shadocvw.dll)的工作中,它具有一种有趣的功能,可以让您轻松管理页面的CSS并实时显示修改后的CSS对页面的影响。我自己从未处理过这些实现的细节,但我建议将其作为一个值得关注的可能解决方案。现在几乎每个人都在使用IE 6或更高版本,你可以跳过关于处理那些只安装了IE 5,4,3或2的人的解释。

#7


0  

Maybe the problem's solution, which is most simple for the programmer and a user is to edit css via html form, maybe. I suppose, to create css-file, which would be "default" or "standart" for this application, and just to read it, for example, by perl script, edit in html and to write it down. Here is just the simple example.

也许问题的解决方案,对于程序员和用户来说最简单的方法是通过html表单编辑css,也许。我想,创建css文件,对于这个应用程序来说是“默认”或“标准”,只是为了阅读它,例如,通过perl脚本,在html中编辑并将其写下来。这是一个简单的例子。

In css-file we have string like:

在css文件中我们有类似的字符串:

border-color: #008a77;

we have to to read this string, split it up, and send to a file, which will write it down. Get something like this in Perl:

我们必须读取这个字符串,将其拆分,然后发送到一个文件,将其写下来。在Perl中得到这样的东西:

tr/ / /s;
($vari, $value) = split(/:/, _$);
# # While you read file, you can just at the time to put this into html form
echo($vari.":<input type = text name = ".$vari." value = ".$value.">");

And here it is, you've got just simple html-form-data, you just shoul overwrite your css-file with new data like this:

在这里,你只有简单的html-form-data,你只需用这样的新数据覆盖你的css文件:

...
print $vari[i].": ".$value.";\n";
...

and voila - you've got programmatical way of changing css. Ofcourse, you have to make it more universal, and more close to your particular problem.

瞧 - 你有改变css的程序化方法。当然,你必须使它更具普遍性,更接近你的特定问题。

#8


0  

Depending on how technically oriented your CSS editors are going to be, you could do it very simply by loading the whole thing up into a TextEdit field to let them edit it - then write it back to the file.

根据CSS编辑器的技术导向程度,你可以非常简单地将整个内容加载到TextEdit字段中让它们编辑它 - 然后将其写回文件。

Parsing and creating an interface for all the possibilities of CSS would be an astronomical pain. :-)

解析和创建CSS的所有可能性的界面将是一个天文数字的痛苦。 :-)