Topics for today
- Finish Cascading & Inheritance
- Positioning
- Floats
- Grid Systems
- One-dimensional layout
position property controls which positioning scheme is used.
Its initial value is static, which corresponds to the default document flow.
position: absolute is applied?top, right,
bottom, left properties.First view:
all: unset resets all CSS properties to their initial or inherited values (depending on whether they are inherited). Useful for undoing UA styles in one fell swoop!top and right offsets we try are relative to the top and right of the viewport. What can we do?position: relative makes this element the containing block of any positioned descendants, i.e. the element the offset properties count from.static makes the element the containing blocktop: 50%; left: 50%;. What happens?z-index controls which element is on top of what. Its initial value is auto which corresponds to source order.Second view:
position: fixed to the rescue!
It's just like absolute but the containing block is the viewport.
This has the effect of the element staying in the same place during scrolling.
position != static
position: sticky is a hybrid of relative and fixed:
relative.fixedrelative againWhen learning CSS, the precision of absolute positioning may be tempting, but avoid it: It will bite you back later, when you need to make changes!
float property removes an element from normal flow and sticks it to the left (or right) side of its parent container.
Any content that comes below the floated element in the normal layout flow will now wrap around it, filling up the space to the right-hand side of it as far up as the top of the floated element.clear: both can help with teh footer, but is not ideal (try adding some top margin…)float & clear) were how CSS layouts were done until ~2015!
In graphic design, as in architecture, the guts of a finished product are held up by an underlying support structure that—more often than not—is invisible to the viewer, but can just as easily make or break a design.
display: grid enables Grid layout on an element.
This element becomes the Grid Container and its children are called Grid Items.display: grid doesn’t do much on its own, you also have to define the Grid template.
There is a number of properties to do that, such as:
grid-template-rowsgrid-template-columnsgrid-template1fr unit allows us to distribute the available space in fractions without having to do any math with percentages.grid-gap property allows us to set spacing between the grid cells.grid-row and grid-column properties allow us to place items on specific rows and/or columns. Note that multiple items can be placed in the same cell, and then they will overlap!grid-area allows you to assign an element to a named area.grid-row and grid-column allow us to control which grid lines elements fall on.repeat allows us to create multiple columns or rows with the same metricsgrid-row-end and grid-column-end allow us to make elements span multiple grid cells without explicit control of which grid cells they fall on.dense keyword in grid-auto-flow prevents holesdisplay:contents allows us to make descendants grid childrendisplay: flex enables Flexbox layout on an element.
This element becomes the Flex Container and its children are called Flex Items.flex: N defines the proportion that a flex item spreads over.flex-direction: column on the flex container makes the items flow from top to bottomalign-items and justify-content on the flex container specify alignment in each direction. Which direction depends on the value of flex-directioncolumns, column-count, or column-widthcolumn-gap (in the future just gap) allows you to control spacing between columnscolumn-rule allows you to add lines between columns. Its syntax is similar to border.Multicol is not only about text, it can be used to lay out any element