Professional Documents
Culture Documents
Web Technologies Week 03-04 (CSS)
Web Technologies Week 03-04 (CSS)
Week 03-04
Introduction to CSS
02 What is CSS?
Recap of
Week
02-03
Prepared by Mian Muhammad Talha 3
Previous Week
• Styling Attributes
CSS
Prepared by Mian Muhammad Talha 8
Advantages of CSS
• Reusable Styling: Write CSS once, apply it across multiple HTML pages,
saving time and effort.
• Faster Page Loads: Use concise CSS rules instead of repetitive HTML
attributes for quicker download times.
• Effortless Updates: Modify a style globally, and all elements across web pages
automatically update.
• Enhanced Design: CSS offers a wider range of attributes, elevating the visual
appeal of HTML pages.
A CSS comprises of style rules that are interpreted by the browser and then
applied to the corresponding elements in your document. A style rule is
made of three parts −
Type Selector
This is the same selector we have h1 {
seen above. Again, one more example
to give a color to all level 1 headings color: #36CFFF;
− }
The Universal
*{ Selectors
Rather than selecting elements of a
specific type, the universal selector
color: #000000; quite simply matches the name of any
} element type −
Prepared by Mian Muhammad Talha 13
CSS Selectors
Type Selector
This is the same selector we have h1 {
seen above. Again, one more example
to give a color to all level 1 headings color: #36CFFF;
− }
The Universal
*{ Selectors
Rather than selecting elements of a
specific type, the universal selector
color: #000000; quite simply matches the name of any
} element type −
Prepared by Mian Muhammad Talha 14
HTML without CSS
ID Selector #intro {
The ID selector in CSS is used to
select and style a single unique font-size: 18px;
element on a web page. Each HTML color: blue;
element can have a unique ID font-weight: bold;
attribute, and the ID selector targets
that specific element to apply styling. }
h1#intro {
font-size: 18px; This rule renders the content for only
color: blue; <h1> elements with id attribute set to
intro.
}
Prepared by Mian Muhammad Talha 17
ID Selector
Class Selector
You can define style rules based on
the class attribute of the elements. All
the elements having that class will be .black {
formatted according to the defined color: #000000;
rule. }
Grouping
Selector
A grouping selector in CSS allows you to h1, h2, h3 {
apply the same styles to multiple color: #36C;
selectors at once, reducing redundancy font-weight: normal;
and making your CSS code more concise. letter-spacing: .4em;
This is particularly useful when you want margin-bottom: 1em;
several elements to share the same text-transform: lowercase;
styling rules.
}
Explore Selectors
There are some selectors such as
Descendent Selector, Child Selector,
Attribute Selector.
Explore these selectors, apply them in
your code and see how they can change
the appearance of your code.
• Inline CSS: You can use style attribute of any HTML element to
define style rules. These rules will be applied to that element only.
• This approach offers a balance between inline CSS and external CSS,
allowing you to apply styles to specific pages.
<style>
h1 ,h2, h3 {
color: #36C;
font-weight: normal;
text-transform: lowercase;
}
</style>
Prepared by Mian Muhammad Talha 30
External CSS
• You define all the Style rules within this text file and then you can
include this file in any HTML document using <link> element.
<head>
<link rel="stylesheet" href="Stylesheet.css" media=" all"
/>
</head>
• Or IDEs like
• Visual Studio Code
• Sublime Text
• Atom
• Adobe Dreamweaver
Stylesheet.css
Inline
Internal
External
Prepared by Mian Muhammad Talha 34
Famous CSS Concepts
• Many times, you may need to put additional comments in your style
sheet blocks. So, it is very easy to comment any part in style sheet.
We can arrange
our page in
different ways
using <div>
• Pseudo-classes let you style elements when users interact with them,
like hovering over a link or clicking a button.
flex-wrap: nowrap;
flex-wrap flex-wrap: wrap;
flex-wrap: wrap-reverse;
Prepared by Mian Muhammad Talha 44
Flex Container Property
Flex
Container Syntax Effect
Property
justify-content: flex-start;
justify-content: flex-end;
justify-content: center;
justify- justify-content: space
content between;
justify-content: space-
around;
justify-content: space-
evenly;