I use this code for HTML:
<!DOCTYPE html>
<html>
<head>
<title>TestSite</title>
<link href="site.css" rel="stylesheet">
<h1>Hello World</h1>
</head>
</html>
And this code for CSS:
h1 {
color: red;
}
You already have it in your code :
<link href="site.css" rel="stylesheet">
You rename your css file site.css and you put it in the same folder of your html file !
Related
My problem is that my website that I'm attempting to host with Github pages will not read the CSS that I have linked to it.
My HTML looks like this:
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="https://github.com/legoman8304/legoman8304.github.io/blob/master/style.css">
<html>
<body>
<h1>Hello World</h1>
<p>I'm under construction!</p>
<h6>Copyright MIT Licence 2018</h6>
</body>
</html>
My CSS looks like this:
body {
background-color: lightblue;
}
h6 {
color: navy;
margin-left: 20px;
}
Link repository: legoman8304.github.io
I'm guessing I linked the CSS wrong because when I using inspect element on the site itself it does show style.css but when opened it's empty. Any help?
You need to link your HTML to the github page rendered style.css and not the file itself in the repo.
Change this:
<link rel="stylesheet" type="text/css" href="https://github.com/legoman8304/legoman8304.github.io/blob/master/style.css">
To this:
<link rel="stylesheet" type="text/css" href="https://legoman8304.github.io/style.css">
And move that stylesheet reference inside your <head> tag.
You can use some way:
Recommend: <link type="text/css" rel="stylesheet" href="style.css" />
Use from raw your css with href: https://raw.githubusercontent.com/legoman8304/legoman8304.github.io/master/style.css
Hello I am trying to set an image as a background using a css file in an index.html, however I use the css declaration the image will not be displayed even if you put it on html, can you please help me figure it out, thank you
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Solution</title>
<style>
body{
background: url("img/notarde.png")
}
</style>
</head>
<body>
HI
</body>
</html>
CssFile
body{
background: url("img/notarde.png")
}
If you have your style in <style></style> it is not needed to add the same content in a CSS file to do it.
However, if you wants to use an external CSS file you can add this line between the <head></head> :
<link rel="stylesheet" type="text/css" href="THE_PATH_OF_YOUR_FILE">
Your code works, it must be the path of the image that went wrong.
See it here
You need to include the stylesheet in the index.html file.
<link rel="stylesheet" type="text/css" href="[your css file path]">
I hope that helps :D
Have you referenced the CSS file in your HTML Page?
<link rel="stylesheet" type="text/css" href="mystyle.css">
Specify the CSS file name and path in href like href="CSS/filename.css"
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Solution</title>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<body>
HI
</body>
</html>
HTML file:
<html>
<head>
<link rel=“stylesheet” type=“text/css” href=“style.css” />
</head>
<body>
<p>Red</p>
</body>
</html>
CSS file:
p {
color: red;
}
The word 'Red' does not change to red text when I open the page in a browser. If anyone would know why my CSS file isn't linking to the HTML file that would be greatly appreciated. The files are in the same directory.
The code you have provided has no errors.
Fiddle: https://jsfiddle.net/9n97Lz69/
Please copy & paste the following code into your html file and verify this works:
index.html:
<style>
.menu p {
color: red;
}
</style>
<div class="menu">
<p>This sentence should be red.</p>
</div>
Fiddle: https://jsfiddle.net/21umj65u/
Then move the CSS to mystyle.css and verify this works:
index.html:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
<div class="menu">
<p>This sentence should be red.</p>
</div>
mystyle.css:
.menu p {
color: red;
}
Please check the file location of mystyle.css and verify against the url in index.html:
index.html:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Your code seems fine, perhaps "p" is already defined in your css file.Try this
.menu p {
color: red !important;
}
I am super new to HTML and CSS and I ran into a problem when I try to link CSS code in HTML. The code doesn't show the background color like it should. HTML Code:
<!doctype html>
<html>
<body>
<link href="styles/main.css" rel="stylesheet" type="text/css"/>
<body>
</html>
CSS code:
body {
background: #999;
}
I have them both in the same folder. I am lost and confused so any help would be greatly appreciated!
CSS files should be included in the head section. If you have them in the same folder you need to change the href aswell.
<!doctype html>
<html>
<head>
<link href="main.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<body>
</html>
You have to use href="main.css"
By using styles/ the browser searches for a folder called styles in the same folders and can't find it so no CSS will be applied
Try adding the link element to head tag instead of body tag.
I have a folder with my loginform.html and a CSS subdirectory with a simple CSS file:
<!DOCTYPE HTML>
<html>
<header>
<title>Login Forms</title>
<link href="CSS/LoginForm_CSS_1.css" rel="stylesheet">
</header>
<body>
</body>
</html>
The problem is that I cannot link them, and I cannot understand why, I tried:
<link href="CSS/LoginForm_CSS_1.css" rel="stylesheet">
and
<link href="/CSS/LoginForm_CSS_1.css" rel="stylesheet">
and
<link href="../CSS/LoginForm_CSS_1.css" rel="stylesheet">
but nothing works, when I put the LoginForm_CSS_1.css file in the same directory as the html file and use <link href="LoginForm_CSS_1.css" rel="stylesheet"> everything are ok. Any idea what I am doing wrong?
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="CSS/LoginForm_CSS_1.css" rel="stylesheet">
</head>
<body>
</body>
</html>
head tag is for root, header tag should be in the body!