This document discusses several CSS features including box alignment, flexbox, grid layout, CSS shapes, feature queries, initial letters, writing modes, custom properties, calc(), position: sticky, and scroll snapping. It provides code examples and links to documentation for each feature. Key points covered include using box alignment properties in flexbox and grid layout, centering content with flexbox, creating responsive grids with CSS grid, applying shapes to images with shape-outside, testing support for features with feature queries, styling initial letters, flipping text direction with writing modes, defining variables with custom properties, performing calculations with calc(), sticking elements to the viewport with position: sticky, and snapping scrolling with scroll snapping. Links to resources
10. The box alignment properties in CSS are a set of 6 properties
that control alignment of boxes within other boxes.
CSS BOX ALIGNMENT LEVEL 3
https://drafts.csswg.org/css-align/
15. “Unlike Flexbox, however, which is single-axis–oriented, Grid
Layout is optimized for 2-dimensional layouts: those in which
alignment of content is desired in both dimensions.”
CSS GRID LAYOUT
https://drafts.csswg.org/css-grid/
18. .cards {
display:flex;
flex-wrap: wrap;
}
.card {
flex: 1 1 250px;
margin: 5px;
}
Flexbox
Flexbox can wrap flex items onto
multiple rows.
A new row becomes a new flex
container for the purposes of
distributing space.
36. The element itself does not generate any boxes, but its children
and pseudo-elements still generate boxes as normal. For the
purposes of box generation and layout, the element must be
treated as if it had been replaced with its children and pseudo-
elements in the document tree.
DISPLAY: CONTENTS
https://drafts.csswg.org/css-display/#box-generation
39. .wrapper {
max-width: 700px;
margin: 40px auto;
display: grid;
grid-column-gap: 30px;
grid-template-columns:1fr 1fr;
}
.wrapper h1, .wrapper p {
grid-column: 1 / -1;
}
.inset {
grid-column: 1 ;
font: 1.4em/1.3 'Lora', serif;
padding: 0;
margin: 0;
}
.inset + p {
grid-column: 2;
}
display: contents
A two column grid. The h1, p and
blockquote with a class of inset are
all direct children.
41. .images {
display: contents;
}
display: contents
The ul has a class of images. By
applying display: contents the ul is
removed and the li elements become
direct children.
45. CSS Shapes describe geometric shapes for use in CSS. For Level
1, CSS Shapes can be applied to floats. A circle shape on a float
will cause inline content to wrap around the circle shape
instead of the float’s bounding box.
CSS SHAPES
https://drafts.csswg.org/css-shapes/
46. .balloon {
float: left;
width: 429px;
shape-outside: circle(50%);
}
<div class="box">
<img class="balloon" src="round-
balloon.png" alt="balloon">
<p>...</p>
</div>
CSS Shapes
A simple shape using the
shape-outside property
50. .balloon {
float: right;
width: 640px;
height: 427px;
shape-outside: ellipse(33% 50% at
460px);
-webkit-clip-path: ellipse(28% 50% at
460px);
clip-path: ellipse(28% 50% at 460px);
}
CSS Shapes
Using clip-path to cut away part of an
image
54. The ‘@supports’ rule is a conditional group rule whose
condition tests whether the user agent supports CSS
property:value pairs.
FEATURE QUERIES
https://www.w3.org/TR/css3-conditional/#at-supports
56. Anything new in CSS you
can use feature queries to
detect support.
57. @supports (display: grid) {
.has-grid {
/* CSS for grid browsers here */
}
}
Feature Queries
Checking for support of Grid Layout
58. @supports ((display: grid) and (shape-
outside: circle())) {
.has-grid-shapes {
/* CSS for these excellent browsers
here */
}
}
Feature Queries
Test for more than one thing
59. Using Feature Queries
▸ Write CSS for browsers without support
▸ Override those properties inside the feature queries
▸ See https://hacks.mozilla.org/2016/08/using-feature-queries-in-css/
60. .balloon {
border: 1px solid #999;
padding: 2px;
}
@supports ((shape-outside: ellipse()) and
((clip-path: ellipse()) or (-webkit-clip-
path:ellipse()))) {
.balloon {
border: none;
padding: 0;
float: right;
width: 640px;
min-width: 640px;
height: 427px;
shape-outside: ellipse(33% 50% at 460px);
-webkit-clip-path: ellipse(28% 50% at
460px);
clip-path: ellipse(28% 50% at 460px);
}
}
Feature Queries
Write CSS for browsers without
support, override that and add new
CSS inside the feature query.
65. Large, decorative letters have been used to start new sections
of text since before the invention of printing. In fact, their use
predates lowercase letters entirely.
This [initial-letter] property specifies styling for dropped, raised,
and sunken initial letters.
INITIAL LETTER
https://drafts.csswg.org/css-inline/#initial-letter-styling
80. This module introduces a family of custom author-defined
properties known collectively as custom properties, which allow
an author to assign arbitrary values to a property with an
author-chosen name, and the var() function, which allow an
author to then use those values in other properties elsewhere in
the document.
CSS CUSTOM PROPERTIES (CSS VARIABLES)
https://drafts.csswg.org/css-variables/
87. <div class="wrapper">
<div class="box box1">
<p>…</p>
<div>height is defined by the flex
container.</div>
</div>
<div class="box box2">
<div>height is 140px</div>
</div>
<div class="box box3">
<div>height is 14em</div>
</div>
</div>
calc()
Three boxes, each with a div nested
inside.
88. .box2 {
height: 140px;
}
.box3 {
height: 14em;
transition: height 0.5s ease;
}
.box3:hover {
height: 30em;
}
calc()
Two of the outer boxes have a height,
box1 is the height of the content
inside.
Box3 will grow on hover.
89. .box > div {
color: #fff;
border-radius: 5px;
position: absolute;
bottom: 20px;
right: 20px;
width: 30%;
height: calc(50% - 20px);
}
calc()
In the CSS for the inner box, we
calculate the height as 50% - 20px.
93. A stickily positioned box is positioned similarly to a relatively
positioned box, but the offset is computed with reference to
the nearest ancestor with a scrolling box, or the viewport if no
ancestor has a scrolling box.
POSITION: STICKY
https://drafts.csswg.org/css-position/#sticky-pos