Hover color cross-site for each color
NickName:user4913694 Ask DateTime:2015-06-11T12:02:48

Hover color cross-site for each color

If I have the following variable:

@text-c: #cccccc;

Is there a way to specify the hover variant of the color (in this case the colour #aaaaaa) so it applies cross-site, without having to add it in each separate :hover rule?

Copyright Notice:Content Author:「user4913694」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30771359/hover-color-cross-site-for-each-color

Answers
seven-phases-max 2015-06-11T04:39:42

Mixin and extend are probably what you're looking for. The variable itself does not say yet how or where you use it (be it either for some color property or not) or if you use it at all. \nSo instead of relying on some indirect logic, as there's no way for compiler to guess to insert :hover {color: #aaaaaa} for every element that has color: #cccccc, first of all because :hover \"sub-style\" is not inherited across elements like properties do (e.g. what if you just set body {color: @text-c}?), make it explicit, e.g. (not optimized variant just to illustrate the method):\n\n// \"color team\"\n.text-c() {\n color: #cccccc;\n &:hover {color: #aaaaaa}\n}\n\n// usage \n\ndiv.zoo {\n .text-c();\n}\n\nspan.park {\n .text-c();\n}\n\ntd#life {\n .text-c();\n}\n\n// etc.\n\n\nAn actual optimized (most likely extending some template instead of copying the same properties every time) would depend on how/where/how-often/etc. you're going to use it and (not-less-important) how (and if) you plan it to be customized (for example see @Harry's answer on how to make a generic mixin instead of color-value-hardcoded like I did above). ",


More about “Hover color cross-site for each color” related questions

Hover color cross-site for each color

If I have the following variable: @text-c: #cccccc; Is there a way to specify the hover variant of the color (in this case the colour #aaaaaa) so it applies cross-site, without having to add it i...

Show Detail

jQuery hover each different background color

How to hover every different background-color? These code set the background-color is working: var dlcabgColors = [ 'rgb(233, 147, 26)', 'rgb(22, 145, 190)', 'rgb(22, 107, 162)' , 'rgb(27, 54,...

Show Detail

Issue changing each li items hover color

this is the reference link: http://www.mytwins.gr/site/ This is a wordpress theme. I editing the css because I want to change the hover color for each menu li item. This is the code I tried till n...

Show Detail

How to set different hover color for each link

I have the following DIV: <div id="second-menu-navi" class="navi"> <a href="" id="tab-1">Why Choose Us</a> <a href="&quo

Show Detail

Jquery, changing color on hover

This has been driving me crazy for a while, I cannot figure out what I am doing wrong. I am trying to make a 4x4 grid and change the color of each square when I hover my mouse over (the color stays...

Show Detail

Auto hover color for buttons based on their Background color

I've googled a lot but I've found nothing about this situation. I have several flat Buttons with different Background colors, but the hover color is the same for all of them! I want each Button ha...

Show Detail

Multiple divs for a hover, changes color at end of webkit color transition

I have a CSS file separate from the main CSS file for a page. Essentially there are three hyperlinks each with their own p tags, one under the other, and each has their own divs for specifying the

Show Detail

Different background color animation for each item.hover()

I'm setting up a new website and want to implement some css animations for the menu via jQuery. I'm using WordPress for this and the theme I've installed has a mega menu-style plugin. The submenu of

Show Detail

jQuery: Changing the hover color with a color picker

I would like to change the hover color with a color picker. This is what I have tried: // First Try $("input[type=color]").change(function(e) { var pickedColor = e.target.value; // $("body...

Show Detail

Highcharts Bubble Chart Hover Color

I am using Highcharts to create a bubble chart and want the color of each bubble to be different. I am setting the color like this: series: [{ data: [ { x: 95, y: 95, z...

Show Detail