A822959691 - 25374 - 29 - 2020 - HTML CSS Javascript
A822959691 - 25374 - 29 - 2020 - HTML CSS Javascript
The Element Selector: The element selector uses the element’s name as
the basis for implementing a style.
• For example:
p{
text-align: left;
color: blue;
}
• The above style rule will result in all <p> elements to be left-aligned with a
blue text color.
CSS SELECTORS
ID Selector: ID selectors name an element’s id attribute as the basis
for implementing a style set. An element with that ID will be
formatted according to its style rule. To use the ID selector, you will
write a hash (#) character before the element’s ID.
• For example, the following style rule will apply to an element with the
id of "parax":
#parax {
text-align: left;
color: blue;
}
CSS SELECTORS
Class Selector: Class selectors are used to format elements with a
particular class attribute. The style rule you define will apply to all
elements that match the specified class. To use the class selector, you
will write a period (.) before the class name.
• For example, in the following code, all HTML elements with
class="black" will be blue and left-aligned:
.black {
text-align: left;
color: blue;
}
INSERTING A STYLE SHEET
• There are three ways to insert a style sheet:
• External style sheet
• Internal style sheet
• Inline style
External Style Sheets : An external style sheet allows you to change the look of
multiple pages and the layout of your entire website by simply changing a single
file. Any modification made to the external style sheet instantly updates all web
pages. The external style sheet is implemented by making a reference to the file
inside the link element placed within the <head> section of the HTML page.
EXTERNAL STYLE SHEETS
INTERNAL STYLE SHEETS
• An internal style sheet is commonly used when you want to present a
page in a different style.
• It is defined inside the <style> element placed within the <head> and
</head> tags of the HTML page.
• For example, the following code uses an internal style sheet to create
a pink background for the entire page and a heading in green font:
INTERNAL STYLE SHEETS
INLINE STYLE SHEETS
• An inline style is commonly used to apply a unique style or isolated
changes to a single element such as a headline, paragraph, or other
element.
• The use of inline style will override both external and internal style
sheets.
• To use it, you have to add the style attribute to the specific element.
INLINE STYLESHEET
<!DOCTYPE html>
<html>
<body>
<h1 style="color:yellow;margin-left:25px;">This space is reserved for a
heading. </h1>
<p>This is a space for a paragraph.</p>
</body>
</html>