Browse > Home / Archive by category 'Web Development'

| Subcribe via RSS

Smart recipes! Intelligent mobile-ready recipes for your kitchen. Share, invent and eat more adventurously!

CSS progress bars without extra DIVs

August 7th, 2010 | Comments Off | Posted in Articles, smrtr, Web Development

While working on the smrtr project I needed to create progress bars to show the completion. However, rather than having independent bars all over the place, I wanted to create bars that could be contained within another element.

The ideal solution would be the possibility to scale a background image to a given width with CSS but this is not available until CSS3 (if then). So another approach was needed:

1. Position absolute & z-index

Intially I approached this by including an additional div within the object to show the progress bar. By setting position:relative; on the container and position:absolute; top:0px; left:0px; on the internal div it was possible to overlay the bar on the container. An additional z-index:1 on the content stacks them up correctly and the bar can then be assigned a width to show the percentage.

This works fine, however, it restricts you from assigning bars to any span elements (can’t put a div inside a span) and gets messy due to the additional divs added. Adding extra elements for an effect is always a last-ditch option, as it complicates the readability of the code.

2. Background-position

So we have option 2. Originally this was option 1, but discarded because it ‘did not work’. A cup of tea later however, and I found a way to make it so it does. Background position positions an image relative to the top-left of the block, and nowhere else. This is a shame because if we could position from the top-right we could just slide the background image backwards and forwards to get the effect.

Setting background-position 0-100% slides it away from the left hand edge, leaving the space in the wrong place. We can set the background-position to -0 to -100%, but only if we know the width of the element and create the background-image to fit. Unfortunately that doesn’t apply here.

So the solution? Create an image that is 50% bar, 50% blank.

When this image is positioned at 50% the division line will the bang on 50% across the container. At background-position: 55% the barline will be 45% across the container. Yes, 45%. The positioning goes the wrong way, but it is proportional and stays so at any size container. All we need to do is subtract the value from 100 before applying the position.

The code can be applied to any element you like:


.percent-complete {
background: url(../img/progressbar-50.gif) repeat-y;
background-position:50%;
}

The source image:

It in action:

Tags: , ,

smrtr: Learn Smarter Not Harder

June 22nd, 2010 | Comments Off | Posted in Articles, Linux, Miscellaneous, News, Web Development

This site has been sat quiet for a long time, hosting howtos and information on my wordpress plugins. But that doesn’t mean that I’ve been sitting here doing nothing. For the past few months I’ve been working on a new project: smrtr.

smrtr is collaborative learning, quiz and study tool. Take quizzes, track progress and receive recommended study aids to build your knowledge. Ideal for students, professionals or general-knowledge know-it-alls alike – focus your learning where it’s needed most!

All this, and it’s community generated too. Following the example of wikipedia, the site allows everyone to contribute their own questions, build their own exams and form their own groups on topics of their choosing.

Take a look at the site and leave feedback here. It’s early days, but this could change the way you learn forever!

Look forward to hearing what you think!

WidgetBucks CPM Location Filtering

January 25th, 2008 | Comments Off | Posted in Articles, Tutorials, Web Development

The new widget advertising network from WidgetBucks has been getting popular recently for the higher click through rate and potential earnings. To maintain the amounts advertisers were willing to pay, they recently switched CPM ads for international traffic. Unfortunately this means that non-US & Canada visitors get lower earning non-targeted ads.

Until WidgetBucks targets non-US/Canada traffic better or provides Google-style “alternate ads”, it would be useful to be able to show something else to non-US/CA users in an attempt to maintain relevance.
More »

Apache vs. the Slashdot Effect

February 9th, 2007 | 2 Comments | Posted in Articles, Linux, Tutorials, Web Development

Increasing traffic is the measure of success for a website. More visitors equals more exposure which in turns generates more income. However, if you have hosted your site on a low-end package you could get hit by excess use charges just as your start celebrating your success.

Here at mutube.com the combination of 4,625 visitors (8,531 hits) a month and popular free downloads quickly helped trip our 1Gb bandwidth limit.

In this article I’ll look at how I’ve used the combined power of Apache Server and Coral Cache to distribute all kinds of requests away from your server transparently.
More »