简体   繁体   English

样式表不适用于 codeigniter

[英]stylesheet not working with codeigniter

I am new to codeigniter.I have created style sheet called mystyle.css with a folder structure of application/styles/mystyle.css .My view is first_view.php with a folder structure of application/views/first_view.php .I have placed the href link like this:我是 codeigniter 的新手。我创建了名为mystyle.css样式表,其文件夹结构为application/styles/mystyle.css我的视图是first_view.php ,文件夹结构为application/views/first_view.php 。我已放置像这样的href链接:

file:///C|/wamp/www/demo_code/application/styles/mystyle.css.

It doesnt work,but it displays the contents with no style.When i use like this它不起作用,但它显示的内容没有样式。当我这样使用时

href="<?php echo base_url('styles/mystyle.css');?>" 

the age is displayed with no contents.I didnt understand how this happens.Please help me年龄显示没有内容。我不明白这是怎么发生的。请帮帮我

EDIT

My config file contains like this:我的配置文件包含这样的:

$config['base_url'] = '';
$config['index_page'] = 'index.php';

I first advice u that it is recommended that store your css in assets我首先建议您建议将您的 css 存储在资产中

/www
/code_igniter
    /application
    /assets
        +img
        +css
        +js
    /controllers
    /system

then use it in your view as including it然后在您的视图中使用它作为包含它

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

into your .htacess file add this到你的 .htacess 文件中添加这个

  RewriteEngine on
  RewriteCond $1 !^(index\.php|assets|_searches|robots\.txt|favicon\.ico)
  RewriteRule ^(.*)$ /sample/index.php/$1 [L]

also include this assests folder into your .htaccess file还包括这个assests文件夹到你的.htaccess file

It is important to understand, that CSS is purely client-side, this has nothing to do with CodeIgniter.重要的是要理解,CSS 纯粹是客户端,这与 CodeIgniter 无关。 CodeIgniter generates HTML, which is parsed by the clients browser. CodeIgniter 生成 HTML,由客户端浏览器解析。

The HTML tag HTML 标签

<link rel="stylesheet" type="text/css" href="/css/format.css">

instructs your browser to download a separate stylesheet file /css/format.css which is fetched from the webserver in a seperate request .指示您的浏览器下载单独的样式表文件/css/format.css ,该文件是在单独的请求中网络服务器获取的。

Your webserver delivers this file, note that the path for all files requested from a webserver is relative to your webservers configured document root.您的网络服务器提供此文件,请注意,从网络服务器请求的所有文件的路径都相对于您的网络服务器配置的文档根目录。

../application/.. does not look like a folder in document root. ../application/..看起来不像文档根目录中的文件夹。 The folder is usually called htdocs or public or httpdocs.该文件夹通常称为 htdocs 或 public 或 httpdocs。 I think codeigniter is working with a central index.php where all dynamic requests are redirected to.我认为 codeigniter 正在使用一个中央 index.php ,所有动态请求都被重定向到其中。 Static files have to be in the same folder or below.静态文件必须在同一文件夹或以下文件夹中。

使用此代码集成样式表

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

Change this line by this in confing file在配置文件中通过此更改此行

$config['base_url'] = 'http://localhost/your_project_name/';

if you are running your site on local server then do nothing if your have running on other server then type its name (domain name) and replace with localhost .如果您在本地服务器上运行您的站点,那么如果您在其他服务器上运行,则什么都不做,然后键入其名称(域名)并替换为localhost

At first change your folder structure to首先将您的文件夹结构更改为

 /public/css/mystyle.css (optional)

To include a stylesheet you can do this at要包含样式表,您可以在

 <head> tag:

as作为

<LINK href= "<?=site_url(); ?>public/css/mystyle.css" rel="stylesheet" type="text/css">

if doesn't work you must configure your .htaccess如果不起作用,您必须配置您的 .htaccess

Put the stylesheet, js or other resource outside the application folder.将样式表、js 或其他资源放在应用程序文件夹之外。 it is standard and secure.它是标准和安全的。 Use this line to include css or js.使用此行包含 css 或 js。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM