# Background Color to a Div Element

**URL:** <https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930>\
**Category:** General\
**Created:** [October 30, 2017, 4:38am UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930 "2017-10-30T04:38:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aet9rat6](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aet9rat6/32/69809_2.png) [@aet9rat6](https://forum.freecodecamp.org/u/aet9rat6)\
**Post date:** [October 30, 2017, 4:38am UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930/1 "2017-10-30T04:38:20Z")

</div>

**Tell us what’s happening:**

The app looks correct but will not allow me to go on when i click run test. What am i doing wrong?

**Your code so far**

```auto
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet" type="text/css">
<style>
  .red-text {
    color: red;
  }

  h2 {
    font-family: Lobster, Monospace;
  }

  p {
    font-size: 16px;
    font-family: Monospace;
  }

  .thick-green-border {
    border-color: green;
    border-width: 10px;
    border-style: solid;
    border-radius: 50%;
  }

  .smaller-image {
    width: 100px;
  }
   div { 
     background-color: silver;}
    
</style>

<h2 class="red-text">CatPhotoApp</h2>

<p>Click here for <a href="#">cat photos</a>.</p>

<a href="#"><img class="smaller-image thick-green-border" alt="A cute orange cat lying on its back. " src="https://bit.ly/fcc-relaxing-cat"></a>

<div class="silver:background;">
  <p>Things cats love:</p>
  <ul>
    <li>cat nip</li>
    <li>laser pointers</li>
    <li>lasagna</li>
  </ul>
  <p>Top 3 things cats hate:</p>
  <ol>
    <li>flea treatment</li>
    <li>thunder</li>
    <li>other cats</li>
  </ol>
</div>

<form action="/submit-cat-photo">
  <label><input type="radio" name="indoor-outdoor" checked> Indoor</label>
  <label><input type="radio" name="indoor-outdoor"> Outdoor</label>
  <label><input type="checkbox" name="personality" checked> Loving</label>
  <label><input type="checkbox" name="personality"> Lazy</label>
  <label><input type="checkbox" name="personality"> Energetic</label>
  <input type="text" placeholder="cat photo URL" required>
  <button type="submit">Submit</button>
</form>

```

**Your browser information:**

Your Browser User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36`.

**Link to the challenge:**  
[https://www.freecodecamp.org/challenges/give-a-background-color-to-a-div-element](https://www.freecodecamp.org/challenges/give-a-background-color-to-a-div-element)

---

<div class="post-metadata">

**Author:** ![alecaceaes](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alecaceaes/32/160822_2.png) [@alecaceaes](https://forum.freecodecamp.org/u/alecaceaes)\
**Post date:** [October 30, 2017, 4:43am UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930/2 "2017-10-30T04:43:46Z")

</div>

If you want to add an inline style on a div. Your code should be like

`<div style="background-color: silver;"></div>`

or If you want to add a class with the ff style

```auto
<style>
.silver-bg {
background-color: silver;
}

</style>
<div class="silver-bg"></div>

```

---

<div class="post-metadata">

**Author:** ![aet9rat6](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aet9rat6/32/69809_2.png) [@aet9rat6](https://forum.freecodecamp.org/u/aet9rat6)\
**Post date:** [October 30, 2017, 4:54am UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930/3 "2017-10-30T04:54:03Z")

</div>

But what i have is showing as correct but it wont allow me to continue, why does that do that?  
What it says to do doesn’t work

---

<div class="post-metadata">

**Author:** ![aet9rat6](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/aet9rat6/32/69809_2.png) [@aet9rat6](https://forum.freecodecamp.org/u/aet9rat6)\
**Post date:** [October 30, 2017, 5:01am UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930/4 "2017-10-30T05:01:27Z")

</div>

My class is the same as yours except I didnt close it.  
But tried that and it will allow me to go on but doesn’t show the silver bg  
I am almost sure it should show a silver bg,This is crazy

---

<div class="post-metadata">

**Author:** ![alecaceaes](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/alecaceaes/32/160822_2.png) [@alecaceaes](https://forum.freecodecamp.org/u/alecaceaes)\
**Post date:** [October 30, 2017, 8:34am UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930/5 "2017-10-30T08:34:49Z")

</div>

I think it renders the right color because of this line in your code.

```auto
div { 
     background-color: silver;
}

```

but this line has incorrect syntax

```auto
<div class="silver:background;">

```

You should put here the **name of the class** not the style.

The goal of the lesson is to **create** a class called **silver-background** with the **background-color of silver** and **assign this class to your div element.**

You may have been seeing the same result, but it is incorrect because it says you need to create a class that will give a silver background, not explicitly style a div with a silver background.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 6:00pm UTC](https://forum.freecodecamp.org/t/background-color-to-a-div-element/155930/6 "2021-01-16T18:00:17Z")

</div>


