Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
From what I've gathered this isn't possible, but seing the amount of weird knowledge on CS someone might have a workaround.
Say I code a basic CSS document as a sort of template with predefined classes, is there an easy way I could go about adjusting all colours only one place.
Basically if it was possible, it would look something like this in my head:
code: .color1
{
color: #fff;
}
.button
{
background-color: color1;
}
The above is not possible of course, but I think it sort of illustrates what I'm after.
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
But with say three or four colours to make up the colour scheme.
|
Whittie
Member
Registered: 11th Aug 06
Location: North Wales Drives: BMW, Corsa & Fiat
User status: Offline
|
How do you mean exactly mate?
Example of a live site i've done... Blue
code: @import url('secondary-blue.css');
.top-aside,
.banner,
.small_banner,
.banner-slider,
footer {
background-color: #0D5292;
background-image: url(../images/skins/bg-banner-blue.png);
background-position: center center;
background-repeat: no-repeat;
background: -webkit-gradient(radial, center center, 0, center center, 460, from(#0D9DDC), to(#0D5292));
background: -webkit-radial-gradient(circle, #0D9DDC, #0D5292);
background: -moz-radial-gradient(circle, #0D9DDC, #0D5292);
background: -ms-radial-gradient(circle, #0D9DDC, #0D5292);
}
Different page in Red
code: @import url('secondary-red.css');
.top-aside,
.banner,
.small_banner,
.banner-slider,
footer {
background-color: #961300;
background-image: url(../images/skins/bg-banner-red.png);
background-position: center center;
background-repeat: no-repeat;
background: -webkit-gradient(radial, center center, 0, center center, 460, from(#C71901), to(#961300));
background: -webkit-radial-gradient(circle, #C71901, #961300);
background: -moz-radial-gradient(circle, #C71901, #961300);
background: -ms-radial-gradient(circle, #C71901, #961300);
}
Obviously you can pick and chose what you want, and just at the top of a page call it in ( <link rel="stylesheet" type="text/css" href="css/secondary-red.css" /> )
I may have completely mis-read what you're trying to achieve though?
[Edited on 12-02-2013 by Whittie]
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
Yeah, basically I want different colour versions of the same CSS document, like you have there, but I want to avoid going back and editing all instances of blue and replacing them with red.
I know that search and replace could do this pretty easily, but there are instances where that wouldn't work
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
You could do a catch-all definition at the top of the stylesheet setting everything to a specific colour and then not define the colour inside specific elements....
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
But say I have two buttons, .button1 and .button2.
One is red with white text other is yellow with black text.
Wouldn't I make them the same colour with a catch all?
|
Whittie
Member
Registered: 11th Aug 06
Location: North Wales Drives: BMW, Corsa & Fiat
User status: Offline
|
Surely won't take long to change a few colours on a seperate style mate? Or is it massive?
|
AndyKent
Member
Registered: 3rd Sep 05
User status: Offline
|
That was just a suggestion for basic definitions, like fonts, headings, background etc.
Entirely depends on the scenario. Of you're going down to that detail I could only suggest leaving colours off the stylesheet completely and defining them through php dynamically on page.
Effort probably disproportionate to the requirement though!
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
No, not a huge issue at all, just something I've wondered as I'm used to working with Color Swatches in InDesign and it's an easy way to quickly determine how a certain colour scheme works.
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
quote: Originally posted by AndyKent
Entirely depends on the scenario. Of you're going down to that detail I could only suggest leaving colours off the stylesheet completely and defining them through php dynamically on page.
Effort probably disproportionate to the requirement though!
And disproportionate to my skills.
|
Gary
Premium Member
Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
|
Find and replace you lazy man
|
AdZ9
Member
Registered: 14th Apr 06
User status: Offline
|
Start reading about LESS or SASS, easiest way to do it.
You define a colour like
$primarycolour which is #000
then in your css anywhere with that colour you put $primarycolour will be #000 - all you do is change the selector at the top and it'll change it for you when outputted.
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
That's exactly what I want! Will have a look now.
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
Was just about to say what AsZ9 said - damn.
|
noshua
Member
Registered: 19th Nov 08
User status: Offline
|
As above is the most effecient way, mega useful
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
So the basic answer is that to achieve what I'm after I'll use a CSS preprocesser to create variables within my stylesheet and it then exports the finished CSS document.
Means I'll have to completely rethink my workflow though...
Thanks for the answer, definitely something to look further into.
|
noshua
Member
Registered: 19th Nov 08
User status: Offline
|
Don't you just import LESS, declare variables and reference them in the CSS?
What are you trying to achieve as the end goal?
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
quote: Originally posted by noshua
Don't you just import LESS, declare variables and reference them in the CSS?
What are you trying to achieve as the end goal?
Looking at SASS you do the coding with variables and the export you SCSS document as a CSS, basically applying all the variables.
My end goal is to have a sort of generic document with all the CSS I tend to reuse and be able to quickly adapt the colour scheme and perhaps other parameters like certain margins and border radius, that type of stuff.
|
AdZ9
Member
Registered: 14th Apr 06
User status: Offline
|
Yeah, the latest 'craze' is changing workflow to use Git and Terminal (if on Mac) to do it all using SASS etc.
It's a big headfuck at first, but once you get used to it the benefits are huge.
It was awesome for me because I also do graphics/print design so i'm used to using big 'stylesheets' in print documents to change everything on a page with one click, so having it then with CSS without using Find/Replace was awesome. It speeds things up massively.
You can also set up .SCSS files to process into automatic .min.css files to make life easier as well
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
Then you're more or less in exactly the same boat as me. I mostly do graphics and print work, so there's a lot of functionality I miss while coding CSS.
I don't aim to build huge websites or do advanced coding, it's purely the visual aspect that's interesting to me.
I'm still not certain about the SCSS workflow and it's obvious it's something I have to learn doing, but looking at how it works it makes NOT preprocessing CSS look medieval.
The whole Terminal thing seems pretty intimidating. Looking at the SCSS guides it looks like something Dom has written.
|
AdZ9
Member
Registered: 14th Apr 06
User status: Offline
|
It is at first, there are Apps that give it a UI so you don't have to fiddle with terminal too much.
I'm Digital Lead at the company I work at as I made the jump to go solely digital now and don't do print work so I made myself learn SCSS etc to make my life easier!
|
Sam
Moderator Premium Member
Registered: 24th Dec 99
Location: West Midlands
User status: Offline
|
quote: Originally posted by AdZ9
Start reading about LESS or SASS, easiest way to do it.
You define a colour like
$primarycolour which is #000
then in your css anywhere with that colour you put $primarycolour will be #000 - all you do is change the selector at the top and it'll change it for you when outputted.
What happens if you are a weirdo that disables JavaScript in your browser? Is there some kind of fallback?
|
Balling
Premium Member
Registered: 7th Apr 04
Location: Denmark
User status: Offline
|
Sam from what I've read about SCSS the code doesn't actually make it's way to the browser. You convert the code before publishing so that every instance of $primarycolor is replaced with #000 and exported as a regular CSS.
If you then want to change the primary colour to #555 you do that in the SCSS and export a new CSS.
|
ed
Member
Registered: 10th Sep 03
User status: Offline
|
That's right - all your CSS is compiled together and spat out. There are quite a few web frameworks which support LESS and the likes, you just need to give the framework a list of your CSS files and they all get bundled together an minified which is nice
[Edited on 13-02-2013 by ed]
|
AdZ9
Member
Registered: 14th Apr 06
User status: Offline
|
Yeah what Balling/Ed said.
Once you start throwing mixins around it all gets more confusing, stick with it though!
|