Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,152,542 members, 7,816,315 topics. Date: Friday, 03 May 2024 at 09:25 AM |
Nairaland Forum / Science/Technology / Webmasters / A Few Css Shortcuts (1277 Views)
Write HTML And CSS Codes On Android Devices / How To: Create A Simple Hover Button With Html And Css / How Is My **Free** Css Ebook? (2) (3) (4)
A Few Css Shortcuts by yawatide(f): 10:40pm On Nov 03, 2008 |
Folks, the following will help you not only shave off a few bytes in terms of bandwidth but will also help make your code cleaner (which translates to better maintenance) and easier to follow. At the end of the day, you will become a better developer: 1) Rather than do this:
Do this:
Note 2 things: 1) if the number is zero, no need specifying units. 2) The order for the above is TRBL or as is called normally, "TRouBLe" 2) Rather than do this:
Do this:
Note 2 things: 1) Use lowercase 2) this only works if the each pair in the sequence is equal. In other words, #ff0000 could be rewritten as #f00 but couldn't rewrite #f0ff00 3) Rather than do this:
Do this:
note: 1) this works only if all 4 sides are the same. If even one side is off, you will need to revert to the "rather than do this" section 4) Rather than do this:
Do this:
Note: Order is important Hopefully some of us get to learn from this. If you have anything else to add, please do so. Let's LEARN something! |
Re: A Few Css Shortcuts by WebMonk(m): 8:46am On Nov 04, 2008 |
Aligning tables to "center" isn't something easily replicated in css, esp if you're beginner. To do this to a div, use the following code:
This will give a div of 902px wide aligned to the center. |
Re: A Few Css Shortcuts by kehers(m): 2:24pm On Nov 04, 2008 |
I go for this this way margin: 0; |
Re: A Few Css Shortcuts by kehers(m): 2:49pm On Nov 04, 2008 |
And by the way, the margin shortcut as well applies to other css properties that have seperate values for their TRBLs e.g padding (padding-top, padding-right, padding-bottom, padding-left) and border-width (border-right-width, border-top-width, ) As uv learnt from the post, that such properties are in the order TBRL, they also go in the order T R/L B and T/B R/L and T/B/R/L. Here is wat Im trying to say:
|
Re: A Few Css Shortcuts by yawatide(f): 3:10pm On Nov 04, 2008 |
kehers: Thanks for the margin: 0 note. I should have used a better example in my case. Yes, when it is all zeroes, you just do margin: 0. Likewise, if all the values aer the same (like say a margin of 5), you just need to specify the value once (margin: 5px Thanks for also specifying the order for when there are only 2 or 3 as well. I forgot about that. I honestly thought I would be the only one posting to this. I am happy there are others. Please post more. Let us all LEARN something! |
Re: A Few Css Shortcuts by kehers(m): 3:31pm On Nov 04, 2008 |
The background shortcut also applies to the list property. Instead of this: U can do this
For the (very) few that may not know, this Can go this way:
|
Re: A Few Css Shortcuts by yawatide(f): 3:41pm On Nov 04, 2008 |
he he Kehers, I was actually purposely avoiding the font thingie because as much as I have tried to memorize it and find a pnemonic for it, my brain seems to be dying on this one I use it all the time but for the life of me, I can never remember the order, he he. |
Re: A Few Css Shortcuts by WebMonk(m): 3:58pm On Nov 04, 2008 |
<removed> |
Re: A Few Css Shortcuts by Nobody: 11:12am On Nov 05, 2008 |
no retreat, no surrender put it back |
Re: A Few Css Shortcuts by kehers(m): 4:24pm On Nov 11, 2008 |
Dis works
instead of this
|
Re: A Few Css Shortcuts by yawatide(f): 5:48pm On Nov 11, 2008 |
weeeell kehers, the background-color option is preferred because it is more semantic. Not only that, when trying to manipulate the DOM, you need to use style.backgroundColor. By saying "background-color" in the CSS, it is easier to follow. This also removes any doubt as to whether u r referring to background-image or background-color or just the whole background (with all its attributes) Sure, a few extra typing but tis more semantic p.s. It is sort of similar to using ticks when displaying background images in CSS (url (images/x.gif vs ('images/x.gif')). Both work but tis preferred to use the version with ticks. |
Re: A Few Css Shortcuts by yawatide(f): 2:12am On Nov 13, 2008 |
This isn't a shortcut per se but a pretty nifty trick: If you are concerned about how your pages are printing (like say you have a table that is printing on 2 pages because of the content above it on the page where it begins) pages, you can set hard breaks via CSS and the page-break-before or page-break-after properties. To avoid boring you with grammar, I will give you a link that explains it better than I probably can Explanation: http://www.javascriptkit.com/dhtmltutors/pagebreak.shtml Demo: http://www.javascriptkit.com/dhtmltutors/example.htm Enjoy! |
Re: A Few Css Shortcuts by xclusiv(m): 8:45am On Nov 13, 2008 |
you can write your css code anyway you understand it, and use Free CSS Toolbox, http://www.blumentals.net/download/to compress your stylesheet |
Re: A Few Css Shortcuts by yawatide(f): 12:22pm On Nov 13, 2008 |
xclusiv, Nice one but don't let that be an excuse to anyone for writing bloated code |
Re: A Few Css Shortcuts by olush0la(m): 1:49pm On Nov 14, 2008 |
I know a lot of you still LOOOOOOVE your <TABLEs> (as lazy as that might sound) And would easily argue about its pros and advantages over using CSS. Good news: YOU CAN EXTEND THE USE OF TABLES WITH CSS. Sample CSS with TABLE code: #main { Don't believe me? See link for more: http://www.digital-web.com/articles/everything_you_know_about_CSS_Is_wrong/ |
Re: A Few Css Shortcuts by kehers(m): 2:30pm On Nov 14, 2008 |
@xlusiv Just a note about CSS compressing - backup the original file as u will need it when u need to edit ur CSS. The same rule applies to JS. @olush0la And how do u express ur colspan and rowspan ? Really, I'd rather use a table that do that. Besides, IE lt 8 (IE before version 8*), which happens to be the most used browser out there (atleast at the moment) doesnt support it. |
Re: A Few Css Shortcuts by yawatide(f): 3:34pm On Nov 14, 2008 |
Yes folks, let's remember that some CSS rules, though very powerful are not cross-browser. Even if they were, you always want to code for the lowest common denominator. Unless you are coding for an intranet where everyone is using the same software, in this case, you want to code for what ppl use the most currently, which is < IE8. |
Re: A Few Css Shortcuts by xclusiv(m): 9:27am On Nov 17, 2008 |
@kehers Compressing Stylesheet does not change the code, it justs reduce the lines of code u have, and the CSS Software can be use to test your code and check for browsers compatibilty |
Re: A Few Css Shortcuts by kehers(m): 5:37pm On Nov 17, 2008 |
I see, Was judging by the ones Iv come across - strips comments, removes all whitespaces and lines - and puts everything in a line. |
(1) (Reply)
I Need Some To Train Me In Php Programming / Who is a moderator? / Hacker Needed Urgently.
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 27 |