CSS Transition: Opacity vs changing Background-Color?Set cellpadding and cellspacing in CSS?How do I give text or an image a transparent background using CSS?Is there a CSS parent selector?Change an HTML5 input's placeholder color with CSSTransitions on the display: propertyHow can I transition height: 0; to height: auto; using CSS?CSS opacity only to background color, not the text on it?Why does HTML think “chucknorris” is a color?CSS Background OpacityIs it possible to apply CSS to half of a character?

Is bounce rate of a website a ranking factor?

Adding command shortcuts to bin

How did the Venus Express detect lightning?

Can a Tiefling have more than two horns?

How can internet speed be 10 times slower without a router than when using a router?

Why did the Apollo 13 crew extend the LM landing gear?

Manager is threatening to grade me poorly if I don't complete the project

Is “snitty” a popular American English term? What is its origin?

How to increase the size of the cursor in Lubuntu 19.04?

Has the Hulk always been able to talk?

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

Refinish or replace an old staircase

In Russian, how do you idiomatically express the idea of the figurative "overnight"?

Word meaning as function of the composition of its phonemes

How do LIGO and VIRGO know that a gravitational wave has its origin in a neutron star or a black hole?

Should I decline this job offer that requires relocating to an area with high cost of living?

What does this wavy downward arrow preceding a piano chord mean?

How to write a 12-bar blues melody

How can I get people to remember my character's gender?

Find the cheapest shipping option based on item weight

Floor of Riemann zeta function

US born but as a child of foreign diplomat

What is the solution to this metapuzzle from a university puzzling column?

Why does sound not move through a wall?



CSS Transition: Opacity vs changing Background-Color?


Set cellpadding and cellspacing in CSS?How do I give text or an image a transparent background using CSS?Is there a CSS parent selector?Change an HTML5 input's placeholder color with CSSTransitions on the display: propertyHow can I transition height: 0; to height: auto; using CSS?CSS opacity only to background color, not the text on it?Why does HTML think “chucknorris” is a color?CSS Background OpacityIs it possible to apply CSS to half of a character?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am curious if there is an industry standard for transitioning colour since there are multiple ways to accomplish the desired transition effect.



There are multiple ways to make a particular colour brighter or darker to indicate to the user that the element is intractable.



For example, if you have a p tag and you want to add a hover over effect you could:



HTML



<div><p> P tag text </p></div>



CSS v1 using opacity



div 
background-color:black;


p
color: white;
opacity: 0.8;
transition: opacity 0.2s ease-in-out;


p:hover
opacity: 1;




CSS v2 using colour



div 
background-color:black;


p
color: #ccc;
transition: color 0.2s ease-in-out;


p:hover
color: #fff;



As far I'm aware both methods provide similar results however, I am still curious whether or not there is a correct way to do this kind of thing.










share|improve this question






















  • There is more than the ways you provided and since it's working then it's correct. There is never one way to achieve something.

    – Temani Afif
    Mar 23 at 0:34

















0















I am curious if there is an industry standard for transitioning colour since there are multiple ways to accomplish the desired transition effect.



There are multiple ways to make a particular colour brighter or darker to indicate to the user that the element is intractable.



For example, if you have a p tag and you want to add a hover over effect you could:



HTML



<div><p> P tag text </p></div>



CSS v1 using opacity



div 
background-color:black;


p
color: white;
opacity: 0.8;
transition: opacity 0.2s ease-in-out;


p:hover
opacity: 1;




CSS v2 using colour



div 
background-color:black;


p
color: #ccc;
transition: color 0.2s ease-in-out;


p:hover
color: #fff;



As far I'm aware both methods provide similar results however, I am still curious whether or not there is a correct way to do this kind of thing.










share|improve this question






















  • There is more than the ways you provided and since it's working then it's correct. There is never one way to achieve something.

    – Temani Afif
    Mar 23 at 0:34













0












0








0








