简体   繁体   English

样式表不适用于Code Igniter

[英]Stylesheet not working with Code Igniter

I am trying to fit a stylesheet into view with CodeIgniter, please bare in mind I am new to CI. 我正在尝试使用CodeIgniter使样式表适合视图,请记住我是CI的新手。

So the stylesheet seems to be included right and I am checking the location, but it still doesn't seem to change a thing.. 因此,样式表似乎已正确包含,我正在检查位置,但似乎仍未更改任何内容。

this is my view: 这是我的看法:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title>newsletter</title>
<link rel="stylesheet" href="<?php echo base_url(); ?>application/css/style.css" media="screen" />
</head>

<body>
<label for="name"> HI TESTING STYLING & EMAILING</label>
<div id="newsletter_form">
<?php echo form_open('email/send'); ?>

<?php

$name_data = array(
    'name' => 'name',
    'id' => 'name',
    'value' => set_value('name')
);



?>

<p><label for="name">Name: </label> <?php echo form_input($name_data); ?></p>

<p><label for="email">Email Address: </label><input type="text" name="email" id="email" value="<?php echo set_value('email'); ?>">

    <p><?php echo form_submit('submit', 'Submit'); ?></p>
    <?php echo base_url(); ?>application/css/style.css
    <?php echo validation_errors('<p class="error">'); ?>

<?php echo form_close(); ?>
</div>
</body>
</html>

as you can see I am echoing out the url just to make sure and it is correct although it is forbidden.. not sure if this is standard CI procedure or if this is the cause.. I am working on my localhost. 如您所见,我正在回显该URL,只是为了确保它是正确的,尽管它是被禁止的。.不确定这是否是标准CI过程还是这是原因..我正在使用本地主机。

and this is my stylesheet... 这是我的样式表

label{
display: block;
background: #FFF;
}

.error{

 color: #373737;
}

#newsletter_form{
background: #000;
width: 100px;
}
input[type=submit]{
border: 1px solid #c62828;
background: #aa2929;
color: #e3e3e3;
padding: .5em;
cursor: pointer;    

}
 input[type=submit]:hover{
background: #9c2222;

}

thanks!! 谢谢!! I am confused, any help is appreciated :) 我很困惑,任何帮助表示赞赏:)

It is not good practice to put css/js files in your applications folder. 将css / js文件放在应用程序文件夹中不是一个好习惯。 Put it in a separate folder called "css" in your root and call it with base_url('css/style.css'); 将其放在根目录下的单独文件夹“ css”中,并使用base_url('css/style.css');调用base_url('css/style.css'); Your root folder should look like this 您的根文件夹应如下所示

-Root
  -application
    (all of your CI files)
  -css
    -Style.css
  -js
    -script.js
    -plugins.js

It is good if CodeIgniter is blocking Application/Css because that means it's protecting your raw files in your application folder properly :) 如果CodeIgniter阻止Application / Css很好,因为这意味着它可以正确保护应用程序文件夹中的原始文件:)

As Branden mentioned above CI will block access to that css file via the .htaccess file in that folder. 正如上文提到的布兰登所说, CI将阻止通过该文件夹中的.htaccess文件访问该css文件。 I would put it another folder as he mentioned. 我会把它放到他提到的另一个文件夹中。 I would also consider moving your index.php file to another folder (putting it outside of the web root) and then edit index.php to reflect the change. 我还将考虑将您的index.php文件移动到另一个文件夹(将其放在网络根目录之外),然后编辑index.php以反映更改。 Something like this: 像这样:

Root
- application
- public
   index.php
- system

Keep your web assets where you like, but I tend to keep them in the public folder. 将您的Web资产保留在您喜欢的位置,但是我倾向于将它们保留在公用文件夹中。

You can use base_url(); 您可以使用base_url(); method in CI. CI中的方法。

Example

CI APP Folder
-application
-system 
-css (supposed you have style.css inside in that folder named 'css')

You use in your views like this 您在这样的视图中使用

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

This might also work 这可能也可以

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

To set base_url() method path, you can check in application/config/config.php 要设置base_url()方法路径,可以检入application / config / config.php

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

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