We are a user experience design and software development firm
Hire us to design your site, build your application, serve billions of users and solve real problems.
CSS 2.1 is more like a Swiss Army knife than a fully stocked toolbox. We can accomplish a lot, but we have to get creative with the standard attachments. Floats, relative positioning, the box model - each tool must performs double or triple duty because they're the only ones we've got.
When we do discover a clever way to accomplish a common task using these limited tools, we're likely to employ that technique over and over. I'm not talking about CSS frameworks here; those help out more at the macro level. I'm talking about repeatable techniques that can be applied at the micro level. When done right, these simple techniques can feel like entirely new Swiss Army attachments rather than intelligent application of existing blades.
Whenever I start out on a new client project, I start off with the following plug-and-play components:
clearfix class, you've got to tackle this problem if you employ float-based layout - until, that is, some future CSS spec implements a float-clear property.first-child pseudo-class means you'll have to create an actual class called first-child and apply it to your initial list element. Still, once you adjust border colors and spacing to fit your site design, this solution works anywhere. Variations can even allow for pipe-delimited definition lists.
/*
standard pipe-delimited list: add a class
of "first-child" to the first element
for IE either via script or in the markup
*/
/*
- the 0 margin and padding are unnecessary if
you're using a standard reset stylesheet
- you'll need to clear floats inside of ul.piped
using whatever your preferred method is
*/
ul.piped {
margin: 0;
padding: 0;
}
ul.piped li {
float: left;
margin-left: 8px;
padding-left: 8px;
border-left: 1px solid #000;
list-style: none;
}
ul.piped li:first-child,
ul.piped li.first-child{
margin-left: 0;
padding-left: 0;
border-left: 0;
}
block, inline, noneBlock and noneInline classes come in. Your JavaScript code just needs to know that elements with a class of block get toggled to noneBlock and vice-versa; same for elements with a class of inline and noneInline.
/* classes to hide and show elements programmatically*/
.inline {
display: inline;
}
.block {
display: block;
}
.noneInline,
.noneBlock {
display: none;
}
href value or cancel out the link's default action. Besides, the <a href=""></a> tag is for taking you to new pages, not performing an action within the existing page.
Some JavaScript coders ignore these advantages because they want the built-in styling shortcut of the a tag: cursors and hover states. As the code below demonstrates, however, it's dead simple to achieve the same visual effects with some simple CSS. Modern browsers can apply the hover pseudo-class to most any element. Ditto custom cursors.
a,
.styleAsLink{
color: #08c;
text-decoration: none;
}
a:hover,
.styleAsLink:hover{
color: #444;
text-decoration: underline;
cursor: pointer;
}
Once you've created a styleAsLink class, you can replace this type of code:
<a href="#"
onclick="alert('Isn't it annoying to have to return
false every time?'); return false;">
this is an actual link
</a>
... with this:
<div class="styleAsLink"
onclick="alert('In the real world the click event
should be applied unobtrusively!');">
this is a pseudo-link
</div>
One caveat: This technique is useful for links that serve no other function than to trigger JavaScript code. Don't employ it in the case of a progressively enhanced link that triggers a script when JavaScript is available but takes you to a new page when it's not. A simple rule of thumb: If the link exists in your actual markup, it should remain a link. If it's inserted into the DOM wholesale by JavaScipt, it should be a pseudo-link.
Enough about my own personal Swiss Army attachments. How do you get all MacGyver with your CSS? Let us know in the comments.
Topics: CSS, Javascript, Progressive Enhancement, Web Standards
Hire us to design your site, build your application, serve billions of users and solve real problems.
[...] I think every developer should have a CSS Swiss Army Knife in their toolbox. This was written at Pathfinder Development here. [...]
Pingback by Things that interested me this week. | Web Development, Web design, Web 2.0, and Me., Friday, September 26, 2008 @ 5:02 am
Cascading Style Sheets (CSS) web design lessons
Css link Properties Attributes - examles
http://css-lessons.ucoz.com/link-css-examples-1.htm
http://css-lessons.ucoz.com/link-css-examples-2.htm
Comment by Sitene Ekle, Wednesday, November 12, 2008 @ 1:58 pm