doumingchen3628 2015-02-04 16:52
浏览 36
已采纳

用PHP混合cookie和CSS

So I have really simple css file that is generated based on cookie that is fetched using php. Whole css is also displayed using php so it

<?php header("Content-type: text/css");
$rand = $_COOKIE['randTopic'];

echo '
body {
    margin-top: 50px;
    margin-bottom: 50px;
    background: none;
}

.full {
  background: url("http://loremflickr.com/1920/1080/' . $rand . '") no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  }
';
?>

Loremflickr is just a service that gives me random image from flickr, I can also choose topic what I am doing actually. So the output css looks exactly like this:

body {
    margin-top: 50px;
    margin-bottom: 50px;
    background: none;
}

.full {
  background: url("http://loremflickr.com/1920/1080/wall
") no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  }

As you can see there's a linebreak that I didn't really want, no idea why it's here. I think it could cause the problem, what do you think?

Thank you kindly in advance for any help.

  • 写回答

2条回答 默认 最新

  • douqian2957 2015-02-04 16:56
    关注

    Quick fix for that is to use trim() function on data from cookie.

    But first of all I would check why is there line break. Inspect your code.

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

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了