DEV Community

Cover image for My Journey Learning CSS - Display Properties, Shadows and Outlines🚀 (Day-12)
Angshuman
Angshuman

Posted on

3

My Journey Learning CSS - Display Properties, Shadows and Outlines🚀 (Day-12)

CSS (Cascading Style Sheets) is an essential part of web development, controlling the layout and design of a webpage. Today, we’ll explore key CSS concepts, including display properties, flexbox, grid, shadows, and outlines.

đź“Š 1. Understanding Display Properties

The display property in CSS determines how an element behaves in the layout. Here are some commonly used values:

a. display: none; vs visibility: hidden;

display: none; → Removes the element from the layout entirely.

visibility: hidden; → Hides the element but it still occupies space.

b. Block vs Inline vs Inline-Block

display: block; → Element takes the full width of its container (e.g., <div>, <p>).

display: inline; → Element only takes up as much space as needed (e.g., <span>, <a>).

display: inline-block; → Behaves like an inline element but allows setting width and height.

đź“Š 2. CSS Flexbox: Simplifying Layouts

Flexbox (display: flex;) is a powerful tool for arranging elements efficiently in a single dimension.

Key Flexbox Properties:

justify-content: → Aligns items horizontally.

center → Centers items.

space-between → Distributes space between items.

space-around → Spaces items evenly with padding.

align-items: → Aligns items vertically.

center → Centers items.

flex-start → Aligns items at the top.

flex-end → Aligns items at the bottom.

flex-direction: → Defines the direction of items.

row (default) → Items placed horizontally.

column → Items placed vertically.

Example of Flexbox:

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

Enter fullscreen mode Exit fullscreen mode

đź“Š 3. CSS Grid: Two-Dimensional Layout

Grid (display: grid;) provides a structured way to create complex layouts.

Key Grid Properties:

grid-template-columns: → Defines the number of columns.

grid-template-rows: → Defines the number of rows.

gap: → Adds spacing between items.

Example of CSS Grid:

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
Enter fullscreen mode Exit fullscreen mode

Image description

đź“Š 4. Adding Depth with Shadows

Shadows enhance the appearance of elements and text.

Box Shadow:

.box {
  box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.2);
}
Enter fullscreen mode Exit fullscreen mode

Text Shadow:

.text {
  text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
}
Enter fullscreen mode Exit fullscreen mode

đź“Š 5. Outlines: Highlighting Elements

Unlike borders, outlines do not take up space and are useful for accessibility.

Example of Outline:

.button {
  outline: 2px solid blue;
  outline-offset: 4px;
}

Enter fullscreen mode Exit fullscreen mode

Image description

🎯 Conclusion

Mastering CSS properties like display, flexbox, grid, shadows, and outlines helps create responsive and visually appealing layouts. By practicing these concepts, you’ll gain better control over your webpage designs.

What CSS topics would you like to explore next? Let me know in the comments! 🚀

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay