dou11655853 2017-07-19 19:21
浏览 262
已采纳

PHP插入时CSS不起作用

I have been trying to use PHP to insert my CSS's file contents in the style tag of a page.

<style>
    <?php 
        $css = file_get_contents('css/roboto-robotocondensed.css');
        $css .= file_get_contents('css/reset.css');
        $css .= file_get_contents('css/mainstyle.css');
        $css .= file_get_contents('css/industriaalimentosebebidas.css');
        echo $css;
    ?>
</style>

And in the last file, "industriaalimentosebebidas.css", i have the following code:

header {
    height: 500px; 
    background: url(../img/cases/casos-de-sucesso-alimentos-e-bebidas-cover.jpg) no-repeat center bottom / cover;
}

header p { 
    width: 75%;
    font-size: 1.536rem;
}
.imgGradient {
    height: 100%;
} 

@media only screen and (min-width: 1600px) {
    header {
        height: 700px;
    }
}

For some reason, the header style code above the media query is being ignored by the browser. But, when I get the CSS file using

<link rel="stylesheet" type="text/css" href="css/industriaalimentosebebidas.css"/>

everything works fine.

In the inspector, the header height does not seem to be overwritten... and background image is not being loaded.

Even if I remove the media query part, the header part does not work.

In the html head I'm using

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>

Does anyone have a clue of what might be going on?

  • 写回答

1条回答 默认 最新

  • dph6308 2017-07-19 19:32
    关注

    in your css look for the line:

    #infos .imgContainer{max-height:25vw}1rem}
    

    this is the reason it is broken.

    original:

    basically add spaces between the files: (not semicolons, remembered that wrong)

    <style>
    <?php 
        echo implode("
    ", [
            file_get_contents('css/roboto-robotocondensed.css'),
            file_get_contents('css/reset.css'),
            file_get_contents('css/mainstyle.css'),
            file_get_contents('css/industriaalimentosebebidas.css')
        ]);
    ?>
    </style>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?