Click here, Press → key to advance.
W3C MW4D Group ; WaSP-ILG
Notice the rounded corners ... those sweet sweet rounded corners
border-radius your friend// cross browser code for border-radius
div{
//The standard. Future proof. Trident, Webkit, and Presto support
border-radius: 10px 5px 10px 3px;
// Gecko specific . FF 4+ aiming to move towards standard though
-moz-border-radius: 10px 5px 10px 3px;
//Old Safari and Chrome browsers
-webkit-border-radius: 10px 5px 10px 3px;
}
Ability to use any font on your web page
@font-face your friend// Set the font like this
@font-face {
src: url('http://yourwebsitename.com/yourFont.ttf');
font-family: 'myFont';
}
//And then use it just like you use any othe font
#mydiv{font: 2.5em 'myFont';}
Don't sacrifice legibility
A quick word...
div {
opacity: 0.7;
}
Value should be between 0 (transparent) and 1 (Completely opaque)
Transitioning the state
Can be text color, background color, width, height etc
div {
width: 3em;
height: 3em;
background-color: red;
-o-transition-property: background-color;
-o-transition-duration: 4s;
-moz-transition-property: background-color;
-moz-transition-duration: 4s;
-webkit-transition-property: background-color;
-webkit-transition-duration: 4s;
transition-property: background-color;
transition-duration: 4s;
}
div:hover { background-color: blue; }
div {
…
-o-transition-property: background-color;
-o-transition-duration: 4s;
-o-transition-delay: 1s;
-o-transition-timing-function: ease-out;
//do same for -webkit and -moz specific code
}
Translating, scaling, rotating etc
div {
height: 100px; width: 100px;
transform: translate(80px, 80px) scale(1.5, 1.5) rotate(45deg);
}
Forget image editors
#content1{
text-shadow: 5px -10px 3px #ccc;
}
#content2{
text-shadow: -5px 10px 0px #ccc;
}
Demo
div{
box-shadow:10px 10px 5px #000;
-moz-box-shadow:10px 10px 5px #000;
-webkit-box-shadow:10px 10px 5px #000;
}
One CSS for all resolutions
@media all and (min-width: 480px) and (max-width: 800px) {
#container {width: auto; max-width: 800px;}
#main {width: 70%; float: left;}
#sidebar {width: 29%; float: left; margin-bottom: 10px;}
#pub {width: 29%; margin-left: 70%; float: none;}
}
@media all and (max-width: 480px) {
#container, #main, #sidebar {width: 100%; font-size: 0.9em;}
#pub {display: none;}
#sidebar ul li {display: inline;}
*{clear: both; border-left: 0 !important; border-right: 0 !important;}
}
Usefull++
//Matches anchors elements which link to wikipedia
a[href="www.wikipedia.org"]{ text-decoration: underline;
}
//Matches all images whose ALT attribute start with 'The'
img[alt~="The"]{
margin-right: 55px;
margin-bottom: 15px;
}
//Matches all images whose ALT attribute have the word 'TV' in them
img[alt*="TV"]{
margin-bottom: 15px;
}
}
//Matches the first list element
ul li:first-child{ //css2
color: red;
text-decoration: underline;
}
//Matches the last list element
ul li:last-child{ //css2
color: blue;
}
//Matches every third list element
ul li:nth-child(3n){ //css3!
color: green;
}
Use with caution!
your -moz or -webkit or -o specific code might be deprecated in the future. Plus, if you only have those vendor specific codes, then you miss out on other vendors which support the property
Its fine for small demos etc but for production code, make sure it works on each browser which supports the property and not just on your favourite browser.
Try to have the standard code along with the vendor specific code, just to make it more future proof.
//Applies only to webkit based browsers :( ... -webkit-transition-property: background-color; }
//Applies to all broswers :) ... -webkit-transition-property: background-color; -moz-transition-property: background-color; -o-transition-property: background-color; transition-property: background-color; //future proof }
Lets not just give great CSS code just to one layout engine...lets try to make sure that every capable browser gets the proper code
Email: shwetankd@opera.com
Twitter: http://twitter.com/shwetank