As the title says - I need something I can feed CSS files into and have it output a list of colour values used in it, what the colours are assigned to, and preferably an example of each colour?
There must be something like that out there somewhere, mustn’t there?
They’re mine in so far as they’ve been set in the CSS of the skin/theme on my blog - it’s not something I’ve created myself. Regex would take me rather longer than going through the file line at a time, which is what I’m doing right now. Maybe regex is easier…
I wouldn’t worry about doing anything like that. I’ll work my way through it bit by bit - I need a better feel for what’s going on in it anyway. The one thing this CSS isn’t, is consistent; so far, I’ve found seven different shades of brown in it.
There seem to be a number of tools that show the colors, but not the selectors that use them.
I use a little Firefox plugin called “Rainbow” that reads and displays the colors. The Web Developer’s Extension for FF seems to be at least as good. Dunno. Haven’t used either tool to examine an entire CSS file.
EDIT: The Web Dev’s Extension does a more thorough job. No selector’s tho.
I’ll take a look at those later - whilst they may not have the selectors, just a complete list of colour values would be a good start point, I’m now up to 10 shades of brown - feels like a book title, anyone care to suggest a plot? On second thoughts…
Whilst I’m not immediately familiar with working in that way, it does rather sound like what I need to be adopting to clean things up. As you might see in that Codepen, there are multiple individual rules applying the same colour - one colour has 7 separate rules applying it - it’s all a bit of nonsense really.
Here is a fun tool that strips hex colour values from a CSS script and displays them as a colour palette. Just paste your style sheet in the text area provided and click the GO button. It only works for hex, so it won’t pick up RGB or colour names like “red”.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Colours from CSS file</title>
<style type="text/css">
body { font-family:arial, helvetica, sans-serif; font-weight:normal; font-size:13px; color: #000000; text-align:left; margin:3px 0px; }
#wrap { position:relative; top:0px; left:0px; width:800px; height:550px; margin:20px; border:1px solid #CCCCCC; }
#ff { color:#F0F; background-color:#FFFF00; }
#outer { position:absolute; top:0px; right:0px; width:230px; }
.square { float:left; width:100px; height:100px; border:1px solid #000; margin:5px; overflow:hidden; }
.bgC { background-color:#FFF; padding:0px; color:#000; margin:0px; }
#goB { margin:10px; }
</style>
</head>
<body>
<div id="wrap">
<textarea id="cssData" cols="50" rows="30" onchange="showColours()">copy CSS to here and click GO button</textarea>
<div id="goB"><input type="button" value="GO" name="GO">
<div id="outer">
</div>
</div>
<!-- end wrap -->
<script type="text/javascript">
function showColours()
{ var tAreaObj=document.getElementById("cssData");
var re=/#[^;]{3}([^;]{3})?[;]/gi;
var getColours=tAreaObj.value.match(re);
var outerObj=document.getElementById("outer");
var build="";
for(var i=0;i<getColours.length;i++)
{ var thisBg=getColours[i].substring(0,getColours[i].length-1);
build+='<div class="square" style="background:'+thisBg+'">';
build+='<span class="bgC">'+getColours[i]+'<\/span><\/div>\n';
}
outerObj.innerHTML=build;
}
</script>
</body>
</html>
Certainly it gave me a good start on what to expect. It seems like it’s limited as to how many colours it will pull out - it looks like 8 text, and 8 background only. Useful on very simple colour schemes though.
This works great for what I need, despite it not indicating what rules are used to apply the colours. Through a combination of the tool as @John_Betong implemented it, and a Google Docs Sheet, I managed to extract everything, sort it, and identify the unique values. I started with 67 separate hex values, which represented 36 unique values, in the one CSS file I ran through it (the main one for my purposes). The unique values are below: It’s fun to just copy these as they are and run them through what John has set up. You very quickly get an idea of what’s going on, and it helps target those values that could be collapsed into a smaller set.
I have always thought that CSS files should separate the positioning elements and colours which is why I have separate colour classes which make it far easier to globally change as shown with the CSS 2nd Pass style sheet:
For the purposes of the Codepen, I was working line by line (or row by row to be more accurate) picking things out - as you can see from my last post, the Codepen is only around a 3rd of the way towards showing everything in there and the rules used to apply them. The original CSS file accounts for 367 lines of the stuff, and shows some rather loose organisation to say the least.
I’m certainly going to be looking at rebuilding the CSS to rationalise it and reduce the number of colours being used. As you were writing, I was just looking at the Paletton.com site - this version of the link has the most prominent background colour set in it. I’m playing around with combinations to see what I like the look of. I like the look of the technique you use there. I can see myself using that. My guess is that the CSS on the site can come down by at least 50% with a bit of a rethink.