© Joe Attardi 2020
J. AttardiModern CSShttps://doi.org/10.1007/978-1-4842-6294-8_7

7. Layout and Positioning

Joe Attardi1 
(1)
Billerica, MA, USA
 

We’ve looked a lot at how to style with CSS. Let’s switch gears now and look at how to lay out and position elements.

Padding

The padding is the spacing between an element’s content and its border. By default, most elements have zero padding. An element’s padding is not inherited by its children.

Padding can be specified with any size unit or with a percentage. When padding is specified as a percentage, the value used is the given percentage of the containing block’s width. Listing 7-1 has a simple example of this.
<style>
  .container {
    border: 1px solid red;
    width: 200px;
  }
  .inner {
    padding: 25%; ...

Get Modern CSS: Master the Key Concepts of CSS for Modern Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.