Web developing noob - help needed for css [duplicate] - html

This question already has answers here:
How to link a CSS file from HTML file?
(2 answers)
Closed 1 year ago.
I am extreme beginner and I have this dumb problem.
So I wrote a css file and html file.
HTML :
<!DOCTYPE html>
<html>
<body>
<img
src="https://i.pinimg.com/originals/67/b2/a9/67b2a9ba5e85822f237caae92111e938.gif"
width="300" id="para1">
<p>Paragraph</p>
</body>
</html>
I did this for my css file
p {
color: red;
}
When I save and refresh my website, the html shows up.
The css doesnt show up like the paragraph doesnt change red. I also want to change the position of the image.
Please help!
I also want to know about indenting please.
Also should for website developing, should I learn css and html at the same time, or like html for 1 year, and then css for one year, because im learning javascript like in a 2 years, next year.

You must tell your HMTL page where to find your CSS.
To do that you have to add link tag into your head tag using:
<head>
<link href="/path/to/your/style.css" rel="stylesheet">
</head>
<link>: The External Resource Link element
The HTML element specifies relationships between the current
document and an external resource. This element is most commonly used
to link to stylesheets, but is also used to establish site icons (both
"favicon" style icons and icons for the home screen and apps on mobile
devices) among other things.
Take a look at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
In your case if your css file named style.css and your index.html file are on the same folder, your html should look like that:
<!DOCTYPE html>
<html>
<head>
<link href="style.css" rel="stylesheet">
</head>
<body>
<img src="https://i.pinimg.com/originals/67/b2/a9/67b2a9ba5e85822f237caae92111e938.gif" width="300" id="para1">
<p>Paragraph</p>
</body>
</html>
The HTML element contains machine-readable information
(metadata) about the document, like its title, scripts, and style
sheets.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
If you want to use inline css you have to put your <style> tag between your <head> tag to make it processed by HTML.
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: red;
}
</style>
</head>
<body>
<img src="https://i.pinimg.com/originals/67/b2/a9/67b2a9ba5e85822f237caae92111e938.gif" width="300" id="para1">
<p>Paragraph</p>
</body>
</html>

Also should for website developing, should I learn css and html at the
same time, or like html for 1 year, and then css for one year, because
im learning javascript like in a 2 years, next year.
Well, HTML, CSS & JS are the fabric of the front end so my advice is why not all three at the same time? They each compliment each other and after 3 years studying you will have understood more about them than focusing your time and energy learning each as separate entities.
Think of HTML as your initial sketch (your structure), CSS as painting your sketch (your make-up and beautifier), and JS as making your painting come to life (your functional and interactive parts). Simply put, it's more fun with working with all 3

Related

How html code flow works with internal CSS?

Hi i'm new in this world of HTML and CSS, so i just want to ask how the html code flow works, specifically html with internal CSS, so as i remember the code starts from the top to the bottom, giving this code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta>.......
<title>Document</title>
<style>
.container {background-color: tomato; padding: 20px;}
.text {color: green;}
</style>
</head>
<body>
<div class="container">
<p class="text">Hello World!!</p>
</div>
</body>
</html>
i would say that this runs normally, but what is first? i mean for example.. we can say that first the CSS styles are saved in a box then html elements are created and finally that box where the CSS rules are looks for the class names, tag names that are declared as CSS rules and starts matching and applying the styles with the correct html element that has relation with this ones (and resolving the complex stuff like specificity...)?, i mean that is how i think it works, in a nutshell am i correct??, and sorry if this sounds dumb i'm new in this :(
you can use css in three type
inline css
internal css
external css
in internal css you write code
<style> write your css </style>
in inline css for example
<h1 style="background-clour:red;">Hello </h1>
in externel css you can call tag by name, id,and so on
the page must be connected to the html page in the top.
<link href="../dashboard-file/css/sb-admin-2.min.css" rel="stylesheet">
this is your answer.

how to use the codes of a css document inline in html document

I wanted to create a contact-us page with HTML(no CSS document is allowed to use), then I found what I wanted but the code is written in 2 documents, HTML code is written in HTML document and the styles are in the CSS document. I'm looking for a way to use the CSS codes inline in the HTML document. Could you help me, please?
<html>
<head>
<style>
p {
color: green
}
</style>
</head>
<body>
<p>All your custom CSS can go in the head section of the HTML</p>
</body>
</html>
You will want to use a style tag like this: <style> </style> and inside will go the CSS.
It's good practice to keep your CSS in a seperate file to make the code look cleaner

