layout by flexbox and css grid

Flexbox

1. For Container:

  • float, clear, vertical-align for the items inside flexbox will become invalid
  • display: inline-flex vs display: flex:—-only apply to flex container, to make it display as inline or block won’t affect flex items
    inside
  • prosperities:
    1. flex-direction: row | row-reverse | column | column-reverse
    2. flex-wrap: break new line or not when exceeding it container nowrap | wrap | wrap-reverse;
    3. flex-flow: combination of the first two flex-direction || flex-wrap;
    4. align-items: where flex items sit on the cross axis
      flex-start | flex-end | center | baseline | stretch;
    5. justify-content: where the flex items sit on the main axis flex-start | flex-end | center | space-between | space-around

2. For flex items:

  • flex: 1 1 20px: three attributes: flex-grow flex-shrink flex-basis
  • order: 3: like the smaller will be put in front
  • align-self: override its container’s align-items layout, update position of itself

Good website to pratice it

CSS Grid

1. Common properties for container:

Use “display: grid;” in container

  • grid-column: span 2; /high number will cause it to create extra grids even if we didn’t tell it/
  • grid-row: span 2;
  • grid-column-start: 2;
  • grid-column-end: 4;
  • grid-column: 2 / 4;
  • grid-column: 2 / -1; / span it to the last track /
  • grid-row: 2 / -1; /but you need to define rows in the container/
  • justify-self: end;
  • align-self: end;

Good link to learn more