I am curious if there is an industry standard for transitioning colour since there are multiple ways to accomplish the desired transition effect.



There are multiple ways to make a particular colour brighter or darker to indicate to the user that the element is intractable.



For example, if you have a p tag and you want to add a hover over effect you could:



HTML



<div><p> P tag text </p></div>



CSS v1 using opacity



div 
background-color:black;


p
color: white;
opacity: 0.8;
transition: opacity 0.2s ease-in-out;


p:hover
opacity: 1;




CSS v2 using colour



div 
background-color:black;


p
color: #ccc;
transition: color 0.2s ease-in-out;


p:hover
color: #fff;



As far I'm aware both methods provide similar results however, I am still curious whether or not there is a correct way to do this kind of thing.










share|improve this question














I am curious if there is an industry standard for transitioning colour since there are multiple ways to accomplish the desired transition effect.



There are multiple ways to make a particular colour brighter or darker to indicate to the user that the element is intractable.



For example, if you have a p tag and you want to add a hover over effect you could:



HTML



<div><p> P tag text </p></div>



CSS v1 using opacity



div 
background-color:black;


p
color: white;
opacity: 0.8;
transition: opacity 0.2s ease-in-out;


p:hover
opacity: 1;




CSS v2 using colour



div 
background-color:black;


p
color: #ccc;
transition: color 0.2s ease-in-out;


p:hover
color: #fff;



As far I'm aware both methods provide similar results however, I am still curious whether or not there is a correct way to do this kind of thing.







css colors css-transitions opacity






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 23 at 0:07









Dzyuv001Dzyuv001

88215




88215












  • There is more than the ways you provided and since it's working then it's correct. There is never one way to achieve something.

    – Temani Afif
    Mar 23 at 0:34

















  • There is more than the ways you provided and since it's working then it's correct. There is never one way to achieve something.

    – Temani Afif
    Mar 23 at 0:34
















There is more than the ways you provided and since it's working then it's correct. There is never one way to achieve something.

– Temani Afif
Mar 23 at 0:34





There is more than the ways you provided and since it's working then it's correct. There is never one way to achieve something.

– Temani Afif
Mar 23 at 0:34












1 Answer
1






active

oldest

votes


















1














The main thing you should realize is that opacity affects an entire element and all its descendants, whereas color and background-color do not.



In your simple example, white text with reduced opacity on a solid black background looks gray, so the visual effect is basically the same as changing the color from gray to pure white.



But in any more complicated example – say, the background of your paragraph's parent div is an image rather than a solid color, or you're using opacity on an element that contains other elements and not merely on text – what you're gonna end up with is things that truly look see-through. That also may mean that text becomes harder to read.



So the answer is less about there being any particular industry standard and more about choosing the right tool for the job. If you just want to make some text a lighter color, transition color itself. If you want to make things see-through, use opacity.



That's the theory, anyway, but in real life sometimes it's not that clean cut. Maybe a designer gives you a mockup with text that's color: #C44242; opacity: 0.87 on top of a solid-colored background that's background-color: #B48927. You could compute what the opaque version of that text color would be, but it may not be worth your time to do so. The world won't end if you just stick with opacity.






share|improve this answer


















  • 1





    Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

    – Dzyuv001
    Mar 23 at 0:53











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309310%2fcss-transition-opacity-vs-changing-background-color%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The main thing you should realize is that opacity affects an entire element and all its descendants, whereas color and background-color do not.



In your simple example, white text with reduced opacity on a solid black background looks gray, so the visual effect is basically the same as changing the color from gray to pure white.



But in any more complicated example – say, the background of your paragraph's parent div is an image rather than a solid color, or you're using opacity on an element that contains other elements and not merely on text – what you're gonna end up with is things that truly look see-through. That also may mean that text becomes harder to read.



So the answer is less about there being any particular industry standard and more about choosing the right tool for the job. If you just want to make some text a lighter color, transition color itself. If you want to make things see-through, use opacity.



That's the theory, anyway, but in real life sometimes it's not that clean cut. Maybe a designer gives you a mockup with text that's color: #C44242; opacity: 0.87 on top of a solid-colored background that's background-color: #B48927. You could compute what the opaque version of that text color would be, but it may not be worth your time to do so. The world won't end if you just stick with opacity.






share|improve this answer


















  • 1





    Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

    – Dzyuv001
    Mar 23 at 0:53















1














The main thing you should realize is that opacity affects an entire element and all its descendants, whereas color and background-color do not.



In your simple example, white text with reduced opacity on a solid black background looks gray, so the visual effect is basically the same as changing the color from gray to pure white.



But in any more complicated example – say, the background of your paragraph's parent div is an image rather than a solid color, or you're using opacity on an element that contains other elements and not merely on text – what you're gonna end up with is things that truly look see-through. That also may mean that text becomes harder to read.



So the answer is less about there being any particular industry standard and more about choosing the right tool for the job. If you just want to make some text a lighter color, transition color itself. If you want to make things see-through, use opacity.



That's the theory, anyway, but in real life sometimes it's not that clean cut. Maybe a designer gives you a mockup with text that's color: #C44242; opacity: 0.87 on top of a solid-colored background that's background-color: #B48927. You could compute what the opaque version of that text color would be, but it may not be worth your time to do so. The world won't end if you just stick with opacity.






share|improve this answer


















  • 1





    Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

    – Dzyuv001
    Mar 23 at 0:53













1












1








1







The main thing you should realize is that opacity affects an entire element and all its descendants, whereas color and background-color do not.



In your simple example, white text with reduced opacity on a solid black background looks gray, so the visual effect is basically the same as changing the color from gray to pure white.



But in any more complicated example – say, the background of your paragraph's parent div is an image rather than a solid color, or you're using opacity on an element that contains other elements and not merely on text – what you're gonna end up with is things that truly look see-through. That also may mean that text becomes harder to read.



So the answer is less about there being any particular industry standard and more about choosing the right tool for the job. If you just want to make some text a lighter color, transition color itself. If you want to make things see-through, use opacity.



That's the theory, anyway, but in real life sometimes it's not that clean cut. Maybe a designer gives you a mockup with text that's color: #C44242; opacity: 0.87 on top of a solid-colored background that's background-color: #B48927. You could compute what the opaque version of that text color would be, but it may not be worth your time to do so. The world won't end if you just stick with opacity.






share|improve this answer













The main thing you should realize is that opacity affects an entire element and all its descendants, whereas color and background-color do not.



In your simple example, white text with reduced opacity on a solid black background looks gray, so the visual effect is basically the same as changing the color from gray to pure white.



But in any more complicated example – say, the background of your paragraph's parent div is an image rather than a solid color, or you're using opacity on an element that contains other elements and not merely on text – what you're gonna end up with is things that truly look see-through. That also may mean that text becomes harder to read.



So the answer is less about there being any particular industry standard and more about choosing the right tool for the job. If you just want to make some text a lighter color, transition color itself. If you want to make things see-through, use opacity.



That's the theory, anyway, but in real life sometimes it's not that clean cut. Maybe a designer gives you a mockup with text that's color: #C44242; opacity: 0.87 on top of a solid-colored background that's background-color: #B48927. You could compute what the opaque version of that text color would be, but it may not be worth your time to do so. The world won't end if you just stick with opacity.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 23 at 0:43









cjl750cjl750

2,48231020




2,48231020







  • 1





    Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

    – Dzyuv001
    Mar 23 at 0:53












  • 1





    Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

    – Dzyuv001
    Mar 23 at 0:53







1




1





Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

– Dzyuv001
Mar 23 at 0:53





Glad to hear I wasn't doing anything wrong and thank you for pointing out that the children element would be affected.

– Dzyuv001
Mar 23 at 0:53



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309310%2fcss-transition-opacity-vs-changing-background-color%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript