Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make my first web page.

I have the css file

body {
background-color: lightblue;
}

and the code
<!doctype html>
<html>
  <head>
    <title> My web Page </title>  
   
<link rel="stylesheet" type="text/css" href="leser/main.css">
  
  </head>

  <body>   
   <h1>  My webSite</h1>
   <ul> 
        <li>home </li>
        <li> <a href="page2.html"> page 2  </li>
        <li> <a href="page3.html"> page 3   </li>
   </ul>
   <h2> This is my homepage content</h2>
   </body>

</html>



The problem is that the css wont show. By accedent charged the default program for css programs into skype, but changed it back into notepad. I dont know which program it original was. Is it the code or the default program that is wrong?

What I have tried:

I have tried changing the default css opening program nto different types, and I tried making the css as a tage inside the index page, but that did not work.

I also tried this

<!doctype html>
<html>
  <head>
    <title> My web Page </title>  
   

<style>
body {
    background-color: red;
}

</style>
  </head>

  <body>   
   <h1>  My webSite</h1>
   <ul> 
        <li>home </li>
        <li> <a href="page2.html"> page 2  </li>
        <li> <a href="page3.html"> page 3   </li>
   </ul>
   <h2> This is my homepage content</h2>
   </body>

</html>
Posted
Updated 28-Nov-17 18:21pm
v3
Comments
Karthik_Mahalingam 29-Nov-17 0:49am    
the above code works. what is the issue?
Member 13546856 29-Nov-17 1:08am    
when I does it, it does not work.
The background is not red.
I beleve it has something to do with that I changed the default program to open css files, but I dont know.
Karthik_Mahalingam 29-Nov-17 1:17am    
this is what i have tried
<!doctype html>
<html>
<head>
    <style>
        body {
            background-color: red;
        }
    </style>
</head>
<body>
    <h1>  My webSite</h1>
    <ul>
        <li>home </li>
        <li> <a href="page2.html"> page 2  </li>
        <li> <a href="page3.html"> page 3   </li>
    </ul>
    <h2> This is my homepage content</h2>
</body>
</html>
enhzflep 29-Nov-17 1:25am    
Is the CSS file in the right place? You need to put the main.html file somewhere. Inside *that same location* you need a folder called "leser". Inside this new folder you put your css file.
If you do this, load the page, then hit Ctrl-Shift-I (Chrome) you'll bring up the developer tools. You'll see immediately if the file is found but some other problem prevents visual changes being made, since there will be a "failed to load" type error for the CSS file.
Member 13546856 29-Nov-17 1:31am    
The css is in the right file. I have a folder called "leser".
I load the page by pressing ctrl + o right?
Nothing happen when I press x + shift + l

What program should I mark as the one to read css files in?
when you right click a file and select "open as" and then mark "always use this program to open". I selected "Skype". Might this be the problem?

1 solution

Take a close look at your body tag in the HTML. You seem to have spelled it wrong.
 
Share this answer
 
Comments
Member 13546856 29-Nov-17 0:19am    
I changed it. That was not the solution
Dave Kreskowiak 29-Nov-17 8:02am    
OK, if you're got your HTML file in a folder and then your CSS file in a subfolder of that folder, this should work, IF everything is spelled correctly.

You also don't need the <!doctype html> tags.
Dave Kreskowiak 29-Nov-17 8:05am    
This is exactly what I did.

Create a folder on your Desktop, called "Test". Put this file in that folder and name this file "Test.html":
<html>
	<head>
		<title> My web Page </title>     
		<link rel="stylesheet" type="text/css" href="leser\main.css">
	</head>
 
<body>   
	<h1>My webSite</h1>
	<ul> 
		<li>home </li>
		<li><a href="page2.html">page 2</li>
		<li><a href="page3.html"> page 3</li>
	</ul>
	<h2>This is my homepage content</h2>
</body>
</html>

Create a subfolder called "leser" in the folder you created above. In this folder, create the following CSS file and call it "main.css":
body {
	background-color: lightblue;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900