views:

128

answers:

4

I'm using xampp for my php. And I have download a code igniter and save it on my htdocs. I already made a databasing and a sample page. My only problem is how can I link my css. Where should I save my style.css? How can I call my style.css?

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

I have this but still have a problem. Is there a step by step on how to link a css?

Thank You.

+1  A: 

You can put your stylesheet anywhere really - it's just a matter of getting your directory to it correctly. The code you posted is going to look in your main directory (the folder with the license, system, user_guide, etc. It's going to a look for a folder called 'stylesheet', and then for style.css.

Make sure that you have your stylesheet in there.

DexterW
+1  A: 

Using the Firefox plugin FireBug will help a lot with that. View the source of the HTML that was output, and find out where the browser is looking for that stylesheet, and make sure it's there.

Zack
+1  A: 

Put your CSS wherever you’d like, then target that url.

Try putting it in the folder ‘/css/test.css’ for instance ‘/’ being the root of your site, not your CI install.

From CI, you can then call it with

<?= link_tag(base_url().'css/test.css'); ?>

That should generate the following code

<link href="http://yoursite.com/css/test.css" rel="stylesheet" type="text/css" />

If you’re having trouble targetin the CSS, the easiest way to find out where your script is trying to call it, is to look in your web pages source output. You’ll see exactly where CI thinks it’s located.

Sarfraz
A: 

hi, This is Syed Haroon from Mysore, Karnataka, India.

Assume: Root Folder Name: ci_test CSS file name : mystyles.css"; Controller file name: Start.php view file name: test_view.php

Solution:

Suggestion for WAMP (hope it will be easy to fix the same in xampp):

Save it in root/system/application/css

Create a new CSS directory in application folder (just to Manage files and folder in the correct way)

How to connect back to CSS file?

in system/application/config/config.php Edit "$config['base_url'] = http://localhost/" to

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

Crate a new line

$config['css'] = "system/application/css/mystyles.css";

Create a Controller in "system/application/controllers/start.php" insert the below sample code:

class Start extends Controller {
 var $base;
 var $css;

 function Start(){
  parent::Controller();
  $this->base = $this->config->item('base_url');
  $this->css = $this->config->item('css');
 }

 function hello(){
  $data['css'] = $this->css;
  $data['base'] = $this->base;
  $data['mytitle'] = 'Welcome to this site';
  $data['mytext'] = "Hello, now this is how CSS work!";
  $this->load->view('test_view', $data);
 }
}

Crate a view file in "system/application/views/test_view.php" insert the below sample code:

<html>
<head>
<title>Web test Site</title>
<base href= <?php echo "$base"; ?> >
<link rel="stylesheet" type="text/css" href="<?php echo "$base/$css";?>">
</head>
<body>
<h1><?php echo $mytitle; ?> </h1>
<p class='test'> <?php echo $mytext; ?> </p>
</body>
</html>

now enter this in ur address bar of the browser "http://localhost/ci_test/index.php/start/hello/"

Syed Haroon