Welcome Guest, Not a member yet? Register   Sign In
Site can not get CSS file
#1

[eluser]StevenTen[/eluser]
Hi everyone,

I'm trying to run my code on localhost, and I config it like this:

Code:
$config['base_url']='http://localhost:8080/'

In my html file, I add css like this:
Code:
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">

But when I run the site, it will display without css style

But inside the web, the url is successfully linked. For example:
Code:
href="<?php echo base_url();?>user/login"
can jump to the right page.

But why can not find css file??
#2

[eluser]jzmwebdevelopement[/eluser]
Do you get any errors?

What localhost programme are you using?
#3

[eluser]skunkbad[/eluser]
If using a base tag try:

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

If not using a base tag, try:

Code:
<link rel="stylesheet" type="text/css" href="/css/style.css">

You could also use codeigniter's link_tag(), which I believe is in the html helper:

Code:
echo link_tag( array( 'href' => 'css/style.css', 'media' => 'screen', 'rel' => 'stylesheet' ) );

And I believe the proper way to use the base_url is like this:

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

[eluser]Aken[/eluser]
I cannot believe how many people are trying to program PHP, but CANNOT fix this extremely simple problem.
#5

[eluser]skunkbad[/eluser]
[quote author="Aken" date="1333767925"]I cannot believe how many people are trying to program PHP, but CANNOT fix this extremely simple problem.[/quote]

This statement would be appropriate for 50% of the questions asked in this forum.
#6

[eluser]Aken[/eluser]
Ain't that the truth...
#7

[eluser]InsiteFX[/eluser]
His base_url is wrong! He's not showing any directory where CI is installed...
#8

[eluser]skunkbad[/eluser]
[quote author="InsiteFX" date="1333773003"]His base_url is wrong! He's not showing any directory where CI is installed...
[/quote]

Maybe the website is in public root, and not in a subdir?
#9

[eluser]StevenTen[/eluser]
Thanks skunkbad, this works fine now!
[quote author="skunkbad" date="1333692816"]If using a base tag try:

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

If not using a base tag, try:

Code:
<link rel="stylesheet" type="text/css" href="/css/style.css">

You could also use codeigniter's link_tag(), which I believe is in the html helper:

Code:
echo link_tag( array( 'href' => 'css/style.css', 'media' => 'screen', 'rel' => 'stylesheet' ) );

And I believe the proper way to use the base_url is like this:

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




Theme © iAndrew 2016 - Forum software by © MyBB