Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

@ValluruSarath

Responsive web design


Responsive web design is an
approach to designing and coding
websites to ensure they work
seamlessly across a variety of devices
and screen sizes. The goal is to create
a user-friendly experience regardless
of whether the website is viewed on a
desktop, tablet, or smartphone.

1. Viewport Meta Tag


2. Fluid Layouts with Percentage
Width
3. Media Queries
4. Flexible Images and Media
5. Mobile-First Design

@ValluruSarath
Responsive web design

@ValluruSarath
Media queries
Media queries in CSS are used to
apply different styles based on
various characteristics of the user's
device, such as screen width, height,
resolution, and more. They play a
crucial role in creating responsive
designs, allowing web pages to adapt
and provide an optimal viewing
experience across different devices
and screen sizes.

@ValluruSarath
Media queries

@ValluruSarath
Flexbox and Grid Layout
Flexbox and Grid Layout are layout models in
CSS that provide powerful tools for creating
complex and responsive layouts. While they
share some similarities, they have distinct
purposes and use cases.
Flexbox:
1. Single-Dimensional Layout:
Primarily designed for laying out items in
a single dimension (either in a row or a
column).
Useful for creating flexible and dynamic
layouts within a container.
2. Main Axis and Cross Axis:
Items can be aligned both along the
main axis and the cross axis.
Perfect for aligning items horizontally or
vertically within a container.
@ValluruSarath
Flexbox and Grid Layout
3. Flex Container and Flex Items:
The container with display: flex becomes
a flex container, and the children become
flex items.
Allows for easy distribution of available
space among items using properties like
flex-grow and flex-shrink.
4. Ideal for Components:
Great for organizing components within a
container, especially when the number of
items may vary.

Grid Layout:
1. Two-Dimensional Layout:
Designed for creating grid-based layouts in
two dimensions (both rows and columns).

@ValluruSarath
Flexbox and Grid Layout
Offers more control over rows and columns
and their alignment.

2. Grid Container and Grid Items:


The container with display: grid becomes
a grid container, and its children become
grid items.
Enables precise control over the
placement of items in both rows and
columns.
3. Alignment and Distribution:
Provides extensive control over the
alignment and distribution of items in
both axes using properties like justify-
content, align-items, etc.

@ValluruSarath
Flexbox and Grid Layout
4. Ideal for Overall Page Layout:
Best suited for defining the overall structure
of a page or large sections of a page.
Useful when you need to create a complex
layout with specific column and row
structures.

When to Choose One Over the Other:


Choose Flexbox When:
Dealing with one-dimensional layouts, like
aligning items in a row or column.
Creating flexible and dynamic components
within a container.

@ValluruSarath
Flexbox and Grid Layout
Choose Grid Layout When:
Working with two-dimensional layouts
that involve both rows and columns.
Needing precise control over the
placement of items in a grid.

Use Both Together:


Often, a combination of Flexbox and Grid
Layout is used to achieve complex and
responsive designs.
For example, you might use Flexbox to
organize items within a grid cell.

@ValluruSarath
CSS box model
The CSS box model is a fundamental concept
that describes the layout of elements on a web
page. It consists of several components, and
each HTML element is represented as a
rectangular box. The key components of the box
model are:

1. Content: The actual content of the box, such


as text, images, or other media. It is enclosed
by padding, border, and margin.
2. Padding: The space between the content and
the border. Padding adds internal spacing
within the box.
3. Border: The border surrounding the padding.
It is optional but can be styled using
properties like border-width, border-style,
and border-color.
@ValluruSarath
CSS box model
Margin: The space outside the border. It
clears an area around the box, preventing it
from touching neighboring elements.
The total width of an element is calculated as
follows:

Totalwidth=Contentwidth+Padding+
Border+Margin

Similarly, the total height is calculated


considering the content height, padding, border,
and margin.

@ValluruSarath
CSS box model
Altering the Box Model Using CSS Properties:

