background color with increasing opacity using less









up vote
0
down vote

favorite












i need to change the background color of the all the children with a gradual increase of opacity. the number of child is dynamic and will be inserted or deleted asynchronously. is there any solution to achieve the same with css or less.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;


ul li:nth-child(1)
background-color: rgba(0,0,255, 0.1);


ul li:nth-child(2)
background-color: rgba(0,0,255, 0.2);


ul li:nth-child(3)
background-color: rgba(0,0,255, 0.3);


ul li:nth-child(4)
background-color: rgba(0,0,255, 0.4);


ul li:nth-child(5)
background-color: rgba(0,0,255, 0.5);

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>












share|improve this question





















  • Your example only goes up to :nth-child(5) and an opacity value of 0.5. What would you want that value to be for the, say, fourteenth child …? Do you need an equal distribution of opacity 0-1 over 1-x items, or what exactly? Does this need to be dynamic, i.e. divided in .1 steps for when there’s ten items, but .05 steps when there’s twenty …? Massively under-specified problem.
    – misorude
    Nov 12 at 7:58











  • opacity here is just an example for the real problem. there can be N numbers of list item. if we do not take opacity to consideration and only want to change the background color like rgb(0,0,0), rgb(1,0,0), rgb(2,0,0)... then how to do it, without writing like nth-child(1)
    – Jeevan Vikas
    Nov 12 at 8:32











  • when the word dynamically is used, typically it means that you cannot do it with just CSS. You would need javascript.
    – Mihai T
    Nov 12 at 9:14














up vote
0
down vote

favorite












i need to change the background color of the all the children with a gradual increase of opacity. the number of child is dynamic and will be inserted or deleted asynchronously. is there any solution to achieve the same with css or less.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;


ul li:nth-child(1)
background-color: rgba(0,0,255, 0.1);


ul li:nth-child(2)
background-color: rgba(0,0,255, 0.2);


ul li:nth-child(3)
background-color: rgba(0,0,255, 0.3);


ul li:nth-child(4)
background-color: rgba(0,0,255, 0.4);


ul li:nth-child(5)
background-color: rgba(0,0,255, 0.5);

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>












share|improve this question





















  • Your example only goes up to :nth-child(5) and an opacity value of 0.5. What would you want that value to be for the, say, fourteenth child …? Do you need an equal distribution of opacity 0-1 over 1-x items, or what exactly? Does this need to be dynamic, i.e. divided in .1 steps for when there’s ten items, but .05 steps when there’s twenty …? Massively under-specified problem.
    – misorude
    Nov 12 at 7:58











  • opacity here is just an example for the real problem. there can be N numbers of list item. if we do not take opacity to consideration and only want to change the background color like rgb(0,0,0), rgb(1,0,0), rgb(2,0,0)... then how to do it, without writing like nth-child(1)
    – Jeevan Vikas
    Nov 12 at 8:32











  • when the word dynamically is used, typically it means that you cannot do it with just CSS. You would need javascript.
    – Mihai T
    Nov 12 at 9:14












up vote
0
down vote

favorite









up vote
0
down vote

favorite











i need to change the background color of the all the children with a gradual increase of opacity. the number of child is dynamic and will be inserted or deleted asynchronously. is there any solution to achieve the same with css or less.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;


ul li:nth-child(1)
background-color: rgba(0,0,255, 0.1);


ul li:nth-child(2)
background-color: rgba(0,0,255, 0.2);


ul li:nth-child(3)
background-color: rgba(0,0,255, 0.3);


ul li:nth-child(4)
background-color: rgba(0,0,255, 0.4);


ul li:nth-child(5)
background-color: rgba(0,0,255, 0.5);

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>












share|improve this question













i need to change the background color of the all the children with a gradual increase of opacity. the number of child is dynamic and will be inserted or deleted asynchronously. is there any solution to achieve the same with css or less.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;


ul li:nth-child(1)
background-color: rgba(0,0,255, 0.1);


ul li:nth-child(2)
background-color: rgba(0,0,255, 0.2);


ul li:nth-child(3)
background-color: rgba(0,0,255, 0.3);


ul li:nth-child(4)
background-color: rgba(0,0,255, 0.4);


ul li:nth-child(5)
background-color: rgba(0,0,255, 0.5);

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>








ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;


ul li:nth-child(1)
background-color: rgba(0,0,255, 0.1);


ul li:nth-child(2)
background-color: rgba(0,0,255, 0.2);


ul li:nth-child(3)
background-color: rgba(0,0,255, 0.3);


