“Light red” and “light green” background colors not working-CSS

  • HTML/CSS
  • Thread starter shivajikobardan
  • Start date
  • Tags
    Green
In summary, the conversation is about a student having trouble getting the background color to work in their CSS code. They share their code and ask for help, and another person suggests that the issue may be the spacing between the color words. The student expresses gratitude and then the conversation shifts to discussing the benefits of using a modern code editor like Visual Studio Code.
  • #1
shivajikobardan
674
54
TL;DR Summary
light red and light green background colors not working.
https://github.com/TheOdinProject/css-exercises/tree/main/foundations/02-class-id-selectors

I’m doing this assignment of The Odin Project. But the two colors aren’t working.
Here’s my code:
index.html:

Code:
<p class="odd">Number 1 - I'm a class!</p>
    <div ids="second">Number 2 - I'm one ID.</div>
    <p class="odd oddly-cool">Number 3 - I'm a class, but cooler!</p>
    <div id="four">Number 4 - I'm another ID.</div>
    <p class="odd">Number 5 - I'm a class!</p>

Style.css:
Code:
.odd{
    background-color: light red;
    font-family: Verdana, Dejavu Sans, sans-serif;
}
 
#second{
    color:blue;
    font-size:36px;
}
 
.oddly-cool{
    font-size:24px;
}
 
.four{
    background-color: light green;
    font-size:24px;
    font-weight: 700;
 
}

If I put rgb value, it will work though. So, what’s the issue? Doesnt’ background-color supports light as a value?
 
Technology news on Phys.org
  • #3
thank you. lightpink works and lightgreen.
 
  • Like
Likes jedishrfu
  • #4
HTML:
<h1>It's not hard to start HTML code with a [code=html] tag.</h1>
<!-- It makes code much easier to read. -->
<p>
  <strong style="color: red">Don't be lazy</strong>, help others to help you.
  <small>You can also select HTML as the language in the "Insert code" dialog.</small>
</p>

CSS:
/* It's not hard to start CSS code with a [code=css] tag.
 * It makes code much easier to read.
 * **Don't be lazy**, help others to help you.
 */
:root {
  --warning-color: rgb(255, 0, 0);
}
.warning {
  color: var(--warning-color);
}
 /*  You can also select CSS as the language in the "Insert code" dialog. */
 
  • Like
Likes Wrichik Basu
  • #5
You should also use a modern code editor such as Visual Studio Code which will often highlight mistakes: this is what it looks like:
1667377191086.png
 
  • Like
Likes jedishrfu and Mark44

FAQ: “Light red” and “light green” background colors not working-CSS

Why are my “light red” and “light green” background colors not showing up on my webpage?

There could be multiple reasons for this issue. The most common reason is that the color names you are using are not recognized by CSS. Instead of using “light red” and “light green”, try using the corresponding hex codes (#FFC0C0 for light red and #90EE90 for light green) or RGB values (rgb(255,192,192) for light red and rgb(144,238,144) for light green).

Can I use any color name I want in CSS?

No, CSS only recognizes certain color names that are part of the CSS3 specification. These color names are divided into 17 basic colors and 134 extended colors.

Why do some color names work in CSS, but others do not?

As mentioned before, CSS only recognizes certain color names that are part of the CSS3 specification. If a color name is not part of this specification, it will not work in CSS.

Are there any alternatives to using color names in CSS?

Yes, instead of using color names, you can also use hex codes or RGB values to specify colors in CSS. These options give you a wider range of colors to choose from and are more reliable than color names.

Is there a way to check if a color name is valid in CSS?

You can use an online color name checker tool or refer to the official CSS3 specification to see a list of all the valid color names. Additionally, most code editors will highlight invalid color names, making it easier for you to spot any errors.

Similar threads

Replies
7
Views
1K
Replies
5
Views
613
Replies
2
Views
1K
Replies
1
Views
3K
Replies
3
Views
3K
Replies
4
Views
2K
Replies
20
Views
4K
Replies
1
Views
3K
Replies
5
Views
2K
Back
Top