douying1119 2012-08-05 07:44
浏览 139
已采纳

使用PHP文件扩展名编写动态CSS样式表效率较低吗?

Ive been trying to think of ways to dynamically change a style based off of input from a website back-end (through a language like PHP). Normally I have my stylesheets be separate CSS-extension files, but these won't allow for PHP tags natively. It is, after all, extra markup in your HTML file than having all of your styles be in a separate file. Is the usage of the HTML <style> tag perhaps slower/less efficient than using a stylesheet?

  • 写回答

2条回答 默认 最新

  • douxin20081125 2012-08-05 08:32
    关注

    The W3C Recommendation for CSS 2.1 contains a section on Conformance: Requirements and Recommendations, which makes no reference to filename extension but does state:

    3.4 The text/css content type

    CSS style sheets that exist in separate files are sent over the Internet as a sequence of bytes accompanied by encoding information. The structure of the transmission, termed a message entity, is defined by RFC 2045 and RFC 2616 (see [RFC2045] and [RFC2616]). A message entity with a content type of "text/css" represents an independent CSS document. The "text/css" content type has been registered by RFC 2318 ([RFC2318]).

    Therefore, provided that the file is served with the text/css content type (and that any cacheing concerns are addressed as mentioned in @Fluffeh's answer), you should not have a problem. In PHP, the content type can be set with a call to header() before any output is sent:

    <? header('Content-type: text/css'); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制