tags:

views:

81

answers:

2

Hi,

I have a site with a customer front end, which has a catalogue, homepage, contact page, about us page and so on. There is also an administration front end. I would like to implement a kind of hierarchy where any elements within an element with class "admin" will inherit properties set in the admin stylesheet and anything else inherits from the customer stylesheet. The purpose of this is so that admin can login on the admin front end, where they have access to lots of advanced stuff, but they can also navigate to the customer front end where they can execute basic tasks (such as hiding catalogue items, running a debug script if a customer reports an issue and so on). I would like all the admin tools on the customer front end to have properties taken from the admin stylesheet instead of the customer one - this will change the background colour and stuff.

Is there any easy way to set up like namespaces to make things simpler, for example:

.admin {
    .list {
        .list-subtitle
        {
        }
        .list-item
        {
        }
    }
    a
    {
    }
}
.customer
{
    .list
    {
        .list-subtitle
        {
        }
        .list-item
        {
        }
    }
    a
    {
    }
}

I know it can be like:

.admin .list {}
.admin .list .list-item {}
.admin a

I just dont want to have to keep putting .admin all the time.

Does anyone have any suggestions on how I could do this? I suppose I could write a .net class which sets this up and writes a stylesheet according to whats put into it, but then I would not be able to read the styles so easily add there would be all sorts of like Classes.Add(blah) and so on.

Thanks in advance for any replies...

Regards,

Richard

<ul class="customer">
    <li>Will appear as a customer control</li>
    <li>Will appear as a customer control</li>
    <li class="admin">Will appear as an admin control</li>
</ul>
<div class="customer">
    <ul class="admin">
        <li>Will appear as an admin control</li>
        <li>Will appear as an admin control</li>
        <li>Will appear as an admin control</li>
    </ul>
</div>

Basically, as you can see, I want any element with class "admin", or within an element with class "admin" to appear as they would on the admin front end. Otherwise they appear as they would on the customer front end. This may also be used the other way around too so administrators can preview what they have entered before submitting it to the database, as it would appear on the customer front end.

If namespaces were allowed in CSS this would be no problem - unfortunately something like Less seems to be my only option to achieve this easily. (I say unfortunately because I have never used it before and I am on a very tight timelimit for this - I have nothing against tools like Less!).

Regards,

Richard

+3  A: 

There's no native CSS way, but you could use something like LESS which will allow you to write it like that and compile it into real CSS.

There's HSS too, which also supports nested rules like the ones you specified.

Andy E
Looks like both these answers are what im looking for.. thanks..Not as simple as I had hoped (only because I was hoping it was possible directly in CSS, rather than having to download and install anything)Ta.
ClarkeyBoy
+4  A: 

Have you looked into using Less CSS or SASS?

great_llama
Looks like both these answers are what im looking for.. thanks..Not as simple as I had hoped (only because I was hoping it was possible directly in CSS, rather than having to download and install anything)Ta.
ClarkeyBoy
Sadly, there isn't much you can do to avoid repeating yourself in vanilla CSS.Based on your scenario, possible to dynamically include the admin version of the stylesheet (after changing both to not be qualified with .client and .admin)? Including both, when an admin is logged in, and the 2nd stylesheet can override anything in the first...
great_llama
I suppose I could just include the admin.css, as you say, if the user is logged in. I have thought about that and came to the conclusion that I may still need to put the .admin prefix before the styles - otherwise the whole page would have the admin styles applied, and i dont want this. Basically I want to have a List control where, if it contains admin links, the parent div has class "admin" applied so all the child elements appear as they would on the admin front end. Its kinda complicated to explain.. will jst see if i can post a code snippet, hang on..
ClarkeyBoy
I have added a sample above..
ClarkeyBoy
Maybe take a stab at using jQuery (or similar) to find anything .admin and apply additional CSS? And then keep the primary CSS file simple?
great_llama
Working with CSS, you'll eventually find--as you have now--that the language does have some serious limitations and pain points. Luckily, stuff like SASS addresses that with a fairly minimal learning curve.
Damien Wilson
I am actually using SASS now - ive only touched on it at the moment but im getting there.. it looks really easy to use and VERY powerful..Thanks all for the links / recommendations..
ClarkeyBoy
PS I have looked at jQuery - turned out it is too much to learn in the time I have (which is a week!).. I think SASS should do everything I want it to do..
ClarkeyBoy
well i have sass working really well now, but i notice there is not much documentation out there, even on the site. its also telling me that some of the stuff is deprecated and to use other stuff - this new stuff is not even mentioned on the web - this doesnt impress me much. However im gonna carry on using it anyway. I am guessing, since you recommended it, that you have used it before. One question in that case - how do you force it to output tabs rather than double spaces? Is there some visual front end that i havent found which allows you to set this? Thanks in advance, Richard
ClarkeyBoy
You'll hopefully never have to edit the output document, does tab/space output matter there?
great_llama
well the problem is that everything is in css files, and i converted them to sass. the output sass files use two spaces, but i will be editing those so i would like them as tabs. i dont care about whether its tabs or spaces in the output css files - its the output in the sass files im worried about.. i suppose i could just do a find n replace on double spaces.. that might be easier than trying to get it to work automatically..
ClarkeyBoy