Also, I should mention I did have a use for something like this. On my site, I sanitize HTML generated by user plugins, and to ensure the HTML doesn't mess up other parts of the page, I would provide a set of allowed CSS classes, but disallow inline styles. The CSS classes would not include "position" properties, so "position: static" wouldn't be allowed. Later I was able to use phloc to parse the inline styles but prohibit "position", so I didn't need a huge set of CSS classes anymore.
Show HN: Mimic – class-fied inline CSS
71–74 of 74 posts
Re: Show HN: Mimic – class-fied inline CSS
#72Re: Show HN: Mimic – class-fied inline CSS
#73Earlier quoted context omitted.
Yes, I fully understand why "alert-danger" is better than "alert-red". What I don't quite get is why "alert alert-danger" is better than "alert-danger". Isn't it possible - using a preprocessor - to maintain alert-danger, alert-warning etc? If multiple classes must be used, why not just "danger" which then allows the red coloration to be shared amongst different object types without being repeated.
In my opinion it is better since having the two classes allow you, amongst other things, to use advanced selectors. Here is an horrible example from the top of my mind: ... ">... .alert { border: 1px solid #ccc; } // Basic alert style .alert-success { border-color: green; } // Success alert are green .alert-warning { border-color: yellow; } // Warning alert are yellow .alert-danger { border: 3px dashed red; } // Dang…
.menu + .alert-danger { margin-top: -16px; }
do that
.menu + .alert.danger { margin-top: -16px; }
doesn't? Isn't "alert-danger" redundant? It means that, in practice, you need to do something like:
.alert-danger, .list-danger, .heading-danger, .foo-danger, .bar-danger, .hum-danger { color: red; }
instead of just
.danger { color: red; }
Re: Show HN: Mimic – class-fied inline CSS
#74Earlier quoted context omitted.
In my opinion it is better since having the two classes allow you, amongst other things, to use advanced selectors. Here is an horrible example from the top of my mind: ... ">... .alert { border: 1px solid #ccc; } // Basic alert style .alert-success { border-color: green; } // Success alert are green .alert-warning { border-color: yellow; } // Warning alert are yellow .alert-danger { border: 3px dashed red; } // Dang…
What does .menu + .alert-danger { margin-top: -16px; } do that .menu + .alert.danger { margin-top: -16px; } doesn't? Isn't "alert-danger" redundant? It means that, in practice, you need to do something like: .alert-danger, .list-danger, .heading-danger, .foo-danger, .bar-danger, .hum-danger { color: red; } instead of just .danger { color: red; }
All my alerts and message styling would be in a separate myApp-messages.scss that would ultimately be merged into myApp.min.css
In this myApp-messages.scss, I would create all my own classes that then extend global style definitions if needed but avoid using them.
.alert{
color: $text-color;
background: $light-background-color;
&.alert-danger {
@extend .danger; // if needed at all
color: $danger-color;
}
}As for "alert alert-danger" vs. "alert-danger". It is true that you could do something like :
.alert {
color: $text-color;
background: $light-background-color;
}.alert-danger{
@extend .alert;
color: $danger-color;
}In the "alert alert-danger" case, you can easily target all and then use advanced selectors to filter out or target more specifically its other states. You can also easily append/toggle the modifier classes with jQuery. With It's all a matter of philosophy, really. I like to have as many tools to do a job as possible, so I try to have as much classes on my elements as I can without going overboard (I'm looking at you, Drupal).