paint-brush
Intro Guide to CSS: Explore Your Boxby@devcronin

Intro Guide to CSS: Explore Your Box

by Zachary CroninAugust 21st, 2021
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Every div, image, and paragraph, etc.. are all boxes. Each of these boxes has the same attributes that can be altered to change how they are displayed. These attributes are margin, border, padding, and lastly your content. The most helpful resource to help you learn are the development tools that are built into every major browser, such as Chrome, Google Chrome, that can help you understand what is going on when you're developing a web site. At the bottom of the page, you can change one of the box model attributes you just learned about!

Company Mentioned

Mention Thumbnail
featured image - Intro Guide to CSS: Explore Your Box
Zachary  Cronin HackerNoon profile picture

Everything is a Box

When I first started web development, it was the above concept that really helped me to understand what was going on.

Every div, image, and paragraph, etc.. are all boxes. Each of these boxes has the same attributes that can be altered to change how they are displayed.

From outermost to innermost, these attributes are margin, border, padding, and lastly your content. Below is a graphic that demonstrates this.

Margin

Margin is very helpful to create space on the outside of a box. It is transparent and therefore meant to structure and space out your boxes without changing the inner content.

Border

The border is typically used to outline the padding and content. It doesn't have to be visible, but it can be if given a color. Defining the radius will also round edges of the visible content.

Padding

Padding is also transparent and is used for spacing like margin. However, the important distinction between the two is that padding creates space directly around the content.

If for instance, the content was a picture, more padding would actually shrink the image. It does not expand the total size of the box, whereas margin does.

Tips and Advice

If you are having a difficult time visualizing what is going on, don't worry because it's perfectly normal!

The most helpful resource to help you learn are the development tools that are built into every major browser.

How to use Google Chrome development tools:

1. Open chrome and find a website you want to inspect.

2. Now, either right-click and choose the inspect option, or hit F12.

3. You should notice a side panel pop up to the right. Inspect the webpage content and you will see the box model layers surrounding the content.

4. Now the fun of breaking things begins.

On the right panel you can change one of the box model attributes you just learned about!

Ex. Change padding from 20px to 40px. Reload the page when needed.

Have fun, good luck learning, and happy coding!

Also published on Hashnode