3

I'm in new to HTML/CSS. I can see that there are various ways of setting color code in a CSS style description i.e. by name e.g. yellow or by hex code #ffff00. I see there are also numeric equivalents of each color e.g. yellow has numeric equivalent as 255,255,0 but applying the below style on my body element has no effect at all:

My CSS:

body {
background-color: 255,255,0;
color: black !important;
}

Can someone help me on this?

5
  • 1
    use rgb(255,255,0) or rgba(255,255,255,0.9) Commented May 11, 2017 at 2:13
  • @ZaidBinKhalid you mean rgb(255,255,255) or rgba(255,255,255,.9) ?
    – Gabe Rogan
    Commented May 11, 2017 at 2:14
  • 1
    @ZaidBinKhalid Cool. This works :) Thanks for your quick response. I used rgb(255,255,0) You might want to add this as an answer.
    – RBT
    Commented May 11, 2017 at 2:14
  • @RBT You very welcome. Commented May 11, 2017 at 2:17
  • I tried googling the same but no luck. I don't know about your googling skills, but if I type CSS RGB, I get back 20,200,000 results with all links on the first page pointing to exactly what you're after, that is the CSS rgb() function. Commented May 11, 2017 at 2:29

4 Answers 4

7

Like this

body {
    background-color: rgb(255,255,0);
}

To add opacity, use rgba. Where 1 is 100% opacity.

body {
    background-color: rgba(255,255,0, 1);
}
2

you need to add this rule to your css rgb(0,0,0) or rgba(0,0,0,0.5) to opacity.

body {
    background-color: rgb(255,255,0);
    color: rgba(0,0,0,0.7);
}
2

rgba(255,255,0,1) To add opacity, use rgba. Where 1 is 100% opacity.

.body {
background-color: rgb(255,255,0);
color: black !important;
padding:25px;
}
<div class="body"></div>

1

.body {
background-color: rgb(255,255,0);
color: black !important;
padding:25px;
}
<div class="body"></div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.