ul li:nth-child(4)
background-color: rgba(0,0,255, 0.4);


ul li:nth-child(5)
background-color: rgba(0,0,255, 0.5);

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>





ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;


ul li:nth-child(1)
background-color: rgba(0,0,255, 0.1);


ul li:nth-child(2)
background-color: rgba(0,0,255, 0.2);


ul li:nth-child(3)
background-color: rgba(0,0,255, 0.3);


ul li:nth-child(4)
background-color: rgba(0,0,255, 0.4);


ul li:nth-child(5)
background-color: rgba(0,0,255, 0.5);

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
</ul>






html css css3 sass less






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 at 6:21









Jeevan Vikas

62




62











  • Your example only goes up to :nth-child(5) and an opacity value of 0.5. What would you want that value to be for the, say, fourteenth child …? Do you need an equal distribution of opacity 0-1 over 1-x items, or what exactly? Does this need to be dynamic, i.e. divided in .1 steps for when there’s ten items, but .05 steps when there’s twenty …? Massively under-specified problem.
    – misorude
    Nov 12 at 7:58











  • opacity here is just an example for the real problem. there can be N numbers of list item. if we do not take opacity to consideration and only want to change the background color like rgb(0,0,0), rgb(1,0,0), rgb(2,0,0)... then how to do it, without writing like nth-child(1)
    – Jeevan Vikas
    Nov 12 at 8:32











  • when the word dynamically is used, typically it means that you cannot do it with just CSS. You would need javascript.
    – Mihai T
    Nov 12 at 9:14
















  • Your example only goes up to :nth-child(5) and an opacity value of 0.5. What would you want that value to be for the, say, fourteenth child …? Do you need an equal distribution of opacity 0-1 over 1-x items, or what exactly? Does this need to be dynamic, i.e. divided in .1 steps for when there’s ten items, but .05 steps when there’s twenty …? Massively under-specified problem.
    – misorude
    Nov 12 at 7:58











  • opacity here is just an example for the real problem. there can be N numbers of list item. if we do not take opacity to consideration and only want to change the background color like rgb(0,0,0), rgb(1,0,0), rgb(2,0,0)... then how to do it, without writing like nth-child(1)
    – Jeevan Vikas
    Nov 12 at 8:32











  • when the word dynamically is used, typically it means that you cannot do it with just CSS. You would need javascript.
    – Mihai T
    Nov 12 at 9:14















Your example only goes up to :nth-child(5) and an opacity value of 0.5. What would you want that value to be for the, say, fourteenth child …? Do you need an equal distribution of opacity 0-1 over 1-x items, or what exactly? Does this need to be dynamic, i.e. divided in .1 steps for when there’s ten items, but .05 steps when there’s twenty …? Massively under-specified problem.
– misorude
Nov 12 at 7:58





Your example only goes up to :nth-child(5) and an opacity value of 0.5. What would you want that value to be for the, say, fourteenth child …? Do you need an equal distribution of opacity 0-1 over 1-x items, or what exactly? Does this need to be dynamic, i.e. divided in .1 steps for when there’s ten items, but .05 steps when there’s twenty …? Massively under-specified problem.
– misorude
Nov 12 at 7:58













opacity here is just an example for the real problem. there can be N numbers of list item. if we do not take opacity to consideration and only want to change the background color like rgb(0,0,0), rgb(1,0,0), rgb(2,0,0)... then how to do it, without writing like nth-child(1)
– Jeevan Vikas
Nov 12 at 8:32





opacity here is just an example for the real problem. there can be N numbers of list item. if we do not take opacity to consideration and only want to change the background color like rgb(0,0,0), rgb(1,0,0), rgb(2,0,0)... then how to do it, without writing like nth-child(1)
– Jeevan Vikas
Nov 12 at 8:32













when the word dynamically is used, typically it means that you cannot do it with just CSS. You would need javascript.
– Mihai T
Nov 12 at 9:14




when the word dynamically is used, typically it means that you cannot do it with just CSS. You would need javascript.
– Mihai T
Nov 12 at 9:14












1 Answer
1






active

oldest

votes

















up vote
3
down vote













Added these styles



ul li 
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));



Instead of coloring each li, give a background gradient to the ul and create a box effect with box-shadow.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>








share|improve this answer






















  • i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
    – Jeevan Vikas
    Nov 12 at 6:35










  • also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
    – Jeevan Vikas
    Nov 12 at 6:50










  • jsfiddle.net/jrtLx0m4 Check this if it works for you
    – Nandita Arora Sharma
    Nov 12 at 6:58










  • jsfiddle.net/jrtLx0m4/1 Check this fiddle
    – Nandita Arora Sharma
    Nov 12 at 7:01










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%2f53256825%2fbackground-color-with-increasing-opacity-using-less%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








up vote
3
down vote













Added these styles



ul li 
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));



Instead of coloring each li, give a background gradient to the ul and create a box effect with box-shadow.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>








share|improve this answer






















  • i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
    – Jeevan Vikas
    Nov 12 at 6:35










  • also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
    – Jeevan Vikas
    Nov 12 at 6:50










  • jsfiddle.net/jrtLx0m4 Check this if it works for you
    – Nandita Arora Sharma
    Nov 12 at 6:58










  • jsfiddle.net/jrtLx0m4/1 Check this fiddle
    – Nandita Arora Sharma
    Nov 12 at 7:01














up vote
3
down vote













Added these styles



ul li 
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));



Instead of coloring each li, give a background gradient to the ul and create a box effect with box-shadow.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>








share|improve this answer






















  • i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
    – Jeevan Vikas
    Nov 12 at 6:35










  • also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
    – Jeevan Vikas
    Nov 12 at 6:50










  • jsfiddle.net/jrtLx0m4 Check this if it works for you
    – Nandita Arora Sharma
    Nov 12 at 6:58










  • jsfiddle.net/jrtLx0m4/1 Check this fiddle
    – Nandita Arora Sharma
    Nov 12 at 7:01












up vote
3
down vote










up vote
3
down vote









Added these styles



ul li 
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));



Instead of coloring each li, give a background gradient to the ul and create a box effect with box-shadow.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>








share|improve this answer














Added these styles



ul li 
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));



Instead of coloring each li, give a background gradient to the ul and create a box effect with box-shadow.






ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>








ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>





ul li 
list-style: none;
font-size: 16px;
text-align: center;
font-weight: bold;
margin: 3px 0;
box-shadow: 2px 2px white, 0px 2px white;


ul
padding: 0;
background-image: linear-gradient(rgba(0, 0, 255, 0.1), rgba(0, 0, 255, 0.8));

<ul>
<li>A</li>
<li>B</li>
<li>C</li>
<li>D</li>
<li>E</li>
<li>F</li>
<li>G</li>
<li>H</li>
</ul>






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 6:37

























answered Nov 12 at 6:27









Nandita Arora Sharma

9,3632618




9,3632618











  • i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
    – Jeevan Vikas
    Nov 12 at 6:35










  • also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
    – Jeevan Vikas
    Nov 12 at 6:50










  • jsfiddle.net/jrtLx0m4 Check this if it works for you
    – Nandita Arora Sharma
    Nov 12 at 6:58










  • jsfiddle.net/jrtLx0m4/1 Check this fiddle
    – Nandita Arora Sharma
    Nov 12 at 7:01
















  • i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
    – Jeevan Vikas
    Nov 12 at 6:35










  • also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
    – Jeevan Vikas
    Nov 12 at 6:50










  • jsfiddle.net/jrtLx0m4 Check this if it works for you
    – Nandita Arora Sharma
    Nov 12 at 6:58










  • jsfiddle.net/jrtLx0m4/1 Check this fiddle
    – Nandita Arora Sharma
    Nov 12 at 7:01















i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
– Jeevan Vikas
Nov 12 at 6:35




i can do the same for background. but there are additional styles that also i need to modify, like the color of the text will be darker in lighter background and lighter in darker background. so i need a mixin solution for it
– Jeevan Vikas
Nov 12 at 6:35












also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
– Jeevan Vikas
Nov 12 at 6:50




also if you are using gradient to the ul that means the background of the li is not a solid color it is a gradient ( e.g background of A is a gradient not blue with 10% opacity )
– Jeevan Vikas
Nov 12 at 6:50












jsfiddle.net/jrtLx0m4 Check this if it works for you
– Nandita Arora Sharma
Nov 12 at 6:58




jsfiddle.net/jrtLx0m4 Check this if it works for you
– Nandita Arora Sharma
Nov 12 at 6:58












jsfiddle.net/jrtLx0m4/1 Check this fiddle
– Nandita Arora Sharma
Nov 12 at 7:01




jsfiddle.net/jrtLx0m4/1 Check this fiddle
– Nandita Arora Sharma
Nov 12 at 7:01

















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53256825%2fbackground-color-with-increasing-opacity-using-less%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

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

Evgeni Malkin