Frontend Engineering, Volume II

CSS: Example 2b—Where Is Top, Left?

© 2013, Martin Rinehart

Create a Page

Use your template to create a new HTML page, with an <h1> that says you're looking for top, left.

Add the Markup

Add an outer <div>.

Add an inner <div>.

Style the <div>s

Use position: absolute; for both. Use borders and padding, all different sizes, all sides, for both. Contrasting colors will help you see your results. Experiment with your favorite border styles.

View the Result

Ours looks like this:

One div at the top, left corner of a containing div.


The chapter quiz will ask questions about the seemingly simple declaration { top: 0px }. This is only simple until you start to think about it!

Part of { top: 0px } refers to the selected element(s) and part to the container(s). top and 0px refer to either content, padding, border or margin areas of the selected element(s) or their container(s). Experiment with your example until you know what this declaration really means.

Good news: if you understand { top: 0px } you also understand { left: 0px }.

Example Code

If you get stuck building this example, take a look at our code. But don't use it as a crutch. Walk on your own.

Feedback: MartinRinehart at gmail dot com

# # #