【发布时间】:2013-06-16 13:30:50
【问题描述】:
我有一个非常简单的html页面:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" type="text/css" href="http://127.0.0.1/assets/css/main.css" />
</head>
<body>
<div>hello world!</div>
<br/>
<div id='global_footer'>copyright 2013</div>
</body>
</html>
main.css 是:
body { font-family: arial; background-color: rgb(185,179,175); }
我通过单击浏览器源代码页面中的链接来确保链接正常工作,并且浏览器确实正确加载了 css 源代码。
但是,CSS 不适用于页面。如果我删除 DOCTYPE 行,完全相同的代码可以正常工作。真的不知道是什么原因。
有关更多信息,我正在使用 CodeIgniter。 assets 文件夹位于我的文档根目录下,与应用程序文件夹同级。我已将 css 添加到根的 .htaccess 以确保它正确加载 css 文件而不添加 index.php。我觉得CI相关设置没问题,浏览器可以定位到css文件,不然没有DOCTYPE行应该不行。
谢谢。
----编辑----
各位,感谢您测试 html 和 css。我测试过,他们自己工作得很好。我认为问题出在CI。我的文档根目录中有 assets 文件夹,位于 subfoder 和 main.css 文件中。不知道为什么这个 html 和 css 在 CI 下不起作用。我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$this->load->helper(array('html','url'));
$this->load->view('main');
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
谢谢。
【问题讨论】:
-
它工作正常:jsfiddle.net/eHDS3(在预览中查看源代码,您会看到它有
<!DOCTYPE html>。您的问题在其他地方。 -
非常适合我,我什至在没有 JSFiddle 的情况下在本地对其进行了测试。
-
你是从127.0.0.1...还是从HD加载你的html文件
-
顺便说一句:你不需要
http://127.0.0.1链接到 css。http://127.0.0.1仅适用于您计算机上的本地服务器,但不适用于远程服务器。 -
127.0.0.1 和 localhost 都链接到本地服务器,但你不应该混合使用这两者,使用一个或另一个
标签: php css codeigniter