{"id":4223,"date":"2011-01-27T12:08:53","date_gmt":"2011-01-27T12:08:53","guid":{"rendered":"http:\/\/aceinfowayindia.com\/blog\/?p=4223"},"modified":"2019-03-12T03:39:48","modified_gmt":"2019-03-12T03:39:48","slug":"top-css3-commands","status":"publish","type":"post","link":"http:\/\/aceinfowayindia.com\/blog\/2011\/01\/top-css3-commands\/","title":{"rendered":"Top CSS3 commands"},"content":{"rendered":"<p><acronym title=\"Cascading Stylesheets Version 3\">CSS3<\/acronym> is really starting to gather momentum with many of the commands outlined in the <acronym title=\"Cascading Stylesheets Version 3\">CSS3<\/acronym> working draft supported by Firefox, Safari and Google Chrome. We thought we&#8217;d put together some of our favourites. Before we get started <acronym title=\"Cascading Stylesheets Version 3\">CSS3<\/acronym> commands require browser specific syntax for them to work.<br \/>\n<!--more--><br \/>\n[ad#co-2]<\/p>\n<p>For Mozilla Firefox we need to use the <strong>-moz-<\/strong> prefix, for example:<\/p>\n<p><strong>-moz-border-radius:<\/strong><\/p>\n<p>And for Safari the <strong>-webkit-<\/strong> prefix, for example:<\/p>\n<p><strong>-webkit-border-radius:<\/strong><\/p>\n<p><strong><\/strong><\/p>\n<h4>1. Border radius<\/h4>\n<p>The <acronym title=\"Cascading Stylesheets Version 3\">CSS3<\/acronym> border radius command creates curved corners on an element. Instead of using 4 or more images to<strong> create curved corners<\/strong> use the following commands:<\/p>\n<div id=\"box1\" class=\"fr\">\n<p>The curved corner command will not display in Internet Explorer<\/p>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4242 alignnone\" style=\"border: 0pt none;\" title=\"border-radius\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/border-radius.jpg\" alt=\"border-radius\" width=\"230\" height=\"100\"><br \/>\n<code><br \/>\n#box1 {<br \/>\nborder: 1px solid #699;<\/code><\/p>\n<p>\/* for Mozilla Firefox *\/<br \/>\n-moz-border-radius: 20px;<\/p>\n<p>\/* for Safari &amp; Google Chrome *\/<br \/>\n-webkit-border-radius: 20px;<br \/>\n}<\/p>\n<h4>2. Box shadow<\/h4>\n<p>A shadow can be applied to elements using the CSS3 box shadow command. The box shadow accepts three numeric values plus a colour to apply this effect. These numbers are:<\/p>\n<p>1. Distance of horizontal offset of shadow &#8211; A positive value means the shadow will cast to the right and a negative value to the left<br \/>\n2. Distance of vertical offset of shadow &#8211; A positive value means the shadow will cast below and a negative value above<br \/>\n3. How blurry you&#8217;d like the shadow<\/p>\n<p>With the addition of a colour value the shadow is complete:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4250\" style=\"border: 0pt none;\" title=\"box-shadow\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/box-shadow.jpg\" alt=\"box-shadow\" width=\"234\" height=\"94\"><br \/>\n<code>#box2 {<br \/>\n\/* Not mandatory for the box shadow effect *\/<br \/>\nborder:1px solid #699;x<\/code><\/p>\n<p>\/* for Mozilla Firefox *\/<br \/>\n-moz-box-shadow: 5px 5px 5px #b6ebf7;<\/p>\n<p>\/* for Safari &amp; Google Chrome *\/<br \/>\n-webkit-box-shadow: 5x 5px 5px #b6ebf7;<\/p>\n<h4>3. Transparency or RGBA<\/h4>\n<p>Transparency has always been tricky. Different browsers historically have applied transparency using different commands. Continuing this cross-browser inconsistency we have the addition of the new CSS3 RGBA background property, however in principle this command is more logical. The command consists of 4 values &#8211; the first, second and third are the red, green &amp; blue values (0-255) respectively followed by the alpha channel or transparency (0-1).<\/p>\n<p>For the RGBA command the browser specific prefixes (-moz-, -webkit-) aren&#8217;t required:<\/p>\n<p>#box3 {<br \/>\nbackground-color: rgba(110, 142, 185, .5);<br \/>\n}<\/p>\n<p>The background colour command adds a nice blue-grey background at .5 or 50% opacity in browsers that understand the CSS3 RGBA property.<\/p>\n<p>Unfortunately Internet Explorer will also attempt to render the background colour command but not understand RGBA. To ensure that the background colour is also set in IE an IE-only hack is required. In the following example the :last-child psuedo selector which Internet Explorer doesn&#8217;t understand is used to exclude it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4257\" style=\"border: 0pt none;\" title=\"transparency\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/transparency.jpg\" alt=\"transparency\" width=\"229\" height=\"100\"><\/p>\n<p><code><br \/>\n#box3 {<br \/>\n\/* For all browsers *\/<br \/>\nbackground-color: #6e8eb9;<br \/>\n}<\/code><\/p>\n<p>body:last-child #box3 {<br \/>\n\/* Exclude all IE browsers using :last-child *\/<br \/>\nbackground-color: rgba(110, 142, 185, .5)!important;<br \/>\n}<\/p>\n<h4>4. Columns<\/h4>\n<p>The ability to add columns has been added to CSS3. Rather than floating elements within containers we can set the column number, width and rule:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4261\" style=\"border: 0pt none;\" title=\"colums\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/colums.jpg\" alt=\"colums\" width=\"541\" height=\"48\" srcset=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/colums.jpg 541w, http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/colums-300x26.jpg 300w\" sizes=\"auto, (max-width: 541px) 100vw, 541px\" \/><br \/>\n<code><br \/>\n#box4 {<br \/>\n\/* Not mandatory for the column property *\/<br \/>\nborder: 1px solid #699;<\/code><\/p>\n<p>\/* for Mozilla Firefox *\/<br \/>\n-moz-column-count: 2;<br \/>\n-moz-column-gap: 20px;<br \/>\n-moz-column-rule: 1px solid #6e8eb9;<\/p>\n<p>\/* for Safari &amp; Google Chrome *\/<br \/>\n-webkit-column-count: 2;<br \/>\n-webkit-column-gap: 20px;<br \/>\n-webkit-column-rule: 1px solid #6e8eb9;<br \/>\n}<\/p>\n<h4>5. Multiple background images<\/h4>\n<p>Background imagery has always been restrictive when it comes to CSS due to the fact you can only apply one background image per element. This isn&#8217;t the case with CSS3 which allows multiple images per element by simply comma-separating them.<\/p>\n<p>To place an image on both the left and right of an element you can use the following commands, with a little styling:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4274\" style=\"border: 0pt none;\" title=\"multiple\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/multiple.jpg\" alt=\"multiple\" width=\"231\" height=\"164\"><br \/>\n<code><br \/>\n#box5 blockquote{<br \/>\nbackground:url(\/i\/quotel.gif) no-repeat 0 0, url(\/i\/quoter.gif) no-repeat 100% 0;<br \/>\nborder:1px solid #699;<\/code><\/p>\n<p>padding:0 20px;<br \/>\n}<\/p>\n<p>This command will be mis-rendered by Internet Explorer as it doesn&#8217;t accept 2 background images on a single element. An exclude all IE hack is required.<\/p>\n<p>#box5 blockquote {<br \/>\n\/* For all browsers, just an open quote *\/<br \/>\nbackground: url(\/i\/quotel.gif) 0 0 no-repeat;<br \/>\npadding: 0 20px;<br \/>\n}<\/p>\n<p>body:last-child #box5 blockquote{<br \/>\n\/* Exclude all IE browsers using :last-child *\/<br \/>\n\/* Then the two images *\/<br \/>\nbackground: url(\/i\/quotel.gif) no-repeat 0 0, url(\/i\/quoter.gif) no-repeat 100% 0;<br \/>\n}<\/p>\n<h4>6. Background gradients<\/h4>\n<p>CSS3 background gradients are extremely flexible and can be used to create complex patterns. At its simplest the CSS linear gradient allows a gradient to be applied to an element from top to bottom and left to right.<\/p>\n<p>This example of a CSS3 gradient in Mozilla Firefox applies a light blue gradient at the bottom of a box for just 20% of the boxes&#8217; height<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4279\" style=\"border: 0pt none;\" title=\"gradients\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/gradients.jpg\" alt=\"gradients\" width=\"540\" height=\"86\" srcset=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/gradients.jpg 540w, http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/gradients-300x47.jpg 300w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><br \/>\n<code><br \/>\n#box8 {<br \/>\n\/* for Mozilla Firefox *\/<br \/>\nbackground: -moz-linear-gradient(bottom, #b6ebf7, #fff 20%);<br \/>\n}<\/code><\/p>\n<p>Safari uses a less intuitive but more flexible approach using colour stop values. An example of the Safari specific code follows (note the linear is included in brackets instead of outside):<\/p>\n<p>#box8 {<br \/>\nbackground: -webkit-gradient(linear, left bottom, left top, color-stop(0, #b6ebf7), color-stop(0.20, #fff));<br \/>\n}<\/p>\n<h4>7. Rotation<\/h4>\n<p>CSS3 also allows rotation of elements using the transform command, with the rotate property accepting degrees as a parameter.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4282\" style=\"border: 0pt none;\" title=\"rotation\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/rotation.jpg\" alt=\"rotation\" width=\"297\" height=\"207\"><\/p>\n<p>&lt;code&gt;#box9 {<br \/>\n-moz-transform: rotate(2deg);<br \/>\n-webkit-transform: rotate(2deg);<br \/>\n}&lt;\/code&gt;<\/p>\n<h4>8. Outlines<\/h4>\n<p>Outilines are included in the <acronym title=\"Cascading Stylesheets Version 3\">CSS3<\/acronym> specification and allow both a border and an outline to be applied to a single element.<\/p>\n<p>The outline property is identical to the border command. The  additional offset property however allows the border to be moved further  inside or outside of the element.<br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4286\" style=\"border: 0pt none;\" title=\"outlines\" src=\"http:\/\/aceinfowayindia.com\/blog\/wp-content\/uploads\/2011\/01\/outlines.jpg\" alt=\"outlines\" width=\"233\" height=\"105\"><br \/>\n<code>#box7 {<br \/>\nborder: 1px solid #000;<br \/>\noutline: 1px solid #699;<br \/>\noutline-offset: -9px;<br \/>\n}<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CSS3 is really starting to gather momentum with many of the commands outlined in the CSS3 working draft supported by Firefox, Safari and Google Chrome. We thought we&#8217;d put together some of our favourites. Before we get started CSS3 commands &hellip; <a href=\"http:\/\/aceinfowayindia.com\/blog\/2011\/01\/top-css3-commands\/\">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],"tags":[52,40,41],"class_list":["post-4223","post","type-post","status-publish","format-standard","hentry","category-css","tag-css","tag-css3","tag-css3-techniques"],"_links":{"self":[{"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts\/4223","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=4223"}],"version-history":[{"count":67,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts\/4223\/revisions"}],"predecessor-version":[{"id":4480,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/posts\/4223\/revisions\/4480"}],"wp:attachment":[{"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/media?parent=4223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/categories?post=4223"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/aceinfowayindia.com\/blog\/wp-json\/wp\/v2\/tags?post=4223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}