corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Defining a colour scheme in CSS


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Defining a colour scheme in CSS
Balling
Premium Member

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 10:22   View Garage View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 10:23   View Garage View User's Profile U2U Member Reply With Quote

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
12th Feb 13 at 10:39   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 10:44   View Garage View User's Profile U2U Member Reply With Quote

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
12th Feb 13 at 11:02   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 11:11   View Garage View User's Profile U2U Member Reply With Quote

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
12th Feb 13 at 11:12   View User's Profile U2U Member Reply With Quote

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
12th Feb 13 at 11:18   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 11:19   View Garage View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 11:20   View Garage View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
12th Feb 13 at 11:39   View Garage View User's Profile U2U Member Reply With Quote

Find and replace you lazy man
AdZ9
Member

Registered: 14th Apr 06
User status: Offline
12th Feb 13 at 17:38   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 17:42   View Garage View User's Profile U2U Member Reply With Quote

That's exactly what I want! Will have a look now.


ed
Member

Registered: 10th Sep 03
User status: Offline
12th Feb 13 at 17:48   View User's Profile U2U Member Reply With Quote

Was just about to say what AsZ9 said - damn.
noshua
Member

Registered: 19th Nov 08
User status: Offline
12th Feb 13 at 17:48   View User's Profile U2U Member Reply With Quote

As above is the most effecient way, mega useful
Balling
Premium Member

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 17:56   View Garage View User's Profile U2U Member Reply With Quote

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
12th Feb 13 at 18:07   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
12th Feb 13 at 18:20   View Garage View User's Profile U2U Member Reply With Quote

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
13th Feb 13 at 09:35   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
13th Feb 13 at 09:40   View Garage View User's Profile U2U Member Reply With Quote

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
13th Feb 13 at 15:57   View User's Profile U2U Member Reply With Quote

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
13th Feb 13 at 16:27   View User's Profile U2U Member Reply With Quote

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

Avatar

Registered: 7th Apr 04
Location: Denmark
User status: Offline
13th Feb 13 at 16:31   View Garage View User's Profile U2U Member Reply With Quote

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
13th Feb 13 at 17:17   View User's Profile U2U Member Reply With Quote

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
13th Feb 13 at 21:42   View User's Profile U2U Member Reply With Quote

Yeah what Balling/Ed said.

Once you start throwing mixins around it all gets more confusing, stick with it though!

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
HTML Help Doug Geek Day 2 472
20th Mar 06 at 20:43
by Doug Corsa
 
FAO: Webmasters: CSS Bart Geek Day 14 1140
24th Oct 06 at 14:57
by Ian
 
Input on a website please, web designers especially :D drunkenfool Geek Day 56 3051
25th Nov 06 at 19:08
by aPk
 
Anyone know their way around wikipedia CSS configs? Kyle T Geek Day 10 361
28th Feb 09 at 13:04
by Kyle T
 
Quick website help html? Simon Geek Day 11 273
30th Sep 10 at 10:28
by noshua
 

Corsa Sport » Message Board » Off Day » Geek Day » Defining a colour scheme in CSS 29 database queries in 0.0186770 seconds