CSS Exam 3: Advanced Layout and Intermediate (Composite Exercises)

CSS Exam 3: Advanced Layout and Intermediate

This exam contains 13 comprehensive exercises. Each exercise includes multiple requirements that should be completed together in one code snippet.
Exercises 1-10: Beginner | Exercises 11-13: Intermediate

Exercise 1 CSS Grid Basics

Create a grid with the following specs:

  1. Make the container (.grid-container) display as a grid (display: grid).
  2. Split the grid into 3 equal columns (1fr 1fr 1fr).
  3. Add a 20px gap between columns and rows.
Solution
.grid-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr; /* or repeat(3, 1fr) */
    gap: 20px;
}
Exercise 2 Grid Placement

Control the placement of items:

  1. Make (.item1) span from column 1 to column 3 (two columns wide).
  2. Make (.item2) span two full rows.
Solution
.item1 {
    grid-column: 1 / 3; /* or span 2 */
}

.item2 {
    grid-row: span 2;
}
Exercise 3 Grid Areas

Use `grid-template-areas` to lay out a page:

  1. Define the areas: header, sidebar, main, footer.
  2. Make the header and footer span full width.
  3. Place the sidebar on the left and main on the right.
Solution
.container {
    display: grid;
    grid-template-areas:
        "header header"
        "sidebar main"
        "footer footer";
}

.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
Exercise 4 Media Queries

Make the layout responsive:

  1. By default, set the page background to white.
  2. When the screen is below 768px (mobile), set a light blue background.
  3. When the screen is wider than 1200px, set the font size to 20px.
Solution
body {
    background-color: white;
}

@media (max-width: 768px) {
    body {
        background-color: lightblue;
    }
}

@media (min-width: 1200px) {
    body {
        font-size: 20px;
    }
}
Exercise 5 Advanced Flexbox (Order & Grow)

Control order and size of flex items:

  1. Make (.item-last) appear first (visual order).
  2. Make (.item-grow) fill the remaining space (flex-grow: 1).
Solution
.item-last {
    order: -1;
}

.item-grow {
    flex-grow: 1;
}
Exercise 6 Responsive Images

Make the image adapt to its container:

  1. Set max-width to 100% so it doesn't overflow.
  2. Set height to auto to preserve aspect ratio.
  3. Use object-fit: cover to fill a fixed-size square without distortion.
Solution
img {
    max-width: 100%;
    height: auto;
}

.profile-pic {
    width: 200px;
    height: 200px;
    object-fit: cover;
}
Exercise 7 Card Layout

Create a responsive card grid:

  1. Use Grid with auto-fit repeating columns.
  2. Set a minimum column width of 250px and max of 1fr (minmax).
  3. This ensures cards wrap automatically based on screen size.
Solution
.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}
Exercise 8 Responsive Element Visibility

Control element visibility by device:

  1. Hide the sidebar (.sidebar) on mobile screens (under 600px).
  2. Show the menu button (.menu-btn) only on mobile (hide it on large screens).
Solution
/* Hide sidebar on mobile */
@media (max-width: 600px) {
    .sidebar { display: none; }
}

/* Hide menu button on large screens */
.menu-btn { display: none; }

/* Show menu button on mobile */
@media (max-width: 600px) {
    .menu-btn { display: block; }
}
Exercise 9 Grid Alignment

Align grid content:

  1. Center the grid itself horizontally (justify-content: center).
  2. Center items within their cells vertically (align-items: center).
Solution
.grid-container {
    display: grid;
    justify-content: center; /* align the grid */
    align-items: center; /* align items within cells */
}
Exercise 10 Mixed Layout (Flex inside Grid)

Combine both techniques:

  1. You have a card (.card) that is a Grid item.
  2. Make the card content use Flexbox to space title and button apart (space-between) in a column.
Solution
.card {
    /* This element is a Grid item, but a Flex parent for its content */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}
Exercise 11 CSS Filters Intermediate

Use CSS filters for visual effects:

  1. Add a blur effect of 5px to an image.
  2. Make the image grayscale at 100%.
  3. Add brightness 150% on hover.
  4. Combine multiple filters (blur + brightness + contrast).
Solution
/* Blur effect */
.blur-image {
    filter: blur(5px);
}

/* Grayscale */
.grayscale-image {
    filter: grayscale(100%);
}

/* Brightness on hover */
.bright-on-hover {
    transition: filter 0.3s ease;
}

.bright-on-hover:hover {
    filter: brightness(150%);
}

/* Combine multiple filters */
.multi-filter {
    filter: blur(2px) brightness(120%) contrast(110%);
}

/* Advanced example: sepia effect */
.vintage-photo {
    filter: sepia(80%) contrast(120%) brightness(90%);
}
Exercise 12 Clip-path Shapes Intermediate

Use clip-path to create custom shapes:

  1. Clip an image into a circle.
  2. Clip an element into a triangle using polygon.
  3. Create a hexagon shape using clip-path.
  4. Add a transition effect when the shape changes.
Solution
/* Circle */
.circle-clip {
    clip-path: circle(50%);
}

/* Triangle */
.triangle-clip {
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}

/* Hexagon */
.hexagon-clip {
    clip-path: polygon(
        50% 0%,
        100% 25%,
        100% 75%,
        50% 100%,
        0% 75%,
        0% 25%
    );
}

/* Transition effect */
.shape-morph {
    clip-path: circle(30%);
    transition: clip-path 0.5s ease;
}

.shape-morph:hover {
    clip-path: circle(50%);
}

/* Extra shapes */
.star-clip {
    clip-path: polygon(
        50% 0%,
        61% 35%,
        98% 35%,
        68% 57%,
        79% 91%,
        50% 70%,
        21% 91%,
        32% 57%,
        2% 35%,
        39% 35%
    );
}
Exercise 13 Advanced Custom Properties (Advanced CSS Variables) Intermediate

Use CSS variables in an advanced way:

  1. Create a full color system using :root variables.
  2. Create spacing scale variables like --space-xs, --space-sm, --space-md.
  3. Use calc() with variables to create dynamic values.
  4. Create a theme switcher by overriding variables in another class.
Solution
/* Color system */
:root {
    /* Colors */
    --color-primary: #007bff;
    --color-secondary: #6c757d;
    --color-success: #28a745;
    --color-danger: #dc3545;
    --color-bg: #ffffff;
    --color-text: #212529;
    
    /* Spacing Scale */
    --space-xs: 0.25rem;  /* 4px */
    --space-sm: 0.5rem;   /* 8px */
    --space-md: 1rem;     /* 16px */
    --space-lg: 1.5rem;   /* 24px */
    --space-xl: 2rem;     /* 32px */
    
    /* Typography */
    --font-size-base: 16px;
    --font-size-lg: calc(var(--font-size-base) * 1.25);
    --font-size-xl: calc(var(--font-size-base) * 1.5);
}

/* Use variables */
.button {
    background-color: var(--color-primary);
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-base);
}

/* Dark Theme */
.dark-theme {
    --color-bg: #1a1a1a;
    --color-text: #ffffff;
    --color-primary: #4dabf7;
}

/* Use calc with variables */
.container {
    padding: calc(var(--space-md) * 2);
    margin-bottom: calc(var(--space-lg) + var(--space-sm));
}

/* Grid system using variables */
:root {
    --grid-columns: 12;
    --grid-gap: var(--space-md);
}

.grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns), 1fr);
    gap: var(--grid-gap);
}
Smart Editor

Write code and see the result instantly

Try it free