Skip to content

Instantly share code, notes, and snippets.

@hlfcoding
Last active March 16, 2023 19:16
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hlfcoding/f7e85f7d2a9d2e8c5a90 to your computer and use it in GitHub Desktop.
Save hlfcoding/f7e85f7d2a9d2e8c5a90 to your computer and use it in GitHub Desktop.
Learn CSS the Hard Way - Example-driven talk that focuses in-depth on CSS2 fundamentals and best practices for real-world scenarios. Examples are interactive. There are also resources (below) for further learning. Everything is online for future reference and experimentation: http://codepen.io/collection/XOLJBj

Introduction (5min)

  • (Setup: http://codepen.io/hlfcoding/pen/vEzpVd, stopwatch, printout of this, all pens loaded.)
  • Reason for this talk: better 'general knowledge of' (will be less lost) / 'fundamental knowledge how to' (will do it right).
  • Format of the talk. Provide general outline. Q&A time after each point.
  • History and personal history with CSS.
    • How complexity has been introduced in places and resolved in others.

Topics

Adding classes to elements (10min)

First topic because grammar establishes foundational conventions. Good warmup.

Show and discuss pros, cons for different markup techniques: http://codepen.io/hlfcoding/pen/dPeBjW

  • Markup in the un-semantic style (first figure).
  • Markup in the semantic style (second figure).
  • Markup in a real example (third figure).
  • Review figure captions.
  • Mention OOCSS.

Intro to positioning and layout properties (25min)

  • The legacy of the document (object) model.
  • These properties (their CSS2 values) have no usage caveats after IE9.

The display property: http://codepen.io/hlfcoding/pen/myBGvq

  • Distinguish block, inline-block, inline. Emphasize this importance.
  • Mention vertical-align, but that it's only reliable / easy to understand for one-liners.
  • Also touch on the table* properties.
  • Note all examples are positioned statically.

The position property: http://codepen.io/hlfcoding/pen/pvZeNM

  • Explain static. Emphasize its use case.
  • Explain relative, expanding on static.
  • Explain absolute, expanding on relative. Discuss common use cases.
  • Explain fixed.
  • Explain z-index.

Floating (float, clear) properties:

  • Gloss over the basics, that floats, along with 'clearfix', are used for columns. There's nothing new or obscure about CSS2 grids.
  • Discuss pitfalls with the toolbar use case. Discuss the complexity around floats.
    • Margins don't collapse, unlike with normal document flow.
    • Floated elements automatically become display: block elements if they are inline.
    • Floated elements remain in the document flow and affect the flow of other elements around it. http://codepen.io/hlfcoding/pen/VYBWww

Mention overflow.

Animations and the works (5min)

Use a personal example (provide context): http://codepen.io/hlfcoding/pen/rhnkD

  • Go over animation through use of transition, animation, @keyframe, transform.
    • Note for performance we're transforming using translate instead of transitioning top and left.
  • Mention use of pseudo-elements for rendering cross-hairs.
  • Note the use of other Sass language features like mixins, maps, loops, and color functions.

Sass gotchas and conventions (5min)

But don't forget the small details of the internals.

Adapting to the future (10min)

http://codepen.io/hlfcoding/pen/JoBOyP

  • Integrating feature detection is easier these days, most CSS features don't need fallbacks.
    • The exception is with layouts and gestures. For example, use flex-box, but fall back to floats or tables.
  • Simple responsive layout techniques:
    • A single mobile breakpoint (two @media queries) and setting min/max-width can go a long way, especially since @media is complex.
    • Support new media incrementally; keep vigilant and test.
    • Note the visual design decisions made to keep the 'spirit' of the UI for smaller viewports.
    • Note sometimes best results mean completely different layouts and additional elements and scripting.

Conclusion (5min, 5min Q&A)

  • Reason for this talk.
  • Imperfect model.
  • Value of experimentation.
  • Brief overview of resources.

Resources

Overviews

Reference

Topical articles

Technical Specs

Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment