DEV Community

Cover image for My Journey Learning CSS - Display Properties, Shadows and Outlines๐Ÿš€ (Day-12)
Angshuman
Angshuman

Posted on

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! ๐Ÿš€

Top comments (0)