freeCodeCamp/curriculum/challenges/english/01-responsive-web-design/css-grid/use-css-grid-units-to-chang...

2.5 KiB

id title challengeType videoUrl
5a9036ee38fddaf9a66b5d34 Use CSS Grid units to Change the Size of Columns and Rows 0 https://scrimba.com/p/pByETK/cvE8phd

Description

You can use absolute and relative units like px and em in CSS Grid to define the size of rows and columns. You can use these as well: fr: sets the column or row to a fraction of the available space, auto: sets the column or row to the width or height of its content automatically, %: adjusts the column or row to the percent width of its container. Here's the code that generates the output in the preview:
grid-template-columns: auto 50px 10% 2fr 1fr;
This snippet creates five columns. The first column is as wide as its content, the second column is 50px, the third column is 10% of its container, and for the last two columns; the remaining space is divided into three sections, two are allocated for the fourth column, and one for the fifth.

Instructions

Make a grid with three columns whose widths are as follows: 1fr, 100px, and 2fr.

Tests

tests:
  - text: '<code>container</code> class should have a <code>grid-template-columns</code> property that has three columns with the following widths: <code>1fr, 100px, and 2fr</code>.'
    testString: 'assert(code.match(/.container\s*?{[\s\S]*grid-template-columns\s*?:\s*?1fr\s*?100px\s*?2fr\s*?;[\s\S]*}/gi), ''<code>container</code> class should have a <code>grid-template-columns</code> property that has three columns with the following widths: <code>1fr, 100px, and 2fr</code>.'');'

Challenge Seed

<style>
  .d1{background:LightSkyBlue;}
  .d2{background:LightSalmon;}
  .d3{background:PaleTurquoise;}
  .d4{background:LightPink;}
  .d5{background:PaleGreen;}

  .container {
    font-size: 40px;
    width: 100%;
    background: LightGray;
    display: grid;
    /* modify the code below this line */

    grid-template-columns: auto 50px 10% 2fr 1fr;

    /* modify the code above this line */
    grid-template-rows: 50px 50px;
  }
</style>

<div class="container">
  <div class="d1">1</div>
  <div class="d2">2</div>
  <div class="d3">3</div>
  <div class="d4">4</div>
  <div class="d5">5</div>
</div>

Solution

var code = ".container {grid-template-columns: 1fr 100px 2fr;}"