Card: Styling boxes

Styling Boxes

Craft your orderly realm

With CSS, you can transform your boxes into enchanted masterpieces, imbuing them with structure and style that even the most finicky wizard would admire. Elegant borders? Check. Padding so balanced it could impress an elf? Absolutely. Margins that bring harmony to the chaos of content? Naturally. Your layout will look like it’s been orchestrated by a grandmaster of magical design.

But wait, there’s more! Breathe life into your boxes with vibrant backgrounds, flowing gradients, or even textures and images that add depth and personality to your page. Sprinkle in some shadows to make your boxes hover like enchanted relics, and round those edges for a softer, more harmonious aesthetic. With just a touch of effort, you’ll turn humble containers into dazzling showcases that present your content in all its spellbinding glory.

Backgrounds & Styles for divs

Images, gradients, shadows – turn simple blocks into real eye-catchers!

Token: placing Boxes

Placing Boxes

Set the stage for your boxes

Assign your boxes a fixed size, and they’ll obediently scoot to the left. But with the magical incantation of margin: auto, you can summon them to center or glide to the right. Nobody wants text sprawling across a screen like a rogue spell. This technique conjures a balanced, harmonious layout that even critical sorcerers applaud.

div {
    max-width: 1200px;
    margin: 0 auto;
    height: 80vh;
}

The container has a fixed width of 1200px. Using margin: 0 auto;, it is centered horizontally with no space at the top and bottom. Additionally, it occupies 80% of the browser window’s height.

Token: gradient

Gradient

Create smooth color transitions

With CSS gradients, you can create smooth transitions between colors, making backgrounds as magical as they are beautiful. Linear or radial, they add depth and charm to your designs. Use Online-Generators to craft and adjust them effortlessly—it’s as easy as a flick of your wand!

.box {
    background: linear-gradient(to right, #ff7e5f, #feb47b);
}

This spell creates a gradient from left to right, starting with warm pink and fading into soft orange, like a sunrise melting into a peachy glow.

Token: border-radius

Border-Radius

Round off your boxes

With the CSS property border-radius, you can soften sharp edges into smooth, rounded corners, giving your boxes an elegant, polished look. Whether slightly rounded or fully circular, this simple tweak can make your elements shine with style.

.box {
    border-radius: 1rem;
}

Use border-radius to round corners your way. You can round opposite corners, like this: border-radius: 1rem 0;, or give each corner its own curve, like this: border-radius: 8px 5px 0 25px;.

Token: background-images

Background Images

Add visual depth to your website

CSS background images bring depth and visual appeal to your designs. They add stunning effects and can be used in countless ways to make your website come alive with creativity.

.box {
    background-image: url('bild.jpg');
}

background-image: sets a background for your container.

Styles for Background Images

Precise control over your design

.box {
    background-image: url('image.jpg');
    background-position: center;
}

Define the position of your background image within an element. Values like center, top, bottom, left, and right, or units like percentages, allow for precise alignment.

.box {
    background-image: url('image.jpg');
    background-size: cover;
}

Set the size of the background image. Use values like cover, contain, or specific dimensions (e.g., 100px 50px) to control how the image is scaled.

.box {
    mix-blend-mode: overlay;
}

Control how the background image blends with its color. With values like multiply, screen, or overlay, you can create dynamic effects. Explore more blend modes on mdn for inspiration.

.box {
    background-image: url('image.jpg');
    background-repeat: no-repeat;
}

Decide if and how the background image repeats. Options like no-repeat, repeat-x, or repeat-y let you choose horizontal, vertical, or no repetition.

.box {
    background-image: url('image.jpg');
    background-attachment: fixed;
}

Choose whether the background image stays fixed or moves with the content. With fixed, the image remains stationary, while scroll moves it along with the page.

.container {
    width: 100%;
    height: 400px;
    background: #000 url('img.jpg') no-repeat center/cover;
    mix-blend-mode: multiply;
}

In the shorthand notation for background, multiple properties are combined: background color (#000), image source (url('img.jpg')), repeat behavior (no-repeat), position (center), and scaling (cover) are all defined in a single line.

CSS
.box1 {
    max-width: 1200px;
    margin: 0 auto;
    height: 50vh;
    background-color: purple;
}

.box2 {
    max-width: 1200px;
    margin: 0 auto;
    height: 50vh;
    background: linear-gradient(to bottom, forestgreen, lightgreen);
    border-radius: 15px;
}

.box3 {
    background-image: url(img/waterfall.jpg);
    height: 50vh;
    background-size: cover;
    background-position: center;
}

.box4 {
    background-image:
        linear-gradient(rgba(0, 0, 0, 0.52), rgba(255, 255, 255, 0.251)),
        url('assets/img/unicorn-large.jpg');
    height: 70vh;
    background-size: contain;
    background-position: right;
    background-repeat: no-repeat;
}
Scroll to Top