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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)