In this page, you will test different display, position and float values in CSS.
span, a, strong,
em, img
div, p, h1–
h6, ul, li
Task: Go to the CSS (.inline, .block, .inline-block) and fill in the
display: values.
After that, try to change margin and padding. See how the layout changes.
We can hide elements in different ways: display: none;,
visibility: hidden;, and by moving them with
position.
Task: Fill in the missing values in the inline styles below.
Paragraph 1 (should be visible)
Paragraph 3 (should be visible)
Paragraph 4 (should be visible)
Paragraph 6 (should be visible)
The next paragraph can be moved out of the screen using
position and top.
Paragraph 7 (move me out of the screen)
We can make div elements act like a table and table cells.
Task: In the CSS, set
display: table; for .mockTable, and
display: table-cell; for .mockCell.
Relative means the box stays in the normal flow, but you can move it a bit.
Task: Add values for left and top.
Absolute means the box is removed from normal flow. It is placed relative to the nearest positioned parent, or the page.
Task: Add values for right and top.
Fixed means the element stays in the same place on the screen when you scroll.
Task: Set the poop image to fixed at the bottom-left of the screen.
Here, the parent <section> is
position: relative;. The small boxes are
position: absolute; inside it.
Task: Change one left value from px to
% and see what happens.
Floats make elements move to the left or right, and text can wrap around them.
Task: Make the image float to the right.
This text is inside a div. We will float the image.
After you add float: right;, this text should wrap around the image.
Task: Float one image left and one image right.
This paragraph will flow around the floating images above. Change the float values and see how it moves.
clear tells the browser: "Do not allow floats on this side."
Task: Make this heading start below any floats.
This paragraph is next to the floating image. The float is on the left.
This paragraph should move below the floating image.
Use clear on the left side.
We can also clear floats using a small empty element or the
overflow property.
If the container has overflow: auto;, it will stretch to hold
the floated elements.
Look at how the border wraps around the floated image.
z-index decides which element is "on top".
A higher number means it is in front.
Task: Set different z-index values to see which one is on top.