CSS: Layout & Positioning Flashcards

1
Q

What is browser flow?

A

Flow is what the browser uses to lay out a page of HTML elements. The browser starts at the top of any HTML file and follows the flow of elements it encounters.

And just considering the block elements for a moment, it puts a line-break between each one. So the first elements is displayed first, then a line break, followed by the second line break, then a line break, and so on, from the top of your file to the bottom. That’s flow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do inline elements flow?

A

Inline elements are flowed next to each other, horizontally, from top left to bottom right. The inline elements are laid next to one another horizontally, as long as there is room on the right to place them.

If we narrow the browser window or reduce the size of the content area with the width property, the browser will create a line break and the inline elements will move onto the next line. The browser uses as many lines as necessary to flow the content into the space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe margin behaviour between side by side inline elements?

A

When the browser has the task of placing two inline elements side by side, and those elements have margins, then the browser does what you might expect. It creates enough space between the elements to account for both margins.

So if the left element has a margin of 10 pixels and the right has a margin of 20 pixels, then there will be 30 pixels of space between the two elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe margin behaviour between inline elements that sit one on top of the other?

A

When the browser places two block elements on top of each other it collapses their shared margins together. The height of the collapsed margin is the height of the largest margin.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe what the float property does?

A

The float property first takes an element and floats it as far left or right as it can. It then flows all the content below it around the element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What two requirements must an element have before it can be floated?

A

An identity and a width.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you make sure that there’s no extra room around the edges of the page?

A

Set the margin of the body to 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is the order of your HTML important when floating elements?

A

When you float an element, you need to move the HTML for the element directly below the element that you want it to follow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What effect does floating an element have on its position within the flow.

A

Floating an element removes it completely from the normal flow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the clear property and how should you use it.

A

The clear property is used on an element to request that as the element is being flowed onto the page, no floating content is allowed on the left, right, or both sides of the element.

For example if you apply the css clear: right to an element, no floating content will be allowed to the right of it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Do margins collapse on floated elements?

A

No. Unlike block elements that are flowed on the page, floated elements are just floating. In other words, the margins of floated elements aren’t actually touching the margins of the elements in the normal flow, so they can’t be collapsed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Can you float an inline element?

A

Yes you can. The best and most common example is to float images. Float an image left or right in a paragraph and you’ll see the text float around it. Don’t forget to add padding to give the room a little room, and possibly a border.

You can also float any other inline element you like, but it’s not commonly done.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What CSS feature do you use to precisely position elements on the page?

A

absolute positioning.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe the way block elements flow on the page?

A

Block elements flow from the top down, with a line break between elements. By default, each element takes up the entire width of the browser window.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the way inline elements flow inside a block element?

A

Inline elements flow inside a block element from the top left to the bottom right. If more than one line is needed, the browser creates a new line, and expands the containing block element vertically to contain the inline elements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe margin collapse?

A

The top and bottom adjacent margins of two block elements in the normal page flow collapse to the size of the larger margin, or to the size of one margin if they are the same size.

17
Q

How to floated elements relate to the normal flow?

A

Floated elements sit on top of block elements and don’t affect their flow. However, the inline content respects the boundaries of a floated element and flows around it.

A floated element must have a specific width set to a value other than auto.

18
Q

What is the clear property used for?

A

The clear property is used to specify that no floated elements can be on the left or right (or both) of a block element. A block element with clear set will move down until it is free of the block element on its side.