douwen8424 2012-08-13 13:33
浏览 50
已采纳

CSS预处理器:来自数据库的Sass,Less,Php和Vals [关闭]

I'm finally delving in to CSS Preprocessing, and trying to figure out the best route to go. My primary questions are:

  1. What is the value of using SASS or LESS over Php?
  2. If I were to use SASS or LESS, what's the best way to integrate values from the database?

Obviously using php to print styles in the header is a pretty bad idea. I was using php to create a stylesheet, and importing it as 'Content-Type: text/css'. It would then create the stylesheet that would be served as such and cached properly. I could use values from the database and work with the language I'm already adept with.

What advantages do SASS and LESS have over Php for creating/working with the stylesheets, and if I were using them, what is the best way to use values from the database? Would I need to use Php to grab the values from the database, basically continuing my methods above, only for that use, then using SASS, LESS, or another to work with the rest of the stylesheet?

Thank you very, very much for your help!

  • 写回答

2条回答 默认 最新

  • duandou9931 2012-08-13 13:46
    关注

    CSS preprocessors like SASS and LESS give you much more than just serving a PHP (or any other server side language) file with dynamic code, served with a content-type:text/css

    They give you:

    • Mixins – Classes for classes.
    • Parametric mixins – Classes to which you can pass parameters, like functions.
    • Nested Rules – Classes within classes, which cut down on repetitive code.
    • Operations – Math within CSS.
    • Color functions – Edit your colors.
    • Namespaces – Groups of styles that can be called by references.
    • Scope – Make local changes to styles.
    • JavaScript evaluation – JavaScript expressions evaluated in CSS.

    To do all that in PHP by yourself would be a fair effort!

    Regarding getting data from a database and using it in your SASS / LESS, it's not something that preprocessors would allow you to do out of the box. You could write your own PHP code that would read from a database, collect the information and values you need, and then write a SASS or LESS file to the filesystem using these values. You could just write a normal CSS file too if you don't need the features above that preprocessors give you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容