CSS Notes
CSS Notes
What is css
CSS stands for Cascading Style Sheets CSS is the language we use to style an
HTML document. CSS describes how HTML elements should be displayed.
2. Css syntax
Selector {
Propetiy : value ;
}
Exa.
p{
color: red;
text-align: center;
}
External CSS
Internal CSS
Inline CSS
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.
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
In "mystyle.css" file
h1 {
color: navy;
}
Internal CSS
An internal style sheet may be used if one single HTML page has a unique style.
The internal style is defined inside the <style> element, inside the head section
<html>
<head>
<style>
h1 {
color: maroon;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
</body>
</html>
Inline CSS
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style attribute
can contain any CSS property.
<body>
<h1 style="color:blue ; text-align:center;">
This is heading
</h1>
</body>
Type of selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
a) Element selector
b) Id selector
c) Class selector
d) Universal selector
element Selector
The element selector selects HTML elements based on the element name.
In html file,
p{
text-align: center;
color: red;
}
CSS id Selector
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.
In html file,
In css file,
#para2 {
text-align: center;
color: red;
}
The CSS class Selector
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.
In css file,
.center {
text-align: center;
color: red;
The universal selector (*) selects all HTML elements on the page.
*{
text-align: center;
color: blue;
}
font-family
p{
font-family: "Times New Roman", Times, serif;
}
font style
p{
font-style: normal;
}
Font Size
p{
font-size: 40px;
}
font-weight
p{
font-weight: normal/bold;
}
4. Css text properties with example
a. Text Color
Specifies the color of text
h1 {
color: green;
}
b. Text Alignment
The text-align property is used to set the horizontal alignment of a text.
h1 {
text-align: center/left/right;
}
c. Text Decoration
The text-decoration-line property is used to add a decoration line to
text.
h1 {
text-decoration-line: overline/line-through/underline;
}
d. Text Transformation
The text-transform property is used to specify uppercase and
lowercase letters in a text.
p{
text-transform: uppercase/lowercase/capitalize;
}
e. Text spacing
p{
letter-spacing: 5px;
line-height: 0.8;
word-spacing: 10px;
}
f. Text shodow
In its simplest use, you only specify the horizontal shadow (2px) and the vertical
shadow (2px):
h1 {
text-shadow: 2px 2px;
}
The CSS box model is essentially a box that wraps around every HTML element.
It consists of: borders, padding, margins, and the actual content.
Content - The content of the box, where text and images appear
p{
width: 300px;
border: 15px solid green;
padding: 50px;
margin: 20px;
}
With the CSS border-radius property, you can give any element "rounded corners"
In html file,
7. CSS Transitions
CSS transitions allows you to change property values smoothly, over a given duration.
It contain 3 properties
transition-delay
transition-duration
transition-timing-function
p
{
transition: width .35s ease-in-out;
}