【问题标题】:how can i include base_url inside background url in css Codeigniter如何在 CSS Codeigniter 的背景 url 中包含 base_url
【发布时间】:2016-01-28 06:08:17
【问题描述】:

大家好,我需要帮助,我正在尝试将 base_url 包含在 CSS 文件中的背景 url 中,但它不起作用,我需要帮助。

  background: url('<?php echo base_url();?>assets/images/re_1.png') repeat;
color: #413c35;
-webkit-font-smoothing: antialiased;
overflow-x: hidden;

【问题讨论】:

  • 你不能在css中运行php代码,不要尝试这个
  • 那我能做什么呢?
  • 您可以使用javascript + php,使用javascript您可以应用样式,使用php您可以将base_url()传递给java脚本
  • 或者你可以提供@Sumanta736 coffeecup.com/help/articles/absolute-vs-relative-pathslinks定义的相对路径
  • css文件放在哪里?

标签: php html css codeigniter


【解决方案1】:

试试这个:

body {
 background:#356aa0 url(../img/background.png) repeat-x;
 color:#fff;
}

现在叫它:

<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/style.css"/>

【讨论】:

    【解决方案2】:

    试试这个

    css

    background:url('assets/images/re_1.png');
    color: #413c35;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    

    html

     <link rel="stylesheet" href="<?php echo base_url('example.css');?>">
    

    example.css 更改为你的 css 文件路径

    【讨论】:

      【解决方案3】:

      在你的视野中编写 css

      <style>
      .blah{ 
         background: url('<?php echo base_url();?>assets/images/re_1.png') repeat;
        color: #413c35;
        -webkit-font-smoothing: antialiased;
        overflow-x: hidden;
        }
      </style>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-19
        • 2017-07-21
        • 2013-08-04
        • 1970-01-01
        相关资源
        最近更新 更多