Reply to topic  [ 2 posts ] 
CSS Stylesheets 
Author Message
I haven't seen my friends in so long
User avatar

Joined: Thu Jun 18, 2009 5:10 pm
Posts: 5836
Reply with quote
Hi all,

I'm asking this in a work-related capacity. We're making a web-app in HTML5/AngularJS and we want to do switchable themes.

Is there any way of doing CSS with variables/constants such that:

  • the colour pallette can be defined at the top of the document
  • the color pallette can changed during runtime and the change rattles through the UI?

We've had a look at SASS but it's pretty hefty and yet another dependency.

What are your thoughts?

_________________
Jim

Image


Wed Oct 28, 2015 2:19 pm
Profile
I haven't seen my friends in so long
User avatar

Joined: Thu Apr 23, 2009 9:40 pm
Posts: 5288
Location: ln -s /London ~
Reply with quote
Assuming you have jQuery I'd do it as follows

index.html
Code:
<!doctype html>
<html>
    <head>
        <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
        <script src="styles.js"></script>
        <link id="css" rel="stylesheet" href="blue.css">
    </head>
    <body>
        <h1>'lo Bob.</h1>
        <button id="switch">Switch</button>
    </body>
</html>


styles.js
Code:
$(document).ready(function() {
    $("#switch").click(function(){
        $("#css").attr("href", function (idx, oldValue) {
            return oldValue === "red.css" ? "blue.css" : "red.css";
        });
    });
});


blue.css
Code:
h1 {color: blue}


red.css
Code:
h1 {color: red}


Having said that, I'm a backend developer, I rarely even dabble in javascript, and I've no clue if this will interfere with angular.

_________________
timark_uk wrote:
Gay sex is better than no sex

timark_uk wrote:
Edward Armitage is Awesome. Yes, that's right. Awesome with a A.


Sun Nov 01, 2015 12:14 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 102 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.