【发布时间】:2015-07-28 09:58:54
【问题描述】:
我尝试包含来自全局变量的 css,但不包含样式。
全局变量:
<?php
require_once '../app/init.php';
define('ROOT_DIR', dirname(__FILE__));
define('CSS_DIR', ROOT_DIR . '\css');
define('CSS_BOOTSTRAP', CSS_DIR . '\bootstrap.min.css');
define('CSS_STYLES', CSS_DIR . '\styles.css');
$app = new App;
HTML:
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Bootstrap Login Form</title>
<meta name="generator" content="Bootply" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href='<?php echo CSS_BOOTSTRAP; ?>' rel="stylesheet">
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href='<?php echo CSS_STYLES; ?>' rel="stylesheet">
</head>
<body>
来自浏览器的代码:
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Bootstrap Login Form</title>
<meta name="generator" content="Bootply" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" type="text/css" href="C:\xampp\htdocs\grade_your_room\public\css\bootstrap.min.css" >
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="C:\xampp\htdocs\grade_your_room\public\css\styles.css" >
</head>
<body>
如果我尝试访问路径 C:\xampp\htdocs\grade_your_room\public\css\styles.css,则可以显示样式。
【问题讨论】:
-
link的href属性必须具有相对/绝对链接作为值,而不是本地路径。因此,它应该是:<link href="/css/styles.css" >如果您所在的域确实针对您的C:\xampp\htdocs\grade_your_room\public文件夹(检查 Apache 的虚拟主机配置)。
标签: html css variables path global