CSS Notes by Iron Coding
CSS Notes by Iron Coding
What is CSS?
CSS stands for Cascading Style Sheets
CSS describes how HTML elements are to be displayed on screen, paper, or in other
media
CSS saves a lot of work. It can control the layout of multiple web pages all at once
External stylesheets are stored in CSS files
CSS Syntax
External CSS
Internal CSS
Inline CSS
External CSS
An external style sheet is ideal when the style is applied to many pages. With an external style
sheet, you canchange the look of an entire Web site by changing one file. Each page must link
to the style sheet using the <link>tag. The <link> tag goes inside the head section:
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
Inline Styles
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.
CSS Selectors
CSS selectors are used to "find" (or select) the HTML elements you want to style.
PROPERTIES IN CSS
CSS Background Property
The CSS background properties are used to add background effects for elements.
div {
background-color: lightblue;
}
Color Systems
RGB color: rgb(255, 0, 0);
Hex color: #ff0000;
RGBA rgba(255, 99, 71, 0) last zero use for transparency
Color Systems
1. text-decoration: text-decoration: underline/overline/line-through
2. font-weight: font-weight : normal / bold / bolder / lighter OR font-weight : 100-900
3. font-family: font-family : arial
4. line-height: line-height : 2px OR line-height OR line-height : 3 line-height : normal
5. text-transform: text-transform : uppercase / lowercase / capitalize / none
div {
width: 320px;
height: 50px;
padding: 10px;
border: 5px solid gray;
margin: 0;
}
Display Property
The display property is used to specify how an element is shown on a web page.
Every HTML element has a default display value, depending on what type of element it is. The
default display value for most elements is block or inline.
The display property is used to change the default display behavior of HTML elements.
CSS Units
CSS has several different units for expressing a length.
Absolute Lengths
The absolute length units are fixed and a length expressed in any of these will appear as exactly that
size.
Unit Description
cm centimetersTry it
mm millimetersTry it
Unit Description
Position Property
The position property specifies the type of positioning method used for an element.
static - default position (The top, right, bottom, left, and z-index properties have no
effect)
relative - element is relative to itself. (The top, right, bottom, left, and z-index will work)
absolute - positioned relative to its closest positioned ancestor. (removed from the flow)
fixed - positioned relative to browser. (removed from flow)
sticky - positioned based on user's scroll position
z-index
It decides the stack level of elements
Background Image
Used to set an image as background
body {
background-image: url("paper.gif");
}
Background Size
background-size : cover / contain / auto
CSS Flexbox
The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure
without using float or positioning.
Flexbox Direction
It sets how flex items are placed in the flex container, along which axis and direction.
The following exapmle shows that when screen width will be 480px then body means webpage
background color changes to lightgreen.
The following example changes the background-color to lightgreen if the viewport is 480 pixels wide
or wider (if the viewport is less than 480 pixels, the background-color will be pink):
The following example shows a menu that will float to the left of the page if the viewport is 480
pixels wide or wider (if the viewport is less than 480 pixels, the menu will be on top of the content):
CSS Transitions
Transitions enable you to define the transition between two states of an element.
Transition Shorthand
CSS Animations
CSS allows animation of HTML elements without using JavaScript!
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
now we have to apply this keyframe in an element with some animation properties
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
}
Animation Properties
animation-name
animation-duration
animation-timing-function
animation-delay
animation-iteration-count animation-direction
Animation Shorthand