Front end Web Technologies_CSS
Front end Web Technologies_CSS
CSS
Selector: An HTML tag is a selector that uses a style. This might be a tag such as <h1> or
<table> etc.
Property: An attribute type of a HTML tag is a property. All of the HTML attributes are
simply converted into CSS. It might be color, border etc.
Value: Properties are allocated values, such as a color property with either a red or
#F1F1F1, etc. value.
CSS Selector
● CSS selectors are used to select the content you want to style.
Selectors are the part of CSS rule set.
● CSS selectors select HTML elements according to its id, class, type,
attribute etc.
● There are several different types of selectors in CSS.
1. Element Selector
2. Id Selector
3. Class Selector
4. Universal Selector
5. Group Selector
Element Selector
The element selector selects the HTML element by name.
Example:
p{
text-align: center;
color: blue;
}
Element Selector Example
<head>
<style type="text/css">
img {
border : solid blue;
}
</style>
</head>
<body>
<img src="diary.jpg" alt="Nature flower">
</body>
ID Selector
● The id selector selects the id attribute of an HTML element
to select a specific element.
● An id is always unique within the page so it is chosen to
select a single, unique element.
● It is written with the hash character (#), followed by the id
of the element.
Note: Do not start an ID name with a number. Because It
will not work in Mozilla/Firefox browser.
ID Selector Example
<head>
<style>
#para1 {
text-align: center;
color: blue;
}
</style>
</head>
<body>
<p id="para1">Hello !!</p>
</body>
Class Selector
● The class selector selects HTML elements with a specific
class attribute.
● It is used with a dot sign ( . ) followed by the class name.
Example:
Universal Selector Example
<style>
*{
color: green;
font-size: 20px;
}
</style>
</head>
<body>
<h2>This is heading</h2>
<p>Universal selector demo</p>
<p> hello!</p>
<p> how are you!</p>
Group Selector
The group selector is used to select all the elements with the
same style definitions.
Group selector is used to minimize the code.
Commas are used to separate each selector in grouping.
Group Selector Example
h1 {
text-align: center;
color: blue;
} h1,h2,p {
h2 {
text-align: center; text-align: center;
color: blue;
color: blue;
}
p{ }
text-align: center;
color: blue;
}
Types of CSS
There are three ways you can use to implement CSS into your
HTML:
Inline CSS
Inline CSS is generally used to style a specific HTML element
only. We can write inline CSS simply by adding the style
attribute to each HTML element.
Example:
<h1 style="background-color:yellow"> This is a heading </h1>
<p style="color:red"> This is some paragraph </p>
Inline CSS Example
<html>
<body style="background-color: lightblue">
<p style="color: red; margin-left: 20px"> This is a paragraph </p>
<br>
<p style="color: green">This is another paragraph </p>
</body>
</html>
Internal CSS
● Internal CSS requires
you to add <style> tag
in the <head> section of
your HTML document.
● It is an effective method
of styling a single page.
● However, using this
style for multiple pages
is time-consuming.
Internal CSS Example
<head>
<style type="text/css">
h3 { color: blue }
p { color: red; margin-left: 20px }
body { background-color: lightblue }
</style>
</head>
<body>
<h3>This is a heading</h3>
<hr>
<p>This is a paragraph</p>
</body>
External CSS
● With external CSS, you’ll link your web pages to an external
.css file, which can be created by any text editor in your device
(e.g., Notepad++ or VS Code).
● This is a more efficient method, especially for styling a large
website.
● By editing one .css file, you can change entire website at once.
● It uses the <link> tag on every pages and the <link> tag should
be put inside the head section.
External CSS Example
<head>
<link rel="stylesheet" src="style.css" type="text/css">
</head>
Output:
CSS inheritance
Some properties are inherited and some are not.
html file css file Output:
css file
html file
Output
CSS inheritance
If we want our child class to inherit all properties of the parent class,
use inherit value. See following example:
css file
html file
Output
CSS Background
● The background-color property specifies the background color
of an element.
● The background-image property specifies an image to use as
the background of an element.
● By default, the background-image property repeats an image
both horizontally and vertically:
○ To repeat an image horizontally, set
background-repeat: repeat-x;
○ To repeat an image vertically, set
background-repeat: repeat-y;
CSS Background
CSS Background
CSS Background
CSS Background
By default, the background-image property repeats an image both
horizontally and vertically.
Some images should be repeated only horizontally or vertically
CSS Background
If the image above is repeated only horizontally
(background-repeat: repeat-x;)
https://www.w3schools.com/css/css3_transitions.asp
CSS Transition
The :hover selector is used to
select elements when you
mouse over them.
https://www.w3schools.com/css/tryi
t.asp?filename=trycss3_transition2
CSS Display Property
The display property defines how an element is rendered in the
layout, determining its positioning and interaction within the
document’s flow and structure.
It takes many different values such as:
● display: none
● display: inline
● display: block
● display: inline-block
● display: flex
<head> <body>
<style> <h2>Before display: inline</h2>
div { <div>First div element.</div>
border: 2px solid blue; <div>Second div element.</div>
margin-bottom: 10px; <h2>After display:inline</h2>
padding: 2px; <div class="after">First div element.</div>
} <div class="after">Second div element.</div>
div.after { </body>
display: inline;
}
</style>
</head>
<head> <body>
<style> <h2>Before display: block</h2>
span { <span>First span element.</span>
border: 2px solid blue; <span>Second span element.</span>
margin-bottom: 10px; <h2>After display: block</h2>
padding: 2px; <span class="after">First span element.</span>
<span class="after">Second span element.</span>
}
</body>
span.after {
display: block;
}
</style>
</head>
<head> <body>
<style>
span { <h2>Display:inline-block</h2>
padding: 10px;
margin: 20px; <p>In this paragraph,<span>SPAN</span>
border: 2px solid black; element is in green-yellow color.</p>
background-color:
greenyellow; </body>
}
span.after {
display: inline-block;
}
</style>
</head>
<head> <body>
<style> <h1>The display Property</h1>
ul.parent { <ul class="parent">
display: flex; <li>Home</li>
background-color: plum; <li>About</li>
padding: 0px; <li>Gallery</li>
} <li>Blogs</li>
li { <li>Contact</li>
background: skyblue; </ul>
padding: 12px; </body>
margin: 8px;
list-style: none;
}
</style>
</head>
CSS Animation
● CSS allows animation of HTML elements without using
JavaScript or Flash!
● It lets an element gradually change from one style to
another.
● CSS animations are made up of two basic building blocks.
1. Keyframes - define the stages and styles of the
animation.
2. Animation Properties - assign the @keyframes to a
specific CSS element and define how it is animated.
CSS Animation - The keyframe rule
When you specify CSS styles
inside the @keyframes rule,
the animation will gradually
change from the current style
to the new style.
Note: If animation-duration
property is not specified, no
animation will occur, because
the default value is 0s (0
seconds).
https://www.w3schools.com/css/tryit.asp?filename=trycss3_animation1
CSS Animation - The keyframe rule
https://www.w3schools.com/css/tryit.asp?file
name=trycss3_animation2
CSS Animation - The keyframe rule
https://www.w3schools
.com/css/tryit.asp?filen
ame=trycss3_animatio
n3
CSS 2D transform
With the CSS transform property you can use the following 2D
transformation methods:
● translate()
● rotate()
● scale(), scaleX(), scaleY()
● skew(), skewX(), skewY()
● matrix()
CSS 2D transform
The translate() method: