SlideShare a Scribd company logo
Advanced
CSS3
Compiled by: Seble Nigussie
Topics
• Custom CSS properties
• Responsive Page Layout
• CSS Flexboxes
• CSS Grid
• Media Queries
• CSS Pre-compilers
CSS Custom Properties
(Variables)
• CSS Variables are entities defined in CSS that contain
specific values to be reused throughout a document
• Variables should be declared within a CSS selector that
defines its scope. For a global scope :root or body
selectors can be used
• Variable name must begin with two -- hypens and is case
sensitive
• Variable Declaration Syntax
• --variable-name: value;
CSS var() Function
• The var() function is used to
lookup the value of a custom
property
• Syntax
• var(property-name, value)
• Property-name: the custom
property’s name
• Optional fallback value used if
the custom property is invalid
• Example
• Declaring a custom property
:root{
--main-text-color: brown;
}
• Using the custom property
p{
color: var(--main-text-color);
}
a{
color: var(--main-text-color, red);
}
Custom Property Fallback Values
• A fallback value is used as the substitution
value when the referenced custom property is
invalid
Inheritance of Custom
Properties
• Custom property values of
parents’ are inherited by child
elements like most other CSS
properties
• If no value is set for a custom
property on a given element,
the value of its parent is used
• Eg. font-size of class four will
inherit the --test definition of
class two
Responsive Page
• A responsive page is a web-page that adapts to
different screen sizes and different display devices
like mobiles, tablets, desktops …
• Techniques to develop responsive web page
components and/or layouts
• CSS Flexboxes
• CSS Grid
• Media Queries
CSS Flexbox
• Flexible boxes, or flexbox, is a new layout mode in CSS3
• It is a one-dimensional layout model that offers space
allocation between items in a container and robust
alignment capabilities
• Use of flexbox ensures that elements behave
predictably when the page layout must accommodate
different screen sizes and different display devices
Flex Containers and Items
• Flexbox consists of flex containers and flex items
• Flexbox defines how flex items are laid out inside a flex
container
• A flex container expands its items to fill available free
space or shrinks them to prevent overflow
• A flex container is declared by setting the display property
of an element to either flex (rendered as a block) or inline-
flex (rendered as inline element)
Flex Containers and Items …
Flex Containers and Items …
• The flex-direction property specifies the
direction of the flexible items inside the
flex container
• Possible Values:- Row, Row-reverse,
Column, Column-reverse
Flex Containers and Items …
• The justify-content property
horizontally aligns the flexible
container's items
• Possible Values: flex-start, flex-end,
center, space-between, space-
around
Flex Properties …
• The align-items property
vertically aligns the flexible
container's items
• Possible Values: stretch, flex-
start, flex-end, center, baseline
Flex Properties …
• The flex-wrap property specifies whether
the flex items should wrap or not, if there
is not enough room for them on one flex
line
• Possible Values: nowrap, wrap, wrap-reverse
Flex Properties …
• The align-self property of flex
items overrides the flex
container's align-items property
for that item
• Possible Values: stretch, flex-start,
flex-end, center, baseline
Flex Properties …
• The flex property specifies the
length of the flex item, relative
to the rest of the flex items
inside the same container
Sample Flexbox Uses …
Sample Flexbox Uses
CSS Grid Layout
• The CSS Grid Layout Module offers a grid-based
layout system, with rows and columns, making it
easier to design web pages without having to use
floats and positioning
• A grid layout consists of a parent element, with
one or more child elements
• An HTML element becomes a grid container when
its display property is set to grid or inline-grid
Grid
Layout
• The grid-template-columns property
defines the number of columns in
your grid layout, and it can define
the width of each column, The grid-
template-rows property defines the
height of each row
• The value is a space-separated-list
• If you want your grid layout to
contain 4 columns, specify the width
of the 4 columns, or "auto" if all
columns should have the same width.
Grid
Properties
• Items gaps can be adjusted by
using one of the following
properties:
• grid-column-gap
grid-row-gap
grid-gap
Grid Properties
• The justify-
content property is used to
align the whole grid inside the
container
• space-evenly, space-around,
space-between, center, start, end
Grid Lines
• Refer to line numbers when placing a grid item in a grid container:
Grid Lines
Grid Lines
• placing a grid item in a
grid container:
Grid Properties …
• The grid-column property is a shorthand property for the grid-column-
start and the grid-column-end properties. The grid-row property does the
same thing for rows
• To place an item, you can refer to line numbers, or use the keyword "span" to
define how many columns the item will span
Grid Properties …
• The grid-area property can be used as a
shorthand property for the grid-row-start,
grid-column-start, grid-row-end and
the grid-column-end properties
• Syntax
• grid-area: grid-row-start/grid-column-start/grow-row-
end/grid-column-end
Grid Properties …
• The grid-area
property can also be
used to assign names
to grid items
• Named grid items can
be referred to by the
grid-template-areas
property of the grid
container
• Each row is defined
by apostrophes (' ')
• The columns in each
row is defined inside
the apostrophes,
separated by a space
Grid Properties …
• A period sign represents a grid item with no name
• Make "item1" span two columns and two rows:
• Let "myArea" span two columns in a five columns grid layout
Flexbox, Grid and Sass
Media Queries
• The @media rule: allows to define different style rules for
different media types
• You could have one set of style rules for computer screens, one for
printers, one for handheld devices, one for television-type devices,
and so on
• Media queries can be used to check many things, such as:
• width and height of the viewport
• width and height of the device
• orientation (is the tablet/phone in landscape or portrait mode?)
• resolution
Media Queries …
• A media query consists of a media type and can contain one or
more expressions, which resolve to either true or false
@media not|only mediatype and (expressions) {
CSS-Code;
}
• You can also attach different external style sheets for different
media:
<link rel="stylesheet" media="mediatype and|not|only (expressions)"
href="print.css">
CSS3 Media Types
• all
• Used for all media type devices
• print
• Used for printers
• screen
• Used for computer screens, tablets, smart-phones etc.
• speech
• Used for screen readers that "reads" the page out loud
Media Queries Example
Media Queries Example …
Media Queries Example…
Size content to the viewport
• A Browser’s viewport is the area of web page in which the content is
visible to the user
• A <meta> viewport element gives the browser instructions on how to
control the page's dimensions and scaling
<meta name="viewport" content="width=device-width, initial-scale=1.0">
• The width=device-width sets the width of the page to follow the
screen-width of the device (which will vary depending on the device)
• The initial-scale=1.0 sets the initial zoom level when the page is first
loaded by the browser
Exercises
• Calculator with flexbox or grid
Sass
• Sass (Syntactically Awesome Stylesheet) is a CSS pre-processor that
reduces repetition of CSS and therefore saves time
• Everything about Sass is to provide tools to prevent repeating
yourself in your code: it’s the DRY principle, which stands
for Don’t repeat yourself
• variables prevents repeating values
• nesting prevents repeating selectors
• mixins and extensions prevent repeating properties
• A browser does not understand Sass code. Therefore, you will need
a Sass pre-processor to convert Sass code into standard CSS
Sass Variables
• Sass variables can store strings,
numbers, colors, booleans, lists,
null
• Variable name is prefixed by $
• Sass Variable Syntax:
• $variablename: value;
• Variables are only available at the
level of nesting where they are
defined
Variables Scope
• Global variables should be
defined outside any rules
• The default behavior for
variable scope can be
overridden by using the !global
switch
• !global indicates that a
variable is global, which means
that it is accessible on all
levels
Sass Nesting
• You can nest properties in Sass
Sass Nesting …
• Many CSS properties have the same prefix, like font-
family, font-size and font-weight or text-align, text-
transform and text-overflow
Sass @import
• You can create small files with CSS snippets to include in
other Sass files. Examples of such files can be: reset file,
variables, colors, fonts etc
• The @import directive allows you to include the content of
one file in another
• Sass Import Syntax:
• @import filename;
• @import "variables";
• You do not need to specify a file extension, Sass automatically
assumes that you mean a .sass or .scss
Sass Mixins
• The @mixin directive lets you create CSS code that is to
be reused throughout the website
• The @include directive is used to include mixins
• @mixin name {
property: value;
property: value;
...
}
Using Mixins
A mixin can also include
other mixins
Passing Variables to a Mixin
• Mixins accepts arguments.
This way you can pass
variables to a mixin
Using Mixins …
• Another good use of a mixin is for vendor prefixes
Sass @extend
Directive
• The @extend
directive lets you
share a set of CSS
properties from one
selector to another
Sass Variables …
Sass files has the ".scss" file extension.

