8 Replies - 4317 Views - Last Post: 07 March 2009 - 07:01 PM

#1 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

linking CSS file to html file

Posted 03 March 2009 - 11:57 AM

Ok Everyone,

So this is my first ever experience with CSS/HTML. I'm a java programmer mostly so this web stuff is new to me. I can't seem to get an external CSS file to link into my html file so the changes that are outlined in my CSS file will take effect.

As for a reference, the CSS file and the HTML file are currently located in the same directory.

here is the code for the CSS file...
body 
{
	background-color:#339900
}
/*This defines the color of header 1*/
h1
{
	color:#000000
}

/*This defines the color of header 2*/
h2
{
	color:#AAAAAA
}


And here is the code for my html file

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<link rel="stylesheet" type="text/css" href="cssSheet.css" />
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Code Perspective</title>
	</head>
	<body>
	   <h1>Test</h1>
	   <h2> This is a Test</h2>
	</body>
</html>


The css file is name "cssSheet.css" for a reference. Any help would be appreciated. I know this is a basic question...lol. Cheers

Is This A Good Question/Topic? 0
  • +

Replies To: linking CSS file to html file

#2 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Re: linking CSS file to html file

Posted 03 March 2009 - 12:18 PM

Your link in your html looks fine, except that you are missing media="screen".

You are though missing semicolons after your css actions.

body
{
	background-color:#339900;
}
/*This defines the color of header 1*/
h1
{
	color:#000000;
}

/*This defines the color of header 2*/
h2
{
	color:#AAAAAA;
}


Was This Post Helpful? 0
  • +
  • -

#3 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: linking CSS file to html file

Posted 03 March 2009 - 12:39 PM

Ok right on thank you! I tried putting the semi-colons into my CSS file and it gives me errors after every semi-colon. I'm using Aptana as an IDE if that matters.
Also, i added the media=screen and that didn't seem to import it as well.

Cheers

This post has been edited by markhazlett9: 03 March 2009 - 01:35 PM

Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3802
  • View blog
  • Posts: 13,798
  • Joined: 08-August 08

Re: linking CSS file to html file

Posted 03 March 2009 - 01:50 PM

Is the style sheet in the same directory as the html file? The way you have it, that's where it should be.
Was This Post Helpful? 0
  • +
  • -

#5 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: linking CSS file to html file

Posted 03 March 2009 - 05:02 PM

Ya i did put it in the same file. They are both within the Aptana workspace project folder in my directory.
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3802
  • View blog
  • Posts: 13,798
  • Joined: 08-August 08

Re: linking CSS file to html file

Posted 03 March 2009 - 07:26 PM

Your browser may not like the trailing /
Try it without it:
<link rel="stylesheet" type="text/css" href="cssSheet.css" >

Was This Post Helpful? 0
  • +
  • -

#7 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: linking CSS file to html file

Posted 03 March 2009 - 10:17 PM

Ok i seemed to have resolved the issue. Apparently it was an IDE issue. When running through aptana it wasn't able to find the css file but when run manually through the directory it worked fine... Thanks for the help everyone.
Was This Post Helpful? 0
  • +
  • -

#8 gregwhitworth   User is offline

  • Tired.
  • member icon

Reputation: 221
  • View blog
  • Posts: 1,613
  • Joined: 20-January 09

Re: linking CSS file to html file

Posted 04 March 2009 - 09:33 PM

No prob, but as a side not - NEVER use an IDE as your display. Always code in the IDE and have a browser open to the file, I have yet to find an IDE that displays correctly at all times.

--

Greg
Was This Post Helpful? 0
  • +
  • -

#9 markhazlett9   User is offline

  • Coding is a lifestyle
  • member icon

Reputation: 61
  • View blog
  • Posts: 1,666
  • Joined: 12-July 08

Re: linking CSS file to html file

Posted 07 March 2009 - 07:01 PM

View Postgregwhitworth, on 4 Mar, 2009 - 08:33 PM, said:

No prob, but as a side not - NEVER use an IDE as your display. Always code in the IDE and have a browser open to the file, I have yet to find an IDE that displays correctly at all times.

--

Greg



Well then maybe that shall be a future project... :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1