CSS Notes-1
CSS Notes-1
CSS
CSS stands for Cascading Style Sheet.
There are three ways in CSS to Style the Web pages
1. Inline CSS
2. Internal CSS
3. External CSS
1. Inline CSS: Inline CSS code is written in the opening tag of the HTML
element by using style attribute.
Syntax: <p style=" "> </p>
2. Internal CSS: Internal CSS code is written in the head section of an HTML
element using <style> tag.
Syntax: <head>
<style>
tag_name{
property: value;
}
<style>
</head>
3. External CSS: External CSS styling can be done by creating a external CSS
file with file_name.css extention and providing the link between that CSS
file to HTML file by <link> tag in the head section of HTML element.
Syntax: <head>
<link rel="stylesheet" href=" file_name.css">
</head>
JSP Trainer
SELECTOR
Selectors are used to select the particular HTML element and to style
them.
Simple Selectors
Simple Selectors
Simple selectors style the HTML element in five ways:
1. Id Selector.
2. Class Selector.
3. Tagname.
4. Groupname.
5. Universe.
Id selectors:
Id selector targets only individual element in the HTML
document.
Prefix symbol used for id selector is # (hash)
Example: #demo{
JSP Trainer
color: red;
background: yellow;
}
Class Selector
Class selector targets multiple elements in the HTML document.
Prefix symbol used for id selector is . (dot)
Example: .test{
color: red;
background: yellow;
}
Tagname Selector
Tagname selector targets the HTML elements by tag name.
There is no symbol used in tagname selectors.
Example: h1{
color: magenta;
background: green;
}
h2{
color: red;
background: black;
}
h3{
color: yellow;
background: orange;
}
Grouping Selector
Groupname selector targets a group of HTML elements.
Example: p, div, h4{
color: magenta;
JSP Trainer
background: green;
}
Universal Selector
Universal Selectors targets the un-targetted properties of every
HMTL element.
The symbol of Universal Selector is *
There is no selector is declared in css.
Example: *{
color: yellow;
background: magenta;
}
First Letter: The first letter styles the very first letter of the content in the
targeted HTML element.
Example: p : : first-letter{
font-size: 30px;
color: black;
}
JSP Trainer
First Line: The first line styles the very first line of the content in the targeted
HTML element.
Example: p : : first-line{
background-color: black;
color: white;
}
Before: The before pseudo element is used to place the specific content before
the targeted HTML element.
Example: p : : before{
content: “&phone”;
background-color: black;
color: white;
}
After: The after pseudo element is used to place the specific content after the
targeted HTML element.
Example: p : : after{
content: “Thank You”;
color: blue;
}
Selection: The selection pseudo element is used to style the content when the
cursor is dragged on the content (when the content is selected) on the targeted
HTML element.
Also copying the text content from the user can also be disabled, by using the
property user-select: none.
Example: p : : selection{
background-color: pink;
color: magenta;
}
Marker: Marker pseudo element is used to style the lists in the HTML
document.
Marker is only used to style the list type not the content.
Declaration of selector is not mandatory here.
Background color will not work for Marker.
JSP Trainer
Example: li : : marker{
color: red;
font-size: 30px;
}
(or)
: : marker{
color: red;
font-size: 30px;
}
Pseudo Classes
Link
Visited
Hover
Active
Focus
o Each dynamic pseudo class selector is declared with the single colon :
o Link, Visited only applicable for anchor tag.
o Link is used to style the unvisited link
o Link doesn’t style the already visited link.
o Active applies the style at the time of click event.
o Hover is applicable for all the HTML elements.
o While using all the Link, Visited, Hover and Active selectors. Hover should be
declared after Link and Visited. Along with that the Active should be declared
after Hover, because to make the elements effective.
Example:
a : link {
color: aqua;
background-color : red;
}
a : visited {
JSP Trainer
color : green;
}
a : hover {
color : yellow;
}
a : active {
color : chocolate;
}
a : focus {
color : magenta;
}
BOX Model
Box Model is essentially a box that wraps around every HTML
element. Box Model is used to design and layout.
The CSS Box Model consists of Margin, Border, Padding and the actual Content.
Content: It is the content of the HTML element.
Padding: It is the space after the content.
Border: It is the Border of the HTML element.
Margin: It is the space after the Border of an HTML element.
Padding and Margin allow up to four values.
Text Properties
JSP Trainer
text-align- Horizontal alignment of the text (here we have right, left, center,
justify).
Example- text-align: center;
background-origin: content-box;
CSS GRADIENTS
CSS defines three types of gradients:
Linear Gradients
background-image: linear-gradient(direction, color1, color2, ...);
direction: to top, to bottom, to left, to right,
and in degree:
0deg ->to top
90deg ->to right
180deg ->to bottom
270deg ->to left
Repeating a linear-gradient
The repeating-linear-gradient()
background-image: repeating-linear-gradient(red, yellow 10%, green 20%);
Radial Gradient
background-image: radial-gradient(shape, start-color, ..., last-color);
background-image: radial-gradient(circle, red, yellow, green);
shape:circle, ellipse.
background-image: radial-gradient(closest-side at 10% 15%, red, yellow, black);
JSP Trainer
Repeating a radial-gradient
The repeating-radial-gradient() function is used to repeat radial gradients:
background-image: repeating-radial-gradient(red, yellow 10%, green 15%);
Position Properties
position:relative;
position:absolute;
position:fixed;
position:sticky;
position:static; (Default value)
Display Properties
display:flex;
display:block;
display:inline;
display:inline-block;
display:none
Flex
The Flexible Box Layout Module, makes it easier to design flexible responsive layout
structure without using float or positioning.
A Flexible Layout must have a parent element with the display property set to flex.
Ex: div {
display: flex;
}
flex-direction
flex-wrap
justify-content
align-items
Transition Properties
Transform Properties