Notes On Css Flexbox and Positions
Notes On Css Flexbox and Positions
Study Material
(Responsive Web Design , BAM27202(T))
_____________________________________________________________________________________________
Table of Contents
Topic Page No
CSS Flexbox 1
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 1
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
Introduction to Flexbox
Flexbox, short for “Flexible Box Layout,” is a CSS3 layout model that provides a more
efficient way to design, align, and distribute space among elements within a container.
It is particularly useful for building responsive layouts, where items need to adjust or
wrap based on screen size.
Before Flexbox, web developers relied on floats and inline-block techniques, which
made vertical alignment and dynamic spacing difficult. Flexbox addresses these issues
by offering flexibility and better control.
● Main Axis: The primary axis along which items are laid out. It changes based on
flex-direction.
● Cross Axis: The axis perpendicular to the main axis.
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 2
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
Flex Container Properties
A flex container is any element with display: flex; or display: inline-flex;. Its
children automatically become flex items.
● display
.container {
display: flex;
● flex-direction
Defines the direction in which items are placed in the container.
● justify-content
Aligns items horizontally along the main axis.
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 3
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
justify-content: flex-start | flex-end | center | space-between | space-around |
space-evenly;
● align-items
Aligns items vertically on the cross axis.
● align-content
Used when there are multiple rows. Aligns entire row blocks.
● flex-wrap
Determines whether flex items wrap to the next line or stay in a single line.
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 4
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
● gap
Defines spacing between items in the flex container.
gap: 20px;
● flex-grow
Specifies how much the item will grow relative to other items.
.item { flex-grow: 1; }
● flex-shrink
Specifies how much the item will shrink if space is limited
.item { flex-shrink: 1; }
● flex-basis
Initial size of an item before space distribution.
● align-self
Overrides align-items for an individual flex item.
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 5
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 6
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
CSS POSITIONING
CSS Positioning is used to control how and where elements appear on a webpage.
Using the position property, you can shift elements away from their normal place in
the document flow to a new specified location.
Types of Positioning
position: static;
2.relative
.element {
position: relative;
top: 10px;
left: 20px;
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 7
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
● The element stays in the normal document flow.
● It moves relative to its original position.
3. absolute
.element {
position: absolute;
top: 0;
left: 0;
4. fixed
.element {
position: fixed;
bottom: 0;
right: 0;
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 8
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
5.sticky
.element {
position: sticky;
top: 0;
● Acts like relative until a threshold is reached, then sticks like fixed.
● Used for "sticky" section headers that stay in view while scrolling.
Offset Properties
Used with relative, absolute, fixed, and sticky
.element {
z-index: 10;
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 9
BACHELOR OF SCIENCE (HONOURS) IN ANIMATION & MULTIMEDIA – 2024 / 2nd Sem
BAM27202(T) - Responsive Web Design
Section - A/B/C
2024-25
Common Use Cases
Position Use Case Example
relative Nudging elements slightly
Ayan Chatterjee
Dept: Multimedia
Brainware University, Kolkata 10