【问题标题】:How to apply css style in codeigniter如何在 codeigniter 中应用 css 样式
【发布时间】:2014-12-12 01:22:25
【问题描述】:

我无法在视图中应用 CSS 样式。

我也在 config.php 中设置了 base_url..

config['base_url']='http://localhost/test_project/'

我的代码是

<html>
<head>
<title>Untitled Document</title>

<link type="text/css" href="<?php echo base_url()?> css/mycss.css" >
</link>

</head>

<body>

<p> This is test.</p>
</body>
</html>

我的 CSS 代码是

p
{
	color:#0066CC;
}

但它只显示简单的文本.. 如何在codeigniter中应用CSS......

【问题讨论】:

    标签: php css codeigniter


    【解决方案1】:

    把路径放在函数里面。在链接标签中包含rel="stylesheet"。您也不需要结束 &lt;/link&gt;

    <link rel="stylesheet" type="text/css" href="<?php echo base_url('css/mycss.css'); ?>">
    

    查看页面的源代码,应该会看到包含的 CSS 是这样的

    <link rel="stylesheet" type="text/css" href="http://localhost/test_project/css/mycss.css">
    

    【讨论】:

    • 还是不行...页面显示链接的源代码但是不能应用。
    • 源显示什么?粘贴整个页面的源代码,因为它是一个小测试页面。
    • 无标题文档 localhost/fleetmaster/css/mycss.css" >

      这是测试

    • 所以它没有使用localhost/test_project ...你确定你将/application/config/config.php设置为$config['base_url']='http://localhost/test_project/';吗?
    • Chrome 开发者工具网络标签是否在文件上显示 404 错误?你的名字一样吗?
    【解决方案2】:

    你需要在html标签中加入属性rel="stylesheet"

    <link type="text/css" href="<?php echo base_url('css/mycss.css') ?>" rel="stylesheet" >
    

    如果您的 css 文件加载正常,请检查您的萤火虫。

    例如,您可以使用名为“base”的 html 标签:

    <base href="http://url" />
    

    在您的代码中:

    <html>
    <head>
       <title>Untitled Document</title>
       <base href="<?php echo base_url()?>" />
       <link type="text/css" href="css/mycss.css" rel="stylesheet"></link>
    </head>
    <body>
       <p> This is test.</p>
    </body>
    </html>
    

    【讨论】:

      【解决方案3】:

      我使用codeigniter的默认功能。例如:

      echo link_tag('assets/css/bootstrap.css');
      

      【讨论】:

        猜你喜欢
        • 2011-10-10
        • 1970-01-01
        • 2013-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多