Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Many of my css files (including bootstrap) use specified colours. I want to be able to change the main colours in one central place (such as the config pages I'm adding).

I have seen that css var's might be a thing soon but are currently not well supported.

Is there a more elegant way I can do this that my current idea of using the css files as templates which I will load with the colour config on page load?

Thanks ^_^
Andy
Posted
Comments
deepankarbhatnagar 6-Jul-15 6:35am    
whare is your css code?
Sreekanth Mothukuru 6-Jul-15 7:14am    
I think we can achieve this by using variables concept that is mentioned in less or sass. We need to create a variable at page body level. Upon selecting the chosen color, we need to set the variable with appropriate color.
Andy Lanng 6-Jul-15 7:30am    
Ha - I was looking to answer deepankarbhatnagar's question when I came across less and sass files :D - Still looking at it
Sreekanth Mothukuru 6-Jul-15 7:37am    
I realized this as a base used in SmartAdmin bootstrap template from wrapbootstrap. They are changing the whole website theme just by changing the css class name at body tag and in that class they are setting the # color the variable itself.

The only supported way (I mean supported in every browser) is to load different CSS files...
Split your CSS info into two: one for the color information and one for all the rest.
Now you can make multiply CSS of color info, like green.css, red.css, yellow.css and so no...
What you have to do now is to include the right CSS in your page according to some user definition (like a cookie value)...
C#
<link href="<%=string.Format(" theme="]) ? " default=" : Request.Cookies[" rel="stylesheet" type="text/css" />
 
Share this answer
 
You can do this easily if you pass your CSS definitions up to your Site Master page. This is the technique I'm using for my current site, and it works really well.

So for example, suppose you want to be able to choose between 2 different header colours for the title banners on your site, you would specify the CSS classes for those colours as below:

CSS
.header-purple
{
    background-color: #aab4cf;
}

.header-green
{
    background-color: #8fa9a0;
}


Then on your local page you would specify which header colour to use on that page with the following in the C# of your .aspx.cs file:

C#
// set the header colour of this page
this.Master.layoutColour = "green";

// or alternatively
//this.Master.layoutColour = "purple";


Then in the C# of your Site.master.cs page, you would define the variable that holds the colour you've just set in the code above:

C#
// default the colour to purple in case it doesn't get set by any code
public String layoutColour = "purple";


This then gets passed through to the actual HTML/CSS layout on your Site.master page, as follows:

HTML
<div class="header-<%=layoutColour %>">Some header text</div>
 
Share this answer
 
Ok so I actually went with using bootstraps .less files and compiling the css with grunt.

The idea is not to have a set number of set themes, but to be able to adjust the theme to get colour matches. For a single site this could be done by a long process of 'tweaking' the theme but I intent to use much of my site as a framework for future sites.

I followed the instructions here: http://getbootstrap.com/getting-started/[^] but a step was missing. I had to install Git-scm, which most people probably already have.

I got the windows installer here: http://git-scm.com/downloads[^]

Now all I need to do it change a few settings in Bootstraps variables.less and compile. This gives me a new bootstrap.css file with the changes applies.

Thanks for taking a look guys ^_^

Andy
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900