Reputation: 1266
i dont see that my web page is changing according to the style defined in the css file. when i added the same in html file, it is working. can someone please help. dont know what is wrong.
below is my simple html file
<html>
<head>
<title>css</title>
<body>
<link rel="stylesheet" type="text/css" href="style.css">
test
</head>
</body>
</html>
below is my css file.
<style>
body
{
background-color:lightblue;
}
</style>
Upvotes: 1
Views: 792
Reputation: 14593
You are using wrong CSS syntax. In a CSS file, there are no <style></style>
tags, they are just rules. So you should have:
body
{
background-color: lightblue;
}
Also, you should link
your CSS file into the <head>
tag, it is better for your file's organization.
Upvotes: 0
Reputation: 345
always css link in head section, u can also see the path of the file, Do not use type attributes for style sheets (unless not using CSS),Specifying type attributes in these contexts is not necessary as HTML5 implies text/css and text/javascript as defaults. This can be safely done even for older browsers type="text/css"
HTML
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
hello
</body>
</html>
Upvotes: 0
Reputation: 4828
You wrapped the head tag around everything. And a link tag should always be placed between head tags and not in the body tag.
your code should be like the example below. All the rest seems fine.
<html>
<head>
<title>css</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
test
</body>
</html>
Css should be like this:
body {
background-color:lightblue;
}
Upvotes: 0
Reputation: 3755
Change css file as: Remove <style> </style>
body
{
background-color:lightblue;
}
Also correct the format of html as
<html>
<head>
<title>css</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
test
</body>
</html>
This works for Me. Make sure your html and css both the files should be in same folder.
Upvotes: 2
Reputation: 1403
Try this.
HTML-
<html>
<head>
<title>css</title>
<link href="style.css" rel="stylesheet" />
</head>
<body>
test
</body>
</html>
CSS-
body {
background-color: lightblue;
}
Upvotes: 0
Reputation: 7100
<style>
body {
background-color:lightblue;
}
</style>
is not a right way to write a .css
file.
Remove those style tags from your .css
file and check again.
Also,
Make sure your .html
and .css
files are on the same path
(In order to make things work without changing the link
tag in your html
head
Just noticed:
Your body
tag is INSIDE your head
tag. Which is incorrect.
Right way to do so is,
<html>
<head>
<title>css</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
test
</body>
</html>
Upvotes: 2