Flow Layout
Inline Elements¶
- thinks it's Typography
[!What's 2 special things about inline?]- - no height/width - can't apply padding - Inline elements don't have to be rectangles -
- Horizontal padding is just on the tips
Troubleshooting inline issues¶
Mysterious space at the bottom of image¶
- Not a part of the box model
-

[!Solution to magic space at the bottom]- -
display: block-line-height: 0on the wrapping div
Unexpected space between inline elements (images)¶
[!Solution to magic space at the bottom]- whitespace in HTML
display: flexorgrid- (this problem is only in flow)
line-height: 0on the wrapping div
Inline padding-left/right¶
Default

Since it line wraps, it only applies padding on the tips

Replaced elements¶
- img
- video
- canvas
Inline wrapper on some foreign object
???? replaced elements vs inline elements???? - images seem to act like inline elements (see above)
Inline-block¶
- like
inlineexcept it has width/height- can apply padding
- Like block that you drop in an inline context
- Parent will treat it like inline
- example: buttons
- inline elements with padding
- doesn't have that sweet sweet word wrap
Width¶
Default: width: auto
Width keywords¶
auto vs 100%¶
[!Solution]-
100%: horizontal scroll if the child has margin - margin not a part ofbox-sizing: border-box
autotakes margin into account - will line wrap if needed - Kevin Powell: Stop using with: 100% - TODO: embed the short video
min-content¶
- sizing based on the children

max-content¶
- never add line breaks
- may cause horizontal scroll
[!Use case of max-content]- why: if you want the background to only cover the text - max-content:
- auto:
fit-content¶
- content can fit in parent -> act like
max-content - otherwise: act like
width: auto
Implementing fit-content¶
- implicit
width: auto - content is short (eg: 100px) -> max-width kicks in
- content is long af
- max-width: has no effect
width: auto
min-widthhandles large unbreakable word in narrow container
min-width vs max-width¶
min-width > max-width > width
Exercise¶
Before ![[image-20230113144441882.png]]
After

[!Solution to dynamic width figure and caption]- on the parent
figure->width: min-contentwill look for the widest child and make that the width
Setting a fixed width¶
- set a
max-width - prevent horizontal scroll where the width is wider than the screen
[[Which units to use#Width/heights]]¶
Height¶
look down the tree to see how tall it should be
- children determine parent height
Default height is like width: min-content
- as small as possible to fit content
Setting a fixed height¶
- you really shouldn't, will almost always cause overflow
- use
min-height
Why percentage height has no effect¶
Goal
![[image-20221024080322661.png]]
Actual
![[image-20221024080337789.png]]
Parents shrink-wrap to fit their children snuggly
Solution¶
When the body has height: 100%
this is better than height: 100vh because 100vh is a bit taller on mobile devices
Or the new CSS viewport heightheight: 100dvh
* doesn't take the keyboard into effect
need to add height: 100% for every element between the html element and the element we want to stretch to 100% of the screen
Aspect Ratio¶
aspect-ratio: 1 / 1;
Implementing Aspect Ratio¶
For 9/16 ratio clientHeight
returns the inner height of an element in pixels, including padding but not
- Horizontal scrollbar
- height
- border
- margin
is a measurement which includes the element borders, the element vertical padding, the element horizontal scrollbar (if present, if rendered) and the element CSS height.
is a measurement of the height of an element's content including content not visible on the screen due to overflow
- Horizontal padding is just on the tips

- auto: 