Use of HTML tag [duplicate]

This question already has answers here:
Is it necessary to write HEAD, BODY and HTML tags?
(6 answers)
Closed 5 years ago.
Recently I created a demo webpage using HTML which contains an unordered list.
My code is:
<Html>
<Head>
<Title>Demo</Title>
</Head>
<Body>
<Ul>
<Li>one
<Li>two
<Li>three
</Ul>
</Body>
</Html>
But if I do only this:
<Ul>
<Li>one
<Li>two
<Li>three
</Ul>
and save it with a .html extension then both gives the same result. So what is the use of <html> tag?
The HTML tag tells the browser that the document is HTML. The reason that works without it, is because your browser is smart enough to see you have HTML there and fill in with the missing tags.
But sometimes if you have a more complicated document it may not know how to fill the blanks and other browsers may not have that functionality. So, always use the html, head and body tags.
The html tag will tell browsers it is going to be html and not xml.
However your browser will interpret it as html anyways, so even the Google style guide for HTML will tell you to Omit it.
The tag tells the browser that this is an HTML document. The tag represents the root of an HTML document. The tag is the container for all other HTML elements (except for the tag).
It is necessary for you to write or , as it acknowledges the browser of the scripting language or else complex codes on older browsers can not be interpreted.
I have been working in Html from past 3 years.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
</body>
</html>
this is a template for HTML. In head tags we set char set which is important as well as a Title for web page. Also, inside head there can be written other useful tags or can be linked bootstrap. This is a template you have to create when you start an HTML document. Your code fine without HTML structure but when your code will grow is size and get more complicated you will have errors in your code
Your Browser automatically add
<html>
<head>
</head>
<body>
............
</body>
</html>
That's why You don't see the difference.
If you check this Right Click on browser->Click Inspect
Then you will see that

How to import an HTML file [duplicate]

This question already has answers here:
How to create a template in HTML?
(3 answers)
Closed 8 years ago.
I have a website which has a navbar and a footer. I want every page of my website to contain this navbar and footer. I have put this HTML code into an HTML file where I have effectively created a website template.
I want this template.html file to be imported so that changes can be made simply and easily if needed. I have tried doing this like so:
<!DOCTYPE html>
<html>
<link rel="import" href="template.html">
<!-- PAGE CONTENT -->
</html>
If implemented correctly, the end result would should look like so:
<!DOCTYPE html>
<html>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<div class="navbar"></div>
<div class="footer"></div>
<!-- PAGE CONTENT -->
</html>
What would be the proper way of doing this? Thanks.
Please note: Content in HTML code has been edited down significantly to make it easier to read
According to the HTML 5 specification, there is not a rel="import" attribute value for link tags.
You have 3 options I know of:
Server Side Includes (SSI)
PHP/ASP/Perl/... name it server-side languages
Ajax to load stuff using Javascript from the server.
Depending on your server, one or more of those will work for you. Bad advice from some online resource won't, of course, so good thing you came here to get that refuted.
Just type in any of the terms above and you'll find a wealth of resources.

Why does Chrome Developer Tool add elements not in the file?

When I have a simple HTML markup like this:
<!DOCTYPE html>
<html>
<head>
<title>lawl</title>
</head>
<body>
</body>
</html>
When viewing the elements of the document, in the Chrome Deceloper Tool(F12) it looks likes this:
<!DOCTYPE html>
<html>
<head>
<title>lawl</title>
<style type="text/css"></style> <-- what the?
</head>
<body>
</body>
</html>
So, my question goes: Where does the style tag come from? What added it, and why?
Hope you guys can clear this up for us, it's been quite the subject the last 10 minutes in class ;-). Also worth mentioning; a class got added to a empty div in another document when the teacher tried it.
Edited title.
Chrome plugins can get access to your DOM, and so does the development tools. In this particular case, I think the development tools is the one to blame.
The empty style tag is probably a placeholder for injected CSS.
If you open the source code (view-source:www.example.com), you will see that your DOM is perfectly fine.
99:1 that the <style> element is a stylesheet injected by your AdBlock (or similar) extension.