@ValluruSarath
Box-sizing property
The box-sizing property in CSS controls
how the sizing of an element is calculated,
specifically regarding the content,
padding, and border dimensions. It has
three possible values:

1. content-box (default): The width and


height of the element are calculated
only based on the content, excluding
padding and border.

@ValluruSarath
Box-sizing property

2. padding-box: The width and


height include the content and
padding, but not the border.

3. border-box: The width and height


include content, padding, and border.
This is often considered more intuitive
for sizing elements.

@ValluruSarath
CSS `position` property
The CSS position property determines
the positioning method used for an
element. It has several values, each
affecting the element's positioning in
a different way:

1. static (default): Elements are


positioned according to the normal
flow of the document. This is the
default behavior

@ValluruSarath
CSS `position` property
2. relative: Elements are positioned
relative to their normal position in the
document flow, but then adjusted
based on the values of top, right,
bottom, or left.

3. absolute: Elements are removed from


the normal document flow and positioned
relative to the nearest positioned ancestor
(or the initial containing block if no
positioned ancestor is found).
@ValluruSarath
CSS `position` property

4. fixed: Elements are removed from the


normal document flow and positioned
relative to the viewport. They stay fixed
even when the page is scrolled.

@ValluruSarath
CSS `position` property
5. sticky: Elements are treated as
relative positioned until they cross a
specified point during scroll, after
which they are treated as fixed.

@ValluruSarath
CSS specificity
CSS specificity is a set of rules that
decides which styles apply to an element
when there are multiple styles targeting
it.

How does it work?


Styles have different levels of
importance: inline styles are most
important, followed by IDs, classes,
and element names.
When styles conflict, the one with
higher specificity wins.
If specificity is the same, the style
that appears later in the stylesheet
wins.

@ValluruSarath
Class, Id, Attribute Selectors
Class Selectors:
Syntax: Class selectors start with a period
(.) followed by the class name. For example,
.my-class.
Usage: Classes are used to apply styles to
multiple elements that share a common
characteristic. Multiple elements can have
the same class, and a single element can
have multiple classes.

@ValluruSarath
Class, Id, Attribute Selectors
Attribute Selectors:
Syntax: Attribute selectors target elements
based on the presence or value of their
attributes.
Examples:
Select elements with a specific attribute:
[attribute]

