Part of the EllisLab Network
   
 
Strange CSS parsing (maybe bug)
Posted: 06 December 2006 08:56 AM   [ Ignore ]  
Summer Student
Total Posts:  5
Joined  12-06-2006

I’am using CI 1.5.1

Two servers:
* linux, apache 2.0, php 5.1
* windows, apache 2.2, php 5.2

So the problem: CI cant’ parse CSS file, when it included in the VIEW like so:

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

. In windows enviroment i got strange error in FF, like a MIME types mix, something about “the css file is text/html type and you need text/css”. I checked the apache config and MIMES types, but all seems ok. And standalone php worked fine (without CI). On linux server theres is no erros, but CSS is not parsed by browser.

It is ok, when you gives the full path.
Or you can do something like that:

<style type="text/css"><?php=get_file_content(path_to_css.'/style.css');?></style>


But this is not a option in my situation, i have a couple js libs, that using CSS include (you can see this in attachment).

In attached file you can see code generated inside of browser with Firebug (it shows a default CI_404, why?). The js and css are in the same directory.

There is something with relative paths to do. Maybe?

Thanks a lot.

Profile
 
 
Posted: 06 December 2006 01:28 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006
Topaz - 06 December 2006 08:56 AM

There is something with relative paths to do. Maybe?

That would be my guess. Try this thread for some tips, particularly where it mentions base_url(). The base_url function is a good way to deal with relative paths.

Profile
 
 
Posted: 06 December 2006 04:39 PM   [ Ignore ]   [ # 2 ]  
Grad Student
Rank
Total Posts:  80
Joined  09-14-2006

You can also have the view write out a var you can use in your

<scrypt type="text/javascript">
var
base_url = '<?=base_url()?>';
</script>

Edit: had to obfuscate a bit to avoid getting the script tags parsed out.

 Signature 

LuTze
If the world didn’t suck, we’d all fall off.
Artful Code

Profile
 
 
Posted: 11 December 2006 06:31 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  5
Joined  12-06-2006

This is not a solution, when you have a complex js library, that operating with html or css inside… :S

Profile
 
 
Posted: 11 December 2006 06:43 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  481
Joined  03-08-2006

You cannot embed Jscript inside a CSS file.

 Signature 

Flickr | Last.fm | Del.icio.us

Profile
 
 
Posted: 11 December 2006 06:52 AM   [ Ignore ]   [ # 5 ]  
Summer Student
Total Posts:  5
Joined  12-06-2006

Indeed, but vice versa?..

Profile
 
 
Posted: 11 December 2006 07:51 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  481
Joined  03-08-2006

Yes you can output CSS via Javascript, but only using something like document . write(). or setting attributes of elements using the DOM.

 Signature 

Flickr | Last.fm | Del.icio.us

Profile
 
 
Posted: 11 December 2006 08:02 AM   [ Ignore ]   [ # 7 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6762
Joined  03-23-2006

You can also change the style property of an element on the page via the DOM.

document.getElementById('element_id').style.color = '#900';

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 12 December 2006 08:19 AM   [ Ignore ]   [ # 8 ]  
Summer Student
Total Posts:  5
Joined  12-06-2006

Thank you, but i know this solutions and there is problems with that.
I have for example 5 different javascript 3rd party libs, that coded something like that:

function AddCss(){
    niftyCss
=true;
    var
l=CreateEl("link");
    
l.setAttribute("type","text/css");
    
l.setAttribute("rel","stylesheet");
    
l.setAttribute("href","http://192.168.1.50/cms/css/niftyCorners.css");
    
l.setAttribute("media","screen");
    
document.getElementsByTagName("head")[0].appendChild(l);
}

And i have to install my CI program to N servers, i have to update those libs (new version of the lib) and so on . This is not a solution to rewrite every time libs and all 3rd party stuff to do there job.

Profile
 
 
Posted: 12 December 2006 09:14 AM   [ Ignore ]   [ # 9 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

I could be wrong, but it seems to me that your .htaccess file may be causing Apache to send the request for your css to CI there by causing the 404. Below are the rewrite rules that I use so that if a request file exists statically on the server (images, css, js, etc) it is served normally, otherwise the request is sent to CI.

RewriteEngine On
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ /index.php/$1 [L]

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 12 December 2006 07:56 PM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  351
Joined  07-25-2006
joeles - 12 December 2006 09:14 AM

I could be wrong, but it seems to me that your .htaccess file may be causing Apache to send the request for your css to CI there by causing the 404. Below are the rewrite rules that I use so that if a request file exists statically on the server (images, css, js, etc) it is served normally, otherwise the request is sent to CI.

RewriteEngine On
RewriteCond
%{REQUEST_FILENAME} !-f
RewriteCond
%{REQUEST_FILENAME} !-d
RewriteRule
^(.*)$ /index.php/$1 [L]

This is a pretty decent rewrite request. I found the following .htaccess in the CI wiki (or forums?) a while back and have used it ever since:

<IfModule mod_rewrite.c>
        
RewriteEngine On
        RewriteBase
/
        
RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond
%{REQUEST_FILENAME} !-d
        RewriteRule
^(.*)$ index.php/$1 [PT,L]
</IfModule>

It’s nearly the same as yours, but using [PT,L] instead of just [L] opens up a few other options. (PT = “pass thru”, check the Apache docs on this, I can’t even begin to explain why it’s good to use it.) You can also replace RewriteBase with your relative path (ie, if your CI_ROOT is “/~someuser/ci”, you just do: RewriteBase /~someuser/ci/

People have different opinions about the good/evil of IfModule, so I’ll just not comment on that. 8)

 Signature 

me and some random code, hosted by dh. and a blog too! ++ dead bugs

Profile
 
 
Posted: 12 December 2006 08:18 PM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Cool, thanks for the tip, Shadowhand.

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 13 December 2006 11:05 AM   [ Ignore ]   [ # 12 ]  
Summer Student
Total Posts:  5
Joined  12-06-2006

Thank you very very much! This worked!
I think this is important solution smile

Profile
 
 
Posted: 15 December 2006 03:23 PM   [ Ignore ]   [ # 13 ]  
Grad Student
Rank
Total Posts:  82
Joined  05-26-2006
Craig - 11 December 2006 06:43 AM

You cannot embed Jscript inside a CSS file.

Yeah, but styles can have Javascript, if you’ve specified the style type as “text/javascript” wink

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66412 Total Logged-in Users: 30
Total Topics: 84752 Total Anonymous Users: 1
Total Replies: 454812 Total Guests: 213
Total Posts: 539564    
Members ( View Memberlist )
Newest Members:  NirCalexmuellerkizerdrixcaptainredmuffquinodligtharttechsivamDjordjesammozzazodman23