Lesson 1 Introduction To Cascading Style Sheet
Lesson 1 Introduction To Cascading Style Sheet
Lesson 1 Introduction To Cascading Style Sheet
1. color: yellow;
2. font-size: 11 px;
Syntax:
Example:
<!DOCTYPE html>
<html>
<body>
<h1 style="color:red;margin-left:40px;">Inline CSS is applied on this
heading.</h1>
<p>This paragraph is not affected.</p>
</body>
</html>
You cannot use quotations within inline CSS. If you use
quotations the browser will interpret this as an end of your
style value. https://www.javatpoint.com/inline-css
These styles cannot be reused anywhere else.
These styles are tough to be edited because they are not
stored at a single place.
It is not possible to style pseudo-codes and pseudo-classes
with inline CSS.
Inline CSS does not provide browser cache advantages.
Internal CSS is used to apply CSS on a single document or
page. It can affect all the elements of the page. It is written
inside the style tag within head section of html.
For example:
<style>
p{color:blue}
</style>
For example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: Red;
margin-left: 80px;
}
</style>
</head>
<body>
<h1>The internal style sheet is applied on this heading.</h1>
<p>This paragraph will not be affected.</p>
</body>
</html>
Output:
External CSS is used to apply CSS on multiple pages or all pages.
Here, we write all the CSS code in a css file. Its extension must be
.css for example style.css.
For example:
p{color:blue}
You need to link this style.css file to your html pages like this:
It uses the <link> tag on every pages and the <link> tag should be
put inside the head section.
Example:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
The external style sheet may be written in any text editor but must
be saved with a .css extension. This file should not contain HTML
elements.
File: mystyle.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
The external style sheet may be written in any text editor but must
be saved with a .css extension. This file should not contain HTML
elements.
File: mystyle.css
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
Note: You should not use a space between the property value and the unit. For
example: It should be margin-left:20px not margin-left:20 px.
CSS comments are generally written to explain your code. It is very
helpful for the users who reads your code so that they can easily
understand the code.