Shaping elements in CSS

In web design, the visual appeal doesn't solely rely on colors or typography; the shape and depth of elements play a pivotal role in guiding user attention and improving the overall aesthetics. 

This lesson will focus on two powerful CSS properties: border-radius and box-shadow. These properties allow you to transform the sharp rectangular edges of an HTML element into softer, more rounded shapes, and give depth or "lift" elements off the page, respectively.

Desired Outcomes:

  • Understand the basic concepts of the border-radius and box-shadow properties and understand their importance in enhancing web design aesthetics.
  • Apply both properties effectively to create rounded edges, and add both outer and inner shadows to web elements.

Border Radius

The border-radius property is used to add rounded corners to an element. You can specify one value for all four corners or provide individual values for each corner.

Uniform Border Radius:

div {
    border-radius: 20px; /* All 4 corners will have the same radius */
}

Individual Border Radius:

div {
    /* Clockwise from top-left: top-left, top-right, bottom-right, bottom-left */
    border-radius: 20px 10px 15px 5px; 
}

You can even create elliptical shapes by defining two distinct values for each corner (horizontal and vertical radii).

div {
    border-radius: 50% 25%;
}

Box Shadow

The box-shadow property is used to cast a shadow behind an element. It's versatile and can be used to produce various effects like depth, focus, or even inner shadows.

The property generally has the following values: horizontal offset, vertical offset, blur radius, spread radius, and color.

Simple Shadow:

button {
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
    /* Horizontal offset: 5px, 
       Vertical offset: 5px, 
       Blur: 15px, 
       Color: semi-transparent black */
}

Inner Shadow:

button.active {
    /* The 'inset' value makes the shadow appear inside the element */
    box-shadow: inset 0 0 10px #888; 
}

The border-radius and box-shadow properties are potent tools in your CSS arsenal. They allow for nuanced changes in design, adding depth, focus, and overall visual appeal. Experiment with different values, combine them, and you'll see how these simple properties can transform your designs from flat and dull to dynamic and engaging.

-75%

Time remaining:
days 00: 00: 00

Learn to code HTML & CSS

From Zero to Hero

Check out this course on Udemy, now at 75% off! Inside this interactive course, I will teach you how to develop websites from scratch moving from beginner to advanced concepts. I take time to explain every detail and finish off by building some real-world websites.

HTML & CSS: From Zero to Hero
Learn to code HTML & CSS

-75%

Time remaining:
days 00: 00: 00

Learn to code JavaScript & jQuery

From Zero to Hero

Check out this course on Udemy, now at 75% off! Inside this interactive course, I will teach you how to develop components from scratch moving from beginner to advanced concepts. I take time to explain every detail and finish off by building some real-world reusable components.

JavaScript & jQuery: From Zero to Hero
Learn to code JavaScript & jQuery

-75%

Time remaining:
days 00: 00: 00

Learn Frontend Web Development

From Zero to Hero

Check out this course on Udemy, now at 75% off! A bundle of the previous two courses. Inside this interactive course, I will teach you how to develop websites from scratch moving from beginner to advanced concepts. I take time to explain every detail and finish off by building some real-world websites.

Frontend Web Development: From Zero to Hero
Learn Frontend Web Development