More Related Content

PPTX
Sass_Cubet seminar
PDF
Basic-CSS-tutorial
PPTX
DSpace 4.2 Transmission: Import/Export
PPTX
ZIP
Rails 3 (beta) Roundup
PPT
Ruby On Rails
PPT
Rubyonrails 090715105949-phpapp01
PPTX
cascading style sheet powerpoint notes.pptx
Sass_Cubet seminar
Basic-CSS-tutorial
DSpace 4.2 Transmission: Import/Export
Rails 3 (beta) Roundup
Ruby On Rails
Rubyonrails 090715105949-phpapp01
cascading style sheet powerpoint notes.pptx

Similar to Flexbox, Grid and Sass (20)

PPTX
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
PPTX
MTA css layouts
PPTX
Lecture-8.pptx
PDF
CSS3 Refresher
PDF
CSS vs. JavaScript - Trust vs. Control
PPTX
Web technologies-course 04.pptx
PPTX
CSS.pptx
PPT
gdg_workshop 4 on web development HTML & CSS
PPTX
CSS3 notes
PDF
Render Conf: Start using CSS Grid Layout Today
PDF
HTML ,CSS ,JQuery Cheat Sheet
PPTX
css3.pptx
PDF
Grid and Flexbox - Smashing Conf SF
PDF
Evergreen websites for Evergreen browsers
PPT
Tutorial0eesrtjfzjgxkgxkxxkxkgxkgxjffj3.ppt
PPTX
Krishan gaurav-sapient bootstrapsession
PDF
PPT
CSS
PDF
Frontend United: Start using CSS Grid Layout today!
PPTX
Lecture 6.pptx..........................
Full Stack Development CSS_Layouts,Grid,FlexboxPPT.pptx
MTA css layouts
Lecture-8.pptx
CSS3 Refresher
CSS vs. JavaScript - Trust vs. Control
Web technologies-course 04.pptx
CSS.pptx
gdg_workshop 4 on web development HTML & CSS
CSS3 notes
Render Conf: Start using CSS Grid Layout Today
HTML ,CSS ,JQuery Cheat Sheet
css3.pptx
Grid and Flexbox - Smashing Conf SF
Evergreen websites for Evergreen browsers
Tutorial0eesrtjfzjgxkgxkxxkxkgxkgxjffj3.ppt
Krishan gaurav-sapient bootstrapsession
CSS
Frontend United: Start using CSS Grid Layout today!
Lecture 6.pptx..........................
Ad

