x404.co.uk
http://www.x404.co.uk/forum/

CSS Stylesheets
http://www.x404.co.uk/forum/viewtopic.php?f=4&t=24532
Page 1 of 1

Author:  rustybucket [ Wed Oct 28, 2015 2:19 pm ]
Post subject:  CSS Stylesheets

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?

Author:  EddArmitage [ Sun Nov 01, 2015 12:14 am ]
Post subject:  Re: CSS Stylesheets

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/