简体   繁体   English

是否可以使用javascript /流星附加并保存CSS文件?

[英]is it possible to append and save a css file using javascript/meteor?

I need to dynamically append css elements to a css file using values selected from a db. 我需要使用从数据库中选择的值将css元素动态附加到css文件。

Is there a way to do this using javascript or some other library. 有没有一种方法可以使用javascript或其他库来执行此操作。 I've looked on atmospherejs.com but didn't see anything that looked like it could do it. 我查看了atmospherejs.com,但没有看到任何看起来可以做到的事情。 I'm currently doing this using php/mysql but if I can use meteor and js that would be better. 我目前正在使用php / mysql进行此操作,但是如果可以使用流星和js,那会更好。

Any ideas? 有任何想法吗?

Take a look at this article: http://davidwalsh.name/add-rules-stylesheets 看一下这篇文章: http : //davidwalsh.name/add-rules-stylesheets

the file will need to get built on every page load, however. 但是,该文件将需要在每次页面加载时构建。 The problem with adding styles via script is that they get parsed REALLY late in the page build process, it will be a way better user experience for you to build a custom.php (or something) file and give that to every page - which it sounds like you're doing already. 通过脚本添加样式的问题在于,它们确实在页面构建过程的后期进行了解析,这将是一种更好的用户体验,可让您构建custom.php(或其他内容)文件并将其分配给每个页面-听起来您已经在做。

That will ensure it processes the styles before the scripts, avoiding a momentary style 'flash' where your script finishes executing and adds the new rules. 这样可以确保在脚本执行之前先处理样式,避免脚本完成执行并添加新规则时出现瞬时样式“ flash”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM