Unit 2 CSS_PPT
Unit 2 CSS_PPT
(CSS)
UNIT 2
Cascading Style Sheets:
1. Introduction; Cascading Style Sheets (CSS); 11. CSS Box Model
2. CSS Syntax 12. Normal Flow Box Layout: Basic Box Layout,
3. Inserting CSS: Inline, Internal, External, 13. Display Property
4. ID and Class Selectors 14. Padding
5. Colors; 15. Margin
6. Backgrounds 16. Positioning: Relative, Float, Absolute
7. Borders 17. CSS3 Borders
8. Text; 18. Box Shadows
9. Font 19. Text Effects and shadow
10. List 20. Basics of Responsive Web Designs
11. Table 21. Media Queries
22. Introduction to Bootstrap
Introduction: CSS
• CSS is the language we use to style a Web page.
• CSS stands for Cascading Style Sheets.
• CSS describes how HTML elements are to be displayed on
screen, paper, or in other media.
• CSS saves a lot of work. It can control the layout of multiple
web pages all at once.
• External stylesheets are stored in CSS files.
One HTML Page - Multiple Styles!
One HTML Page - Multiple Styles!
One HTML Page - Multiple Styles!
One HTML Page - Multiple Styles!
One HTML Page - Multiple Styles!
CSS Syntax
• A CSS rule consists of a selector and a declaration block.
Internal styles are defined within the <style> element, inside the <head> section of an HTML page
External CSS
• With an external style sheet, you can change the look of an entire
website by changing just one file!
• Each HTML page must include a reference to the external style sheet
file inside the <link> element, inside the head section.
Example: External styles are defined within the <link> element, inside
the <head> section of an HTML page: • An external style sheet can be written in any text
editor, and must be saved with a .css extension.
• The external .css file should not contain any HTML
tags.
• Here is how the "mystyle.css" file looks:
External CSS
Cascading Order
• What style will be used when there is more than one style specified
for an HTML element?
• All the styles in a page will "cascade" into a new "virtual" style sheet
by the following rules, where number one has the highest priority:
1. Inline style (inside an HTML element)
2. External and internal style sheets (in the head section)
3. Browser default
• So, an inline style has the highest priority, and will override external
and internal styles and browser defaults.
CSS Selectors
• A CSS selector selects the HTML element(s) you want to style.
• CSS selectors are used to "find" (or select) the HTML elements you
want to style.
• CSS selectors are patterns used to specify which elements in a web
page to style.
• They are used to target specific HTML elements based on their
attributes, relationships, or other criteria.
ID and Class Selectors
• ID and Class selectors are the most widely used element
selectors in CSS (HTML).
• The basic difference between ID and Class is that the ID
selector is applied only to one element in a page, whereas
the class selector can be applied to several elements on a
single page.
ID Selectors
• The id selector uses the id attribute of an HTML element to select a
specific element.
• The id of an element is unique within a page, so the id selector is used
to select one unique element!
• To select an element with a specific id, write a hash (#) character,
followed by the id of the element.
ID Selectors
Example: The CSS rule below will be applied to the HTML element with
id="para1“.
ID and Class Selectors
Example of ID Selector
ID and Class Selectors
What is CLASS in HTML?
• In HTML, the "class" selector is used to select an element
with a specific class attribute.
• The class selector starts with a period (.) followed by a class
name. Unlike the id selector, we can attach multiple selector
to an HTML element. Therefore, the class can be applied
many time within a page.
• The important point to note about the class selector is that
the class name must not be started with a number.
ID and Class Selectors
• The class selector selects HTML elements with a specific class
attribute.
• To select elements with a specific class, write a period (.) character,
followed by the class name.
ID and Class Selectors
Key Id Class
In HTML, for an element, the ID
"class" assigned to an element
name starts with the "#" symbol
Syntax has its name starts with "."
followed by a unique name
followed by class name.
assigned to it.
Only one ID selector can be Multiple class selectors can be
Selector
attached to an element. attached to an element.
The class can be applied to
ID is unique in a page and can only
Uniqueness multiple elements so it could be
apply to at most one element
multiple times on a single page.
Colors
Colors
• Colors are specified using predefined color names, or RGB, HEX, HSL,
RGBA, HSLA values.
• CSS uses color values to specify a color.
• Typically, these are used to set a color either for the foreground of an
element (i.e. its text) or else for the background of the element.
• They can also be used to affect the color of borders and other
decorative effects.
Colors;
• CSS Color Names
In CSS, a color can be specified by using a predefined color name:
Colors;
Colors;
Named Colors: A CSS named color is the name of a color, such as red, blue,
black, or lightseagreen.
color: blue;
border: 1px solid red;
background: aliceblue;
Positioning: Relative
The CSS position: relative property positions the elements relative to
their original position in the page. You can use the left, right, top, and
bottom properties to move the element around, but it will still take up
space in the document flow.
Positioning: Fixed
To make an element stay in the same place on the screen even when the
user scrolls, you can set the position property to fixed. You can then use
the left, right, top, and bottom properties to position the element where
you want it.
Positioning: Absolute
An element with position: absolute is taken out of the document flow
and positioned relative to its nearest positioned ancestor (if any). If there
is no positioned ancestor, then the element is positioned relative to the
viewport.
You can use top, right, bottom, and left properties to specify the position
of the element relative to its containing block.
Positioning: Sticky
You can set the position property to sticky to create an element that
sticks to the top of the viewport when the user scrolls through a page.
The position: sticky property is a combination of the position: relative
and position: fixed properties