CSS 3 Explained
CSS has been around for over 10 years now, long enough that we can stop talking about it like it’s the new kid on the block. There were are a number of frustrating thing about CSS that have been addressed by later version – now at CSS Version 3 – but many of these improvement have not been taken up as browsers simple weren’t ready. Well they are getting there so in this article were going to look at some of the features of CSS 3 that we all need to get used to using.
Selectors
The idea of selectors is to target HTML elements without needing Classes OR IDs
Syntax
* [att^="value"]
Matches elements to an attribute that starts with the specified value.
* [att$="value"]
Matches elements to an attribute that ends with the specified value.
* [att*="value"]
Matches elements to an attribute that contains the specified value.
Example
a[title$="cats"]
{
background-color: red;
}
Why bother?
They cut down on code
Combinators
A combinator targets all siblings of an element that has the same parent. For example, to add a red background border to all spans that are a sibling of a particular div
div~span {
Background-color: red;
}
Not supported in IE 6!
Pseudo Classes
These are a pretty cool set of classes. E.g.
:nth-child(n) Allows you target elements based on their positions in a list of child elements. Could be used for making striped rows. So if you want to match a group of two elements after the forth third, you can simply use:
1name="code">:nth-child(2n+3) { background-color: #ccc; }
Theres a bunch more too!
::selection lets you target elements that have been highlighted by the user.
RGB and Opacity
RGBA lets you set the colour and opacity of an element. There is already an opacity command but it targets the parent and all its children – not just the one element.
Multi Column Layout
This is an important one if you ask me. This allows you have multi-column layouts without having to use multiple divs.
.index #content div {
-webkit-column-count : 4;
-webkit-column-gap : 20px;
-moz-column-count : 4;
-moz-column-gap : 20px;
}
Multi Backgrounds
Apply multiple layered backgrounds with CSS3. Here’s what it looks like in shorthand.
div {
background: url(example.jpg) top left (100% 2em) no-repeat,
url(example2.jpg) bottom left (100% 2em) no-repeat,
url(example3.jpg) center center (10em 10em) repeat-y;
}
Word Wrap
word-wrap stops long words from overflowing.
Text Shadow
Exactly how it sounds, a drop shadow on text, and the CSS looks a bit like this.
.signup_area p {
text-shadow: rgba(0,0,0,.8) 0 1px 0;
}
@Font Face Attribute
@font-face allows you use any font on your site by making it downloadable. It’s a major contentious issue with font foundries very concerned but a solution is being worked on. It looks like this:
@font-face{
font-family: ‘DroidSans’;
src: url(’../fonts/DroidSans.ttf’) format(’truetype’);
}
Border Radius
Added curved corners to HTML elements without using background images.
h2 span {
color: #1a1a1a;
padding: .5em;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
}
Border Image
Use an image for the border of an element. Something like this:
Box Shadow
Add shadows to HTML elements without background images.
#content .post img {
border: 6px solid #f2e6d1;
-webkit-border-image: url(main-border.png) 6 repeat;
-moz-border-image: url(main-border.png) 6 repeat;
border-image: url(main-border.png) 6 repeat;
}
Box Sizing
Legacy browser can interpret boxes sizes (padding/height) in weird ways. The box-sizing property lets you specify how the browser calculates the width and height of an element
Media Queries
This these let you define styles depending on the screensize. So if the screensize is below 500px the navigation might appear in a different location. Or something.
Speech
specify the speech style of screen readers.
The Nielsen Group of Jacob Nielsen fame have been hard at work testing users on the mobile web. They have found that its about as easy to use as the “normal” web was was about 15 years ago. The average completion rate for tasks on the mobile web was 59% compared to 80% on a regular PC. “Observing users suffer during our sessions reminded us of the very first usability studies we did with traditional websites in 1994,” said Nielsen.
In April Ireland saw the launch of the Google Local Business Centre, AT LAST. If you search for a service and in the search results you see a wee map with an A-J of businesses alongside, your looking at the GLBC, also know as the 10 Pack.
iPhone has become a web designers best friend with the release of FTP-On-The-Go, a program that allows you download, edit and
Recent Comments