Layouts: Floats, Flexbox, CSS Flashcards
Page Layout vs. Component Layout
Page Layout:
Laying out elements - big pieces of content
Component layout:
The components themselves need to have some sort of layout as well
What is considered the old way of building layouts? And what are its characteristics?
Float layouts. Uses the float CSS property. However it is getting outdated fast.
What is a modern way of laying out elements in a 1-dimensional row without using floats? What is it perfect for?
Flexbox. Perfect for component layouts.
Used for laying out element in a fully-fledged 2-dimensional grid. What is it perfect for?
CSS Grid. Perfect for page layouts and complex components
What is Flexbox used for?
Modern way of laying out elements in a 1-dimensional row without using floats. Perfect for component layouts.
What is CSS Grid used for?
Laying out element in a fully-fledged 2-dimensional grid. Perfect for page layouts and complex components
What will CSS property float do?
Makes the content inline, so that the other content will float around it.
How to easily write fake text
Write lorem in html files and you can select it from there
Easily move a line up or down
Alt + arrow
What happens with the heigth when there’s two child floats in a component?
The element’s height will collapse. The only reason why it still has any body is because of the padding that is set.
What to do when one floating element is not offsetting from the other?
Make both elements floating. Make second one float either left or right
Can floats still have a bit of margin around them
Yes
What is a similarity between absolute positioning and floats?
Elemens is removed from the normal flow: “out of flow”
How do absolute positioning and floats differ?
With absolute positioning there’s no impact on surrounding elements (might overlap them)
With floats text and inline elements will wrap around the floated element
Will the container adjust to the height of the float element?
No this will not happen. That is the whole reason why height collapses.
Solve collapsing height due to floats
Add empty div with class name “clear”. In CSS set:
.clear{
clear: both;
}
Explain the use of ‘clearfix’ method
In order to avoid having to write a lot empty divs, use this pseudo class to artificially create empty content:
.clearfix::after{
clear:both;
content:””;
display: block;
}
How to break a float?
footer{
clear:both;
}
When not doing this, the next element (footer in this case) will take the width of the previous element.
What does box sizing do?
It will consider the border + padding as part of the width and height instead of being an extra to the width and heigth, hence box model
Box sizing property CSS?
box-sizing: border-box
What is the difference between content-box and border-box?
content-box gives you the default CSS box-sizing behavior. Any border or padding will be added to the final rendered width, making the element wider than the set width.
With border-box, if you set an element’s width to 100 pixels, that 100 pixels will include any border or padding you added, and the content box will shrink to absorb that extra width.
What to do when wanting to apply border box to all elements
*{
box-sizing: border-box
}
How is the clearfix method used?
Use is as class name in the container:
It will then create empty content after the last element of that container
div class=”container clearfix”
How to tell the container to use the flex rules?
display: flex
Flexbox: Create space between items
gap: 10px
Flexbox: Align items along main axis (top, center, bottom)
justify-content: flex-start / flex-end / center
Flexbox: Align items along cross axis (left, center, right)
align-items: flex-start / flex-end / center / stretch
Flexbox: overwrite align-items for individual flex items
align-self: auto / stretch / flex-start / flex-end
Flexbox: Evenly spread out space between the elements
justify-content: space-between
Change order of elements & How to rank?
.el–5{
order: 1;
}
.el–4{
order: 2;
}
.el–6{
order: -1;
}
Order from low to high