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条)

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)