Careeroza
Backgrounds
Background Properties
| Property | Example |
|---|---|
background-color | #f1f1f1 |
background-image | url("photo.jpg") |
background-repeat | no-repeat, repeat-x |
background-size | cover (fill, may crop), contain (fit, may leave space) |
background-position | center, top right, 50% 20% |
background | shorthand for all of the above |
Hero Image Example
Example
A full-width banner with a darkened background image and centered text:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
.hero {
height: 180px;
background: linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.45)),
url("https://picsum.photos/id/1018/800/300") center / cover no-repeat;
color: white;
display: flex;
align-items: center;
justify-content: center;
font: bold 28px Arial, sans-serif;
}
</style>
</head>
<body>
<div class="hero">Learn CSS</div>
</body>
</html>Result