douyangqian5243 2014-03-31 08:14
浏览 59
已采纳

在CSS中使用PHP与通过JS进行适配[一般]

I have a general question about the use of PHP in CSS. I am working right now on a Wordpress Theme and would like to make it as customizable as possible. I therefore sent the CSS Properties I would like to change via PHP to a JS file that changed them for me. But I am unsure if this is the best way to do it.

Would you guys recommend it and what are the pros and cons?

  • 写回答

2条回答 默认 最新

  • dqeq885710 2014-03-31 08:22
    关注

    Let me tell you how I implemented customisable themes on my website, and see if it's of any help to you.

    To start with, I use LESS. Wherever I have something customisable (usually colours, but sometimes background images too) I drop in a variable.

    Then I have a _colours.less file, which simply defines all the variables, and gets imported at the start of every other .less file.

    Finally, I present the users with an interface to edit these variables in a user-friendly manner.

    At run-time, the PHP checks:

    • Does the main core.css file exist?
    • Is the core.css's modification time more recent than the _colours.less modification time?
    • Are the modification times of all .css file being used in this page more recent than the corresponding .less file's?

    If any of the above result in the answer "no", then the given .css file is recompiled on-the-fly using the PHP lessc class (that basically implements the LESS compiler).

    In this way, users can easily create their own custom themes, but it doesn't interfere in any way with my ability to update the site's layout.

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

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?