4 ms·
I don't understand the use of something like this. Instead of: .selector-1{a:b;color:red;} ...hundreds of other things... .selector-2{c:d;color:red;} someone
by etherealG 15y ago
I don't understand the use of something like this. Instead of:
.selector-1{a:b;color:red;}
...hundreds of other things...
.selector-2{c:d;color:red;}
someone can just:
.selector-1, .selector-2{color:red;}
...hundreds of other things...
It seems to me most cases where variables are used they are needed because of writing bad css in the first place. Use a colour only once and you only need to change it in 1 place, why do you need a variable for that?
- powrtoch 15y agoYou seem to go about CSS very differently then most. The typical way of doing styleshets is more or less "What properties does this type of element have? Now what about this type?..." Rather than "Now which elements on my site have this property-value? What about this property-value?..." Which isn't to say that comma syntax is in any way rare, just that CSS is usually approached by pairing properties to selectors, not the other way around. I would say this helps your style sheet make intuitive sense too. If you want to change the color of the sidebar text, you find the part of your style sheet for #sidebar and then change the color property, rather than finding the section for "blue", removing the sidebar from a big comma separated list of selectors, then placing it into a similar list for "green". From this standpoint variables make a lot of sense.
- catshirt 15y agoorganizing your css by property value sounds like a nightmare. it's much easier to organize hierarchically, which means your colors can scatter.
- pbhjpbhj 15y agoBut then when quarter of your red things have one width, and that's the same width as quarter of your green things, and another quarter of the reds have another width, which is the same as quarter of your orange things ... then you need variables again or you end up using multiple classes for each object just so that you can apply multiple properties.
- lambda 15y agoNo, you would end up with: .selector1, .selector2 { color: green } .selector3, .selector4 { color: red } .selector1, .selector3 { width: 100px } .selector2, .selector4 { width: 200px } No variables, no multiple classes. Now, I'm not saying that this is better than variables, or that variables won't make it easier to manage. But you don't have to repeat attributes or use many classes for each element currently in CSS, you just have to organize it a bit differently than you might expect at first.
- creamyhorror 15y agoAnd that's a lousy way to go, considering how spread out your properties can get. It's okay in small amounts when applied to a group of adjacent elements, but going any further makes no sense (unless you like using Ctrl+F a lot). I need an editor/IDE with a dropdown that displays the properties of any element in one panel, perhaps showing me where the actual stylesheet changes are made in a side column. Like editing styles in Firebug, only smarter. Anyone got a recommendation?
- spullara 15y agoFirst, I think it is inappropriate to down vote this comment as it is a valid point that you can actually solve the color problem in current CSS. However, building your CSS in this way probably takes a lot longer to render since the selectors are expensive and setting attributes is cheap. Further, I have never seen a page of any complexity where this would make sense.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]