TutorialsCSSStyling & Layout
Share:

Styling & Layout

intermediate

What You'll Learn

    Theory

    Styling and layout are where CSS truly shines. After mastering fundamentals, the next step is understanding how to control text appearance and build multi-dimensional page layouts.

    Typography & Text Styling

    Good typography is the foundation of great web design. Key properties include font-family, font-size, font-weight, line-height, text-align, text-transform, and letter-spacing. Use web fonts (Google Fonts or @font-face) for custom typefaces. Always provide fallback fonts and end with a generic family like sans-serif.

    The Display Property

    The display property controls how an element behaves in the document flow:

    • block — takes full width, starts on a new line
    • inline — flows within text, only takes needed space
    • inline-block — inline but accepts width/height and margins
    • none — removes the element visually
    • flex — creates a flex container for one-dimensional layouts
    • grid — creates a grid container for two-dimensional layouts

    Positioning

    The position property controls element placement:

    • static — normal flow (default)
    • relative — offset from normal position, original space preserved
    • absolute — removed from flow, positioned relative to nearest positioned ancestor
    • fixed — positioned relative to viewport, stays on scroll
    • sticky — hybrid that sticks at a threshold

    Layout Approaches

    Flexbox excels at one-dimensional layouts (rows or columns). It distributes space and aligns items along the main and cross axes.

    CSS Grid handles two-dimensional layouts (rows and columns simultaneously). It provides precise control over both dimensions with features like grid-template-areas and fr units.

    Responsive thinking means designing for all screen sizes. Use relative units (%, rem, vw/vh), fluid grids, and media queries to adapt layouts. Mobile-first design starts with base styles for small screens, then adds complexity at larger breakpoints.

    Why this matters

    Layout and typography are what give a website its visual identity and usability. Flexbox and Grid have revolutionized how developers build responsive designs that work across every screen size.

    What's next

    In the next lessons, you'll dive deeper into each topic with hands-on examples and exercises.

    Practical Example

    Example: Basic Layout with Flexbox and Grid
    html

    Exercises

    Build a Responsive Card Grid

    medium

    Create a page with a Flexbox navigation bar and a CSS Grid of cards. The navbar should have a logo on the left and three links on the right. The grid should display 4 cards with titles and descriptions. Use gap for spacing between items.

    Expected Output:

    A page with a horizontal navbar (logo left, links right) and a responsive grid of 4 cards. Cards sit in 2+ columns on wider screens and stack on narrow screens.

    Mini Quiz

    Mini Quiz