Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS speed dating for JavaScript people

CSS speed dating for JavaScript people

A lot of people dislike CSS for no reason, either one did not take the time to learn the fundamentals as they did with JavaScript, or sometimes one just doesn't know about specific superpowers of CSS. Let's take 30 minutes to quickly go through crucial CSS fundamentals and dive into some nifty techniques for your next front-end adventures.

Avatar for Nico König

Nico König

May 30, 2019
Tweet

More Decks by Nico König

Other Decks in Programming

Transcript

  1. Hey, my name is Nico. I like CSS, hand ground

    coffee and I organize FrankenJS in Nuremberg. twitter: @theNicoKoenig
  2. But I wasn’t alone CSS was just an obstacle in

    our codebase and copy and pasting from stack overflow was our super power.
  3. The expert In the land of the blind, the one-eyed

    man is king - so I accidentally became the wizard. And somehow a trainer.
  4. The box model is the blueprint of layout on the

    web. Each element is made out of the box’s content, padding, border, and margin.
  5. Question: what are the dimensions of the div? div {

    margin: 10px; border-width: 10px; padding: 10px; width: 400px; }
  6. box-sizing: content-box Width and height only set the size of

    the elements content-box. The values for padding and border are added to the total dimensions. This is the default behavior.
  7. box-sizing: border-box Width and height properties define the dimensions of

    the element including values for padding and border.
  8. Question: what are the widths of the elements? div {

    width: 200px; } button { width: 200px; } span { width: 200px; }
  9. display: block • create a newline before and after •

    takes up the full width of the parent element by default • adjusts to content height by default • width and height can be set • can contain any elements
  10. display: inline • width and height properties are ignored •

    as big as the elements content • overflows to a new line • creates no new lines • can only contain other inline elements or data
  11. In the normal document flow, all elements are laid out

    according to their appearance in the document respecting the individual display type and direction.
  12. Normal document flow with direction: LTR <main> <p></p> <span></span> <p></p>

    <span></span> <span></span> <span></span> <button></button> </main>
  13. Normal document flow with direction: RTL <main> <p></p> <span></span> <p></p>

    <span></span> <span></span> <span></span> <button></button> </main>
  14. The position property defines how an element is positioned. The

    top, bottom, left and right properties define the final location of positioned elements.
  15. position: static • is not positioned • default position of

    all elements in the normal document flow • top, right, bottom and left properties are ignored
  16. position: relative • is positioned • still takes up the

    original space in the normal document flow • top or bottom set vertical offset • left or right set horizontal offset
  17. position: relative If left and right property have a value

    other than auto, the logical starting property for the current direction wins. Left for LTR and right for RTL.
  18. position: absolute can be slightly tricky, because it depends on

    the containing block and if top, bottom, left or right properties are set. P.S: it’s positioned
  19. The containing block for absolute positioned elements is the nearest

    positioned parent element* * close, but there are some exceptions.
  20. position: absolute • removed from the normal document flow •

    block elements shrink to it’s content size if no width or height property is set • stays in the normal document flow position if no offset properties are set • if offset properties are set, it’s positioned according to the offsets within the padding box of the containing block