{"id":2799,"date":"2009-11-27T07:37:04","date_gmt":"2009-11-27T07:37:04","guid":{"rendered":"http:\/\/aceinfowayindia.com\/blog\/?p=2799"},"modified":"2018-07-18T21:12:04","modified_gmt":"2018-07-18T21:12:04","slug":"5-steps-to-write-better-css-part-ii","status":"publish","type":"post","link":"http:\/\/aceinfowayindia.com\/blog\/2009\/11\/5-steps-to-write-better-css-part-ii\/","title":{"rendered":"5 Steps to Write Better CSS Part II"},"content":{"rendered":"<p>This is the second part of 5 Steps to Write Better CSS. There are plenty of CSS tutorials are available on internet but the few tutorials are useful. In this tutorial you will find 5 steps to write better css code for your next website project. I hope you will enjoy this tutorial.<br \/>\n<!--more--><\/p>\n<h4>1. Keep CSS declarations in one line<\/h4>\n<p>you should always keep CSS declarations in one line, it helps in keeping your CSS file clean and smaller. It also helps to remove unwanted spaces and characters.<\/p>\n<p><strong>Good Code<\/strong><\/p>\n<pre>[code lang=\"css\"]\nh2 {font-size:18px; color:#333333; background:#cccccc; }\n[\/code]\n<\/pre>\n<p><strong>Bad Code<\/strong><\/p>\n<pre>[code lang=\"css\"]\nh2 \n{\n font-size:18px;\n color: #333333;\n background: #cccccc; \n}\n[\/code]\n<\/pre>\n<h4>2. Combine Elements<\/h4>\n<p>One of the best way to save lines of code is by grouping selectors. There are some examples below of what I am referring to.<\/p>\n<p><strong>Good Code<\/strong><\/p>\n<pre>[code lang=\"css\"]\nh1, h2, h3 {\nfont-family: Arial, Helvetica, sans-serif; color:#333;\n }\n[\/code]\n<\/pre>\n<p><strong>Bad Code<\/strong><\/p>\n<pre>[code lang=\"css\"]\nh1 {\nfont-family: Arial, Helvetica, sans-serif; color:#333; \n}\nh2 {\nfont-family: Arial, Helvetica, sans-serif; color:#333;\n }\nh3 {\nfont-family: Arial, Helvetica, sans-serif; color:#333;\n }\n[\/code]\n<\/pre>\n<h4>3. Use &#8220;Margin&#8221; to Center Layout<\/h4>\n<p>Many beginners to CSS can&#8217;t figure out why you can&#8217;t simply use float: center to achieve that centered effect on block-level elements. If only it were that easy! Unfortunately, you&#8217;ll need to use.<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre>[code lang=\"css\"]\n#Container {\nmargin:0 auto; \/* top, bottom - and left, right*\/\nwidth:xxxpx;\n }\n[\/code]\n<\/pre>\n<h4>4. Comment your CSS<\/h4>\n<p>It&#8217;s a great idea to comment your code in sections. To add a comment, simply add \/* behind the comment, and *\/ to close it, like so:<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre>[code lang=\"htmlstrict\"]\n\/******** CODE START HERE ********\/\n[\/code]\n<\/pre>\n<h4>5. Use CSS Compress Tools<\/h4>\n<p>if you don\u2019t want to waste your time in modifying your old style sheets you can simply use online css compress tools, it make your work in seconds.<\/p>\n<p>check this online css compress tools\u2026<\/p>\n<p><a href=\"http:\/\/csstidy.sourceforge.net\">Css Tidy<\/a><\/p>\n<p><a href=\"http:\/\/cleancss.com\">Clean Css<\/a><\/p>\n<p><a href=\"http:\/\/cssoptimiser.com\">Css Optimiser<\/a><\/p>\n<p><a href=\"http:\/\/flumpcakes.co.uk\/css\/optimiser\/\">Flumpcakes Css optimizer<\/a><\/p>\n<p><a href=\"http:\/\/cssdrive.com\/index.php\/main\/csscompresssor\/\">cssdrive Css Comperasor<\/a><\/p>\n<p><a href=\"http:\/\/jigsaw.w3.org\/css-validator\/\">W3C Css Validator<\/a><\/p>\n<h4>Conclusion<\/h4>\n<p>These are just some of the tips that help me to write better code. I hope that tutorial will also help you to write better and clean code. Apply these Tips to your current and next projects, and you will surely appreciate the efforts.<\/p>\n<p><strong>If You Think that tutorial can be more better , Please share with us. Comment us<\/strong><\/p>\n<p>if you would like to receive more tutorials from us, please consider subscribing to our feed by <a href=\"http:\/\/feeds.feedburner.com\/developers-paradise\"><strong>RSS<\/strong><\/a> or by <a href=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=developers-paradise&amp;loc=en_US\"><strong>email<\/strong><\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second part of 5 Steps to Write Better CSS. There are plenty of CSS tutorials are available on internet but the few tutorials are useful. In this tutorial you will find 5 steps to write better css &hellip; <a href=\"http:\/\/aceinfowayindia.com\/blog\/2009\/11\/5-steps-to-write-better-css-part-ii\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,56],"tags":[52,23],"class_list":["post-2799","post","type-post","status-publish","format-standard","hentry","category-css","category-tutorials","tag-css","tag-tutorials"],"_links":{"self":[{"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts\/2799","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/comments?post=2799"}],"version-history":[{"count":25,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts\/2799\/revisions"}],"predecessor-version":[{"id":4466,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts\/2799\/revisions\/4466"}],"wp:attachment":[{"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/media?parent=2799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/categories?post=2799"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/tags?post=2799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}