More from Seble Nigussie (9)

PDF
Fundamentals of programming with C++
PDF
Introduction to JSON & Ajax
PDF
Introduction to jQuery
PDF
Introduction to Javascript
PDF
Introduction to Bootstrap
PDF
Introduction to CSS3
PDF
Introduction to HTML
PDF
Introduction to HTTP
PDF
Introduction to Microprocessors
Fundamentals of programming with C++
Introduction to JSON & Ajax
Introduction to jQuery
Introduction to Javascript
Introduction to Bootstrap
Introduction to CSS3
Introduction to HTML
Introduction to HTTP
Introduction to Microprocessors
Ad

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Cell Structure & Organelles in detailed.
PDF
Basic Mud Logging Guide for educational purpose
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Pharma ospi slides which help in ospi learning
Microbial diseases, their pathogenesis and prophylaxis
Cell Structure & Organelles in detailed.
Basic Mud Logging Guide for educational purpose
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
O7-L3 Supply Chain Operations - ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
The Final Stretch: How to Release a Game and Not Die in the Process.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Cardiovascular Pharmacology for pharmacy students.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Open Quiz Monsoon Mind Game Final Set.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Pharma ospi slides which help in ospi learning

Flexbox, Grid and Sass

  • 2. Topics • Custom CSS properties • Responsive Page Layout • CSS Flexboxes • CSS Grid • Media Queries • CSS Pre-compilers
  • 3. CSS Custom Properties (Variables) • CSS Variables are entities defined in CSS that contain specific values to be reused throughout a document • Variables should be declared within a CSS selector that defines its scope. For a global scope :root or body selectors can be used • Variable name must begin with two -- hypens and is case sensitive • Variable Declaration Syntax • --variable-name: value;
  • 4. CSS var() Function • The var() function is used to lookup the value of a custom property • Syntax • var(property-name, value) • Property-name: the custom property’s name • Optional fallback value used if the custom property is invalid • Example • Declaring a custom property :root{ --main-text-color: brown; } • Using the custom property p{ color: var(--main-text-color); } a{ color: var(--main-text-color, red); }
  • 5. Custom Property Fallback Values • A fallback value is used as the substitution value when the referenced custom property is invalid
  • 6. Inheritance of Custom Properties • Custom property values of parents’ are inherited by child elements like most other CSS properties • If no value is set for a custom property on a given element, the value of its parent is used • Eg. font-size of class four will inherit the --test definition of class two
  • 7. Responsive Page • A responsive page is a web-page that adapts to different screen sizes and different display devices like mobiles, tablets, desktops … • Techniques to develop responsive web page components and/or layouts • CSS Flexboxes • CSS Grid • Media Queries
  • 8. CSS Flexbox • Flexible boxes, or flexbox, is a new layout mode in CSS3 • It is a one-dimensional layout model that offers space allocation between items in a container and robust alignment capabilities • Use of flexbox ensures that elements behave predictably when the page layout must accommodate different screen sizes and different display devices
  • 9. Flex Containers and Items • Flexbox consists of flex containers and flex items • Flexbox defines how flex items are laid out inside a flex container • A flex container expands its items to fill available free space or shrinks them to prevent overflow • A flex container is declared by setting the display property of an element to either flex (rendered as a block) or inline- flex (rendered as inline element)
  • 10. Flex Containers and Items …
  • 11. Flex Containers and Items … • The flex-direction property specifies the direction of the flexible items inside the flex container • Possible Values:- Row, Row-reverse, Column, Column-reverse
  • 12. Flex Containers and Items … • The justify-content property horizontally aligns the flexible container's items • Possible Values: flex-start, flex-end, center, space-between, space- around
  • 13. Flex Properties … • The align-items property vertically aligns the flexible container's items • Possible Values: stretch, flex- start, flex-end, center, baseline
  • 14. Flex Properties … • The flex-wrap property specifies whether the flex items should wrap or not, if there is not enough room for them on one flex line • Possible Values: nowrap, wrap, wrap-reverse
  • 15. Flex Properties … • The align-self property of flex items overrides the flex container's align-items property for that item • Possible Values: stretch, flex-start, flex-end, center, baseline
  • 16. Flex Properties … • The flex property specifies the length of the flex item, relative to the rest of the flex items inside the same container
  • 19. CSS Grid Layout • The CSS Grid Layout Module offers a grid-based layout system, with rows and columns, making it easier to design web pages without having to use floats and positioning • A grid layout consists of a parent element, with one or more child elements • An HTML element becomes a grid container when its display property is set to grid or inline-grid
  • 20. Grid Layout • The grid-template-columns property defines the number of columns in your grid layout, and it can define the width of each column, The grid- template-rows property defines the height of each row • The value is a space-separated-list • If you want your grid layout to contain 4 columns, specify the width of the 4 columns, or "auto" if all columns should have the same width.
  • 21. Grid Properties • Items gaps can be adjusted by using one of the following properties: • grid-column-gap grid-row-gap grid-gap
  • 22. Grid Properties • The justify- content property is used to align the whole grid inside the container • space-evenly, space-around, space-between, center, start, end
  • 23. Grid Lines • Refer to line numbers when placing a grid item in a grid container:
  • 25. Grid Lines • placing a grid item in a grid container:
  • 26. Grid Properties … • The grid-column property is a shorthand property for the grid-column- start and the grid-column-end properties. The grid-row property does the same thing for rows • To place an item, you can refer to line numbers, or use the keyword "span" to define how many columns the item will span
  • 27. Grid Properties … • The grid-area property can be used as a shorthand property for the grid-row-start, grid-column-start, grid-row-end and the grid-column-end properties • Syntax • grid-area: grid-row-start/grid-column-start/grow-row- end/grid-column-end
  • 28. Grid Properties … • The grid-area property can also be used to assign names to grid items • Named grid items can be referred to by the grid-template-areas property of the grid container • Each row is defined by apostrophes (' ') • The columns in each row is defined inside the apostrophes, separated by a space
  • 29. Grid Properties … • A period sign represents a grid item with no name • Make "item1" span two columns and two rows: • Let "myArea" span two columns in a five columns grid layout
  • 31. Media Queries • The @media rule: allows to define different style rules for different media types • You could have one set of style rules for computer screens, one for printers, one for handheld devices, one for television-type devices, and so on • Media queries can be used to check many things, such as: • width and height of the viewport • width and height of the device • orientation (is the tablet/phone in landscape or portrait mode?) • resolution
  • 32. Media Queries … • A media query consists of a media type and can contain one or more expressions, which resolve to either true or false @media not|only mediatype and (expressions) { CSS-Code; } • You can also attach different external style sheets for different media: <link rel="stylesheet" media="mediatype and|not|only (expressions)" href="print.css">
  • 33. CSS3 Media Types • all • Used for all media type devices • print • Used for printers • screen • Used for computer screens, tablets, smart-phones etc. • speech • Used for screen readers that "reads" the page out loud
  • 37. Size content to the viewport • A Browser’s viewport is the area of web page in which the content is visible to the user • A <meta> viewport element gives the browser instructions on how to control the page's dimensions and scaling <meta name="viewport" content="width=device-width, initial-scale=1.0"> • The width=device-width sets the width of the page to follow the screen-width of the device (which will vary depending on the device) • The initial-scale=1.0 sets the initial zoom level when the page is first loaded by the browser
  • 38. Exercises • Calculator with flexbox or grid
  • 39. Sass • Sass (Syntactically Awesome Stylesheet) is a CSS pre-processor that reduces repetition of CSS and therefore saves time • Everything about Sass is to provide tools to prevent repeating yourself in your code: it’s the DRY principle, which stands for Don’t repeat yourself • variables prevents repeating values • nesting prevents repeating selectors • mixins and extensions prevent repeating properties • A browser does not understand Sass code. Therefore, you will need a Sass pre-processor to convert Sass code into standard CSS
  • 40. Sass Variables • Sass variables can store strings, numbers, colors, booleans, lists, null • Variable name is prefixed by $ • Sass Variable Syntax: • $variablename: value; • Variables are only available at the level of nesting where they are defined
  • 41. Variables Scope • Global variables should be defined outside any rules • The default behavior for variable scope can be overridden by using the !global switch • !global indicates that a variable is global, which means that it is accessible on all levels
  • 42. Sass Nesting • You can nest properties in Sass
  • 43. Sass Nesting … • Many CSS properties have the same prefix, like font- family, font-size and font-weight or text-align, text- transform and text-overflow
  • 44. Sass @import • You can create small files with CSS snippets to include in other Sass files. Examples of such files can be: reset file, variables, colors, fonts etc • The @import directive allows you to include the content of one file in another • Sass Import Syntax: • @import filename; • @import "variables"; • You do not need to specify a file extension, Sass automatically assumes that you mean a .sass or .scss
  • 45. Sass Mixins • The @mixin directive lets you create CSS code that is to be reused throughout the website • The @include directive is used to include mixins • @mixin name { property: value; property: value; ... }
  • 46. Using Mixins A mixin can also include other mixins
  • 47. Passing Variables to a Mixin • Mixins accepts arguments. This way you can pass variables to a mixin
  • 48. Using Mixins … • Another good use of a mixin is for vendor prefixes
  • 49. Sass @extend Directive • The @extend directive lets you share a set of CSS properties from one selector to another
  • 50. Sass Variables … Sass files has the ".scss" file extension.