@ValluruSarath
Class, Id, Attribute Selectors
ID Selectors:
Syntax: ID selectors start with a hash (#)
followed by the ID name.
Usage: IDs are used to uniquely identify a
single HTML element on a page. Each ID
should be unique within the HTML document.

@ValluruSarath
CSS variables
CSS variables, also known as custom
properties, allow you to define reusable
values in your stylesheets. They are
declared using the -- prefix and can be
used to store values such as colors, font
sizes, or any other property value. CSS
variables bring modularity and ease of
maintenance to your styles.
Example:
--main-color and --font-size are CSS
variables defined in the :root pseudo-
class, making them globally available.
The var() function is used to reference
the variable values, making it easy to
update styles consistently across the
stylesheet.
@ValluruSarath
CSS variables

@ValluruSarath
CSS preprocessors
CSS preprocessors are scripting
languages that extend the capabilities of
CSS. They introduce features like variables,
nesting, mixins, functions, and more,
allowing developers to write more
maintainable and efficient stylesheets. Two
popular CSS preprocessors are

1. Sass (Syntactically Awesome


Stylesheets)

Advantages:
Variables: Allows the use of variables
to store and reuse values, making it
easier to maintain and update styles.

@ValluruSarath
CSS preprocessors
Nesting: Supports nesting of selectors,
making the stylesheet structure more
closely mirror the HTML structure.
Mixins: Enables the creation of reusable
groups of styles, improving modularity.
Functions: Introduces functions that
can be used to manipulate values or
generate complex styles dynamically.

@ValluruSarath
CSS preprocessors
2. Less:
Advantages:
Variables: Allows the use of
variables for storing and reusing
values.
Nesting: Supports nesting of
selectors to create a more
organized structure.
Mixins: Allows the creation of
reusable styles.
Math Operations: Provides basic
mathematical operations within
styles.

@ValluruSarath
CSS preprocessors

Advantages of using CSS preprocessors:


Code Reusability
Modularity
Maintaniability
Mathematical Operations
Vendor Prefixing &
Easier Debugging
@ValluruSarath
CSS transformations
CSS transformations are used to modify the
appearance of elements by applying various
transformations like translation, rotation,
scaling, and skewing. They allow you to change
the position, size, and orientation of elements
without affecting the normal document flow.

@ValluruSarath
keyframes in CSS
animations
Keyframes in CSS animations define the styles
at certain points during the animation. They
allow you to control the intermediate steps in
an animation.

@ValluruSarath
CSS transitions and
animations
CSS Transitions and CSS Animations are
both techniques for adding dynamic
behavior to elements, but they differ in
their implementation and use cases.

CSS Transitions:
1. Triggered by Changes: Transitions are
typically triggered by changes in an
element's state, such as hovering over
it, changing its class, or altering a
property like color or size.
2. Properties: They transition between
two states of a specific property, for
example, changing the opacity, width,
or color
@ValluruSarath
CSS transitions and
animations

Usage:
Ideal for simple, state-based
animations.
Suited for hover effects, fade-ins,
and other small interactions.
Easy to implement with minimal
code.
Declaration:

@ValluruSarath
CSS transitions and
animations

CSS Animations:
1. Keyframes: Animations use
keyframes to define a sequence of
styles for an element at different
times during the animation.
2. Properties: They can animate multiple
properties at different intervals and
durations.
3. Usage:
Suitable for complex and continuous
animations.
Provides more control over the entire
animation sequence.

@ValluruSarath
CSS transitions and
animations

Can be used for looping animations,


sequential movements, and more.

Declaration:

When to use one over the other:


Use Transitions When:
Dealing with simple state changes
like hover effects.

@ValluruSarath
CSS transitions and
animations

Transitioning a specific property from one


state to another.
Looking for a quick and easy
implementation with less code

Use Animations When:


Creating complex, continuous, or sequential
animations.
Needing precise control over the entire
animation sequence.
Animating multiple properties at different
intervals.

@ValluruSarath
Pseudo-classes and
Pseudo-elements

Difference:
Pseudo-classes (:hover, :nth-child(),
:not(), etc.) select and style elements
based on their state or position in the
document.
Pseudo-elements (::before, ::after,
::first-line, ::first-letter, ::selection,
etc.) select and style parts of an
element, creating virtual elements or
targeting specific portions of the
content.

@ValluruSarath
Pseudo-classes and
Pseudo-elements

@ValluruSarath
Pseudo-classes and
Pseudo-elements

@ValluruSarath
JustifyContent &
alignItems difference
Flexbox is a powerful layout model in CSS that
allows you to design complex layouts more
efficiently. To align items using Flexbox, you
can use the justify-content and align-items
properties.

justify-content: This property aligns items


along the main axis (horizontally in a row,
vertically in a column). It controls the
distribution of space between and around
content items.
align-items: This property aligns items along
the cross-axis (vertically in a row,
horizontally in a column). It specifies the
default alignment for items inside the
container.
@ValluruSarath
JustifyContent &
alignItems difference

@ValluruSarath
CSS Grid template areas
CSS Grid template areas allow you to define
named grid areas within a layout, making it
easier to visualize and control the placement
of elements on the grid. By assigning names
to different sections of the grid, you can
then place elements into these areas using
the grid-area property.

Example:
The grid-template-areas property
defines the named areas for the grid.
The grid-template-columns and grid-
template-rows properties specify the
size of columns and rows.
Elements with classes .header, .sidebar,
.main, and .footer are placed into their
respective grid areas using grid-area.

@ValluruSarath
CSS Grid template areas

@ValluruSarath
Follow
@ValluruSarath

You might also like