My Journey Learning CSS - Display Properties, Shadows and OutlinesπŸš€ (Day-12)

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;
}

πŸ“Š 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;
}

πŸ“Š 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);
}

Text Shadow:

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

πŸ“Š 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;
}

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

Β