Professional Documents
Culture Documents
Cascading Styling Sheets
Cascading Styling Sheets
1
• CSS stands for cascading styling sheets, it’s allows us to describe the styling of HTML
document.
• For example, we can control the coloring and layouts of HTML elements.
• With CSS you can describe the presentation of a web page via things like color, layout,
and font. Adjusting to different types of devices and screen sizes is also handled by CSS.
• By separating CSS from HTML, it makes it easier to maintain a website. This way you
can share a style sheet across pages, or adjust it to different environments.
2
CSS HTML
3
?
?
?
?
Why is CSS
important?
?
?
?
4
Freedom to position HTML Endless customization
elements anywhere options
CSS preprocessors
. . Using a CSS preprocessor, a
on a web page, while allowing to a web page including fonts,
developer is able to write out
you to keep your markup colors, borders, hover and
(HTML) clean and organized. transition effects, etc. more complex style and layout.
The source code can be shorter
and more readable. use tools
such variables.
5
Change Your life
learn Code
6
CSS for
Mobile apps
7
MAKING MOBILE APPS WITH HTML
AND CSS
Yes, there are many mobile apps development frameworks that use HTML and CSS
to make mobile applications.
Technically speaking, mobile apps in Android, iOS
8
WHAT WE WILL
LEARN
we will cover the essential / basic CSS concepts you need to understand to
build beautiful web pages.
9
How to use CSS Testing our CSS web CSS selectors
pages
10
PROJECTS
WE WILL USE OUR ALL CSS TO MAKE PROJECT
11
</ > </>
</ >
{}
?
How to add CSS to your
<>
HTML file.
<> <>
{} {}
12
The three different ways to providing CSS, there are three methods of including CSS in an HTML
document.
1. Embedded styles — We can use Embedded stylesheets - so we include our styles in our HTML documents, Using
the <style> element in the head section of a document.
2. External style sheets — we can also use external CSS file - External stylesheets which means make our styles in
separate files. this has couple benefits. Using the <link> element, pointing to an external CSS file.
3. Inline styles — we can apply our styles directly to our particular HTML elements Using the style attribute in the
HTML start tag. inline style used to apply a style for a single element.
13
Internal stylesheet has two problems
A First problems is that they not scalable, so if we have multiple pages, we want our
paragraph to be orange with this approach we have to copy all the styles that we have here
and put them in to every single web page.
The Second problems with this approach is that we have every import concept in computer
science called (Separation of Concerns), So we have different modules for different
concerns.
As we leaned (HTML & CSS) we use HTML to structure web pages and we use CSS to style
them. These are two different concerns, so we should separate them.
14
Thinking of supermarkets in supermarket we have
different section with different types of products,
we have section for food, another section for
cleaning products, and imagine if we have
supermarket with only single section all the
products in the single section, we could not find
anything in that supermarket.
15
External styles sheet
So create a new file called (styles.css), we can call anything the name doesn’t matter.
<link rel="stylesheet" href="" />
(rel) relation which determines the type of resource we are linking this document to in this case
(stylesheet).
(href) here we type relative or absolute URL. here we can type (style.css)
So these are two different ways provide styles, but they is third way we can use (Inline styles)
to apply styles to particular HTML elements.
16
Inline styles Example
inline style used to apply a style for a single element.
I want make first paragraph (blue) but only the first paragraph, every HTML element has style attribute
and this where we can write one or more styles. So we can set the color to blue and add (;) semicolon
so we can type second CSS property, so we can say font-weight to bold. Don’t worry about this we
will talk it.
<p style="color: blue; font-weight: bold">Lorem ipsum dolor sit amet.</p>
17
CSS Syntax
A CSS rule have two main parts, a selector and
declarations.
18
Basic Selectors
19
Selectors are one of the most important aspects of CSS as they allow you to target
specific elements on your web page in various ways that we want to style them.
In CSS we have few different ways to select elements or styling proposes. We can select by
(Type, ID, Class, Attributes).
Universal Selector ( * )
The universal selector, select every single element on the page.
/* Selects all elements */
* {
color: green;
}
20
A type selector matches a HTML element directly. selects HTML elements based on the
element name.
21
ID selector
The id selector is used to define style rules for a single or unique element.
The id selector is defined with a hash sign (#)
<body>
<section id="product</section>
</body>
#products{
}
22
Class selector (.)
The class selectors can be used to select any HTML element that has a class attribute. All the
elements having that class will be formatted according to the defined rule .
<body>
<section id="products">
<article class="product"></article>
<article class="product"></article>
<article class="product"></article>
</section>
</body>
.product{
}
23
Example
Any styling information that needs to be applied to multiple objects on a page
should be done with a class. Take for example a page with multiple “button”:
<body>
<div class=“button"></div>
<div class="button"></div>
<div class="button"></div>
</body>
24
?
?
?
?
What is different between ID
and CLASS?
?
?
?
25
ID selectors are the most specific selector, because we can’t have multiple
elements with the same ID.
your code will not pass validation if you use the same ID on more than
one element. Validation should be important to all of us, so that alone is a
big one.
Class selectors are less specific because we can have many elements with
the same class.
26
ID’s and Classes
Information that is reusable should be kept in a class
and information that is totally unique should be kept
in an ID.
27
CSS Colors
28
In CSS we have different ways to present colors, We can use (Color Names,
RGB Value, HEX codes)
1. RGB Let’s look up the (RGB) first (Red Green Blue) these three value present the
degree of Red Green and Blue colors
• Each value can be number between 0-255
• So we use rgb() function to set the background color
.box{
width: 200px;
height: 200px;
background-color: grb(230,205,15);
}
29
RGBA We have another function which is called rgba() which is stand for alpha (Red-green-
blue-alpha)
.box{
width: 200px;
height: 200px;
background-color: grba(230,205,15,0.5);
}
30
HEX we can also use hexadecimal to represent colors, Hexadecimal is one of
the numerical systems, we have
Binary systems (0,1)
We have binary system that contain the digit 0 and 1
Decimal (0-9)
We have Decimal system that contain the digit 0 to 9
Hexadecimal (0-9, a-f)
Hexadecimal is another system that contain (0-9) and letters (a-f)
.box{
width: 200px;
height: 200px;
background-color: #e6cd10;
}
31
Color Name We can also use by name our colors
.box{
width: 200px;
height: 200px;
background-color: orange;
}
32
Comments are used to explain your code, and may help you when you edit the
source code at a later date. Comments are ignored by browsers.
A CSS comment begins with "/*", and ends with "*/", like this:
/*This is a comment*/
33
Comments are used to explain your code, and may help you when you edit the
source code at a later date. Comments are ignored by browsers.
A CSS comment begins with "/*", and ends with "*/", like this:
/*This is a comment*/
Font Color
The color property defines the text color of an element.
color: #ff5722;
Font Size
The font-size property is used to set the size of font for the text content of an element.
font-size: 24px;
34
Width and Height
The width and height property defines the width and height of the content
area of an element.
div{
width: 600px;
background-color: dodgerblue;
}
div{
width: 600px;
height: 458px;
background-color: dodgerblue;
}
35
Day in the Life of a Software Engineer in Australi
a
Gradients
37
Gradients
We have learned about Colors, now let’s talk about Gradients,
With Gradients we can create beautiful transitions between two or more
colors.
To set the gradients we use linear-gradient() function, here We use two colors
(dodgerblue, yellow).
div{
width: 600px;
height: 458px;
background: linear-gradient(tomato, deeppink);
}
38
Direction
We can also change the direction of gradient
Direction - to Right
shows a linear gradient that starts from the left. It starts red, transitioning to
yellow.
div{
width: 600px;
height: 458px;
background: linear-gradient(tomato, deeppink);
}
Direction - to left
39
Direction – to top to left to bottom
now the transitions start from top left and goes to bottom right.
Using degree
41
Styling list
42
CSS provides the several properties for styling and formatting the most commonly
used unordered and ordered lists.
<ul> ul{
<li>item one</li>
<li>two</li> list-style-type:square;
<li>three</li> }
</ul>
<ol> ol{
<li>item one</li> list-style-type:upper-alpha;
<li>two</li>
<li>three</li> }
</ol>
43
Changing the Position of List Markers
By default, markers of each list items are positioned outside of their display boxes.
ul{
list-style-type:square;
list-style-position: inside;
}
ul{
list-style: square inside url(tick.svg);
}
44
Border
45
Now let’s talk about Borders, this property takes three values, the first value border size (10px) and the second value is the
style of the border (solid), the third value is to set the border color (dodblue)
div{
width: 300px;
height: 208px;
border: 5px solid dodgerblue;
}
div{
width: 300px;
height: 208px;
border: 5px dotted dodgerblue;
}
46
Border radius (border-radius) is use to make border rounded styles.
div{
width: 300px;
height: 208px;
border: 5px solid dodgerblue;
border-radius: 20px;
}
47
If we want to make circle, so we set value (100% or 50%)
div{
width: 200px;
height: 200px;
border: 5px solid dodgerblue;
border-radius: 100%;
}
CSS Border Width The border-width property specifies the width of the four borders.
border-width: 12px 3px ; trbl
48
CSS Table
49
Tables are typically used to display tabular data, such as financial reposts.
When you create an HTML TABLE without any styles or attributes, browsers display them without any
border.
With CSS we can control the layout of the table elements.
table,th, td{
border: 1px solid black;
}
Width Table
table{
width: 50%;
}
50
Collapsing Table Borders
separate border model, which is the default, You can set the border model for an HTML table by using
the CSS border-collapse property.
table{
width: 50%;
border-collapse: collapse;
}
th{
height: 30px;
}
51
Aligning the Text Inside Table Cells
You can align text content inside the table cells either horizontally or vertically.
For horizontal alignment of text inside the table cells you can use the text-align property
th{
height: 30px;
text-align: center;
}
table,th, td{
border: 1px solid black;
height: 30px;
vertical-align: bottom;
}
52
CSS Styling Table
Horizontal Dividers
Add the border-bottom property to <th> and <td> for horizontal dividers:
table {
border-collapse: collapse;
width:70%;
}
th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
53
Creating Zebra-striped Tables
Setting different background colors for alternate rows is a popular technique to improve the
readability of tables that has large amount of data.
For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd)
table rows:
tr:nth-child(even){
background-color: #dddddd;
}
54
Responsive Table
A responsive table will display a horizontal scroll bar if the screen is too small to display the full content:
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
table {
border-collapse: collapse;
width: 100%;
}
th,
td {
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #f2f2f2;
} 55
Shadows
56
In CSS we can easily add shadows around elements by using the (box-shadow)
property .
- the first value is horizontal destines of the shadow to the element, if we use
positive value (10px) this will move shadow to the right, and if we use negative
value (-10x) this will move the shadow to the left .
- the second value is vertical destines of the shadow to the element, if we use
positive value (10px) this will move the shadow to the bottom, and if we use the
negative value (-10px) this will move the shadow to the top.
.box{
width:200px;
height: 200px;
background-color: rgb(48, 92, 137);
box-shadow: 15px 10px;
}
57
We can change the color
.box{
width:200px;
height: 200px;
background-color: #305c89;
box-shadow: 15px 10px wheat;
}
Now what if we want to make this shadow a little bit softer, so here we can add a third value.
.box{ .box{
width:200px; width:200px;
height: 200px; height: 200px;
background-color: #305c89; background-color: #305c89;
box-shadow: 15px 10px 20px wheat; box-shadow: 0px 0px 20px wheat;
} }
Online tools
https://getcssscan.com/css-box-shadow-examples
https://box-shadow.dev/
https://box-shadow.art/inspiration/
58
Text Shadows
For text show we use the same property that we used in box-shadow
h1{
color: white;
text-shadow: 3px 3px 5px gray;
}
More clear
h1{
color: white;
text-shadow: 3px 3px 5px rgba(0, 0, 0, 0.2);
}
59
Assignments
60
61
62
63
64
65
66
67
68
69
70
Inheritance
71
Inheritance
One of the importance concepts in CSS is Inheritance, we need to understand. Some CSS properties by default inherit
values from their Parents,
For example (we make a paragraph with some text, now add some text in <Storge> elements)
CSS properties such as height , width , border , margin , padding , etc. are not inherited
<p>
Lorem ipsum dolor, sit amet <strong>consectetur</strong>
adipisicing elit.
Distinctio, quibusdam.
</p>
p{
color: dodgerblue;
border: 1px solid black;
}
Now if we look the our <strong> is all so blue even though our, we didn’t apply the color to <strong> element,
this is inheritance in action. The <strong> element is the child of <p> element
72
- If we want to stop the inheritance so we use, we set the value to initial. This set the color property to it’s
default value
strong{
color: initial;
}
- Now let’s look the property that does not inherit, If we add the border to our paragraph,
p{
color: dodgerblue;
border: 1px solid black;
}
strong {
color: initial;
border: inherit;
}
73
Advance CSS
selector
74
Inheritance
One of the importance concepts in CSS is Inheritance, we need to understand.
For example (we make a paragraph with some text, now add some text in <Storge> elements)
<p>
Lorem ipsum dolor, sit amet <strong>consectetur</strong>
adipisicing elit.
Distinctio, quibusdam.
</p>
p{
color: dodgerblue;
border: 1px solid black;
}
Now if we look the our <strong> is all so blue even though our, we didn’t apply the color to <strong> element,
this is inheritance in action. The <strong> element is the child of <p> element
75