【发布时间】:2016-10-10 20:46:30
【问题描述】:
嘿,我正在为我正在开办的一家咖啡馆制作一个非常基本的页面。我有代码可以从我完成的照片池中随机选择页面的背景图像,但是当我尝试引用同一目录中的 css 文件时,样式根本不会反映在页面中。
index.php
<?php
$bg = array('bg1.jpg', 'bg2.jpg', 'bg3.jpg', 'bg4.jpg', 'bg5.jpg', 'bg6.jpg', 'bg7.jpg' ); // array of filenames
$i = rand(0, count($bg)-1); // generate random number size of the array
$selectedBg = "$bg[$i]"; // set variable equal to which random filename was chosen
?>
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<title>Recharge Cafe</title>
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<style type="text/css">
body {
background: url(images/<?php echo $selectedBg; ?>) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
</style>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-79082509-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<p>Recharge Cafe</p>
</body>
</html>
样式表.css
html {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
p {
color: FFFFFF;
}
编辑:如果有人想查看,请访问http://recharge.cafe
【问题讨论】: