Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Ashley Carpenter
Ashley Carpenter
13,393 Points

Why won't my variable field pick up my CSS file?

I am using the following code in my navigation as a link to my CCS file:

<link rel="stylesheet" href=<?php $csslink ?> type="text/css" media="screen">

I have also tried:

<link rel="stylesheet" href="$csslink" type="text/css" media="screen">

and:

<link rel="stylesheet" href="<?php $csslink ?>" type="text/css" media="screen">

but i can't get it to work. Can some good samaritan please tell me how i'm an idiot?

Hi Ashley,

Can you show us what your $csslink variable is set to?

Also, are you getting any kind of error or is it just not linking?

Have you looked at the html source to see what you do get?

3 Answers

Your 3rd example should work correctly assuming you have your link variable set right but you need to echo the variable to the page.

You should also get in the habit of ending your statements with semi-colons.

<link rel="stylesheet" href="<?php echo $csslink; ?>" type="text/css" media="screen">
Ashley Carpenter
Ashley Carpenter
13,393 Points

Hi, I gave it 20 minutes last night and sorted it but thanks for your help! It's very much appreciated.

You're right about the semi-colon as we'll. That is a bad habit I have picked up!

Jaime Bernal
Jaime Bernal
8,068 Points

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

Ashley Carpenter
Ashley Carpenter
13,393 Points

Sorry i can't get my code to paste properly.

i'm trying href=<?php $csslink ?> but it's not linking to my stylesheet

Jaime Bernal
Jaime Bernal
8,068 Points

Reference the markdown cheatsheet below in order to paste your code here. Otherwise the website will remove your code.

Ashley Carpenter
Ashley Carpenter
13,393 Points

Thanks, the question should make more sense now