Careeroza
Sizing & box-sizing
width, height, min and max
| Property | Use |
|---|---|
width / height | fixed or percentage size |
max-width | never wider than this; great for readable text (max-width: 65ch) and images (100%) |
min-height | at least this tall, can grow with content |
box-sizing: border-box
Example
With border-box, padding and border are included in the width, which makes layouts far easier. Both boxes have width: 200px:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
div { width: 200px; padding: 20px; border: 5px solid #282A35; margin-bottom: 10px; font-family: Arial; }
.content { box-sizing: content-box; background: #ffe8cc; }
.border { box-sizing: border-box; background: #d3f9d8; }
</style>
</head>
<body>
<div class="content">content-box: 250px wide</div>
<div class="border">border-box: 200px wide</div>
</body>
</html>Result
Tip: Most projects start with *, *::before, *::after { box-sizing: border-box; }.