Search code examples
htmlcsscss-variables

How would I go about solving this problem on freecodecamp.org? - css related


The .red-box rule should include a fallback with the background set to red immediately before the existing background declaration.

Here is the pre-generated code:

:root {
  --red-color: red;
}

.red-box {
  background: var(--red-color);
  height: 200px;
  width: 200px;
}
<div class="red-box"></div>


Solution

  • I believe what they are looking for is for you to set background: red; immediately before background: var(--red-color); so that if the latter fails, background: red; will be used.

    :root {
      --red-color: red;
    }
    
    .red-box {
      background: red;
      background: var(--red-color);
      height: 200px;
      width: 200px;
    }
    <div class="red-box"></div>