The life, work and thoughts of Bence Kucsan - There are 0 new posts and 0 new comments since Your last visit
This is a new, regularly (planned...) section where I’ll share every month or so a CSS trick, which will (hopefully) freak you out and make you spend your days naked dancing on your desk in ecstasy. For this first time I share a very handy method to keep your CSS files smaller.
So I wanted to start this new section with a very impressive technique, I just discovered a couple of days ago. Although it’s very plausible, I’ve never used this before, but probably would have saved me a good amount lines of code.
How does it work?
It’s very simple, you can add multiple classes to a tag separated with a space. In the example I highlighted above I would use it to define the model of a text box called “message” only once, like
.message { width: 250px; background-color: #eeeeee; border: 1px solid #cccccc; }
and let them mutate in cases where I need this box in form of an error message, where I only need for example the borders to be red. For this I would only need the easy one liner:
.error { border: 1px solid red }
And this would overwrite the border definition of the class message to the red one. Awesomeness.
Your thoughts are welcome!
Make your voice heard, fill out the comment form below and don't be shy to hit that big blue button.
Oh yeh, forgot to mention. This isn’t a CSS trick. It’s a HTML ‘trick’. You can access they classes with JavaScript, as well.
Also, beware when using the selectors. .message.error {} works incorrectly in IE6. It will apply this selector to any element which has a class of ‘error’, ignoring the other classes in the selector part. Whenever you join up classes like this IE6 will apply the selector to the last one mentioned.
Wow, great tip - I’ve been using CSS for years and always wondered if I could do this but never did much about it until now. I Googled “add two classes to tag”, found your page and tried it—it works!
I now can use one class to shape a server-side include menu in a right column, and I added another class that I needed to put a space above that right-column include only on some pages.
Thanks!
Tips for caring for a fish aquarium
http://www.freewebtown.com/toyaquarium/
Tips for caring for a fish aquarium
sapropel drudgism chufa emersion cheap seizer unphysicked doughmaker
<a href= http://www.jud.state.ct.us/external/kids/history/postcards/ >Connecticut Courthouse Postcards</a>
http://www.clubdonatello.org
http://www.youtube.com/SergTorres free porn movies
<a href=” http://www.youtube.com/SergTorres “>free porn movies</a>
<a href=” http://www.youtube.com/SergTorres “>free porn movies</a>
example site for css - stylesheet : http://hotels.saemco.org
viagra cialis levitra clomid buy viagra onli generic viagra http://www.parzufim.com cipro gay viagra buy viagra online cheap viagra
free viagra
herbal viagra
propecia xenical viagra side effects buy viagra zithromax lasix female viagra cream cheapest cialis http://www.parzufim.com
This e-mail message is intended only for the addressee(s) and contains information which may be confidential or legally privileged. If you are not the intended recipient please advise the sender by return e-mail, do not use, copy or disclose the contents, and delete the message and any attachments from your system. Unless specifically indicated, this email does not constitute formal advice or commitment by the sender. E-mail communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions which arise as a result.
28 comments, add yours!