Week 6: More CSS Layout

The sections in this reading on position, z-index, and overflow
draw heavily from a page by David Humphrey.

Flexbox Layout

I have not written any material on flexible box layout (flexbox) in CSS, but we need to learn more about it than we saw in class Thursday.

MDN's tutorial material on flexbox is quite good. Read its chapter Flexbox Layout up to and including the section Columns or rows?

If you'd like to see another example, read Typical Use Cases of Flexbox, which applies flexbox to solve a few common layout problems.

Using the position Property to Place Items in Precise Locations

Many desires require more sophisticated element positioning than simply allowing everything to flow. Sometimes we desire precise control over where elements appear on the page, and how the page reacts to scrolling or movement.

To accomplish this kind of positioning, we can use the CSS position property to override the defaults provided by the browser. Its possible values include:

Using the z-index Property to Position Elements on Top of Other Elements

In addition to controlling how elements are positioned in the two-dimensional x-y plane of the screen, we can also stack elements on top of each other in different layers. We achieve this through use of the z-index property.

The z-index is an integer, positive or negative, that indicates the level at which the element should be placed in a stack between the screen and the user. The default stack level is 0, so using a positive z-index will place an element on top of anything not given a z-index.

The z-index is often used together with position to place elements in arbitrary positions on top of other elements. For example, YouTube uses this combination to show a video's running time in the lower righthand corner of the thumbnail image shown in its search results.

Using the overflow Property to Layout of Content Bigger Than its Container

When the contents of an element are too large to be displayed in the space available, we have options for how the browser will display the extra content. To do this, we work with the overflow property. It lets us control the overflow-x and overflow-y properties of the element in a single declarations. Possible values of the property include: