Jul 14
by Paul OB
Now that IE7 has overtaken IE6 in usage it has become more common to find authors trying to use position:fixed in their layouts. Therefore in this article we will try to address some common problems and misconceptions when using position:fixed (we will not be covering the background-attached “fixed” property but you can find out more about that here if you are interested.).
Note that position:fixed doesn’t work in IE6 and under so you will need to be using another browser although we will try to accommodate IE6 with some alternate styling.
Fixed to What?
Fixed positioning varies from other positioned elements in that the element is always placed in relation to the viewport and not a local stacking context. Even if you add position:relative to a parent of the fixed element it is still placed in relation to the viewport.
This can present problems if you want to place the fixed element inside a centered layout and then place it at a certain position within that centered layout.
In order to have a positioned element inside a centered layout you can simply let it occupy its normal position in the flow and not specify any position values for top, bottom, left or right at all. This will enable the element to become fixed at that point while the rest of the content scrolls.
We’ll work through some simple examples to show this in effect.
We’ll start with this simple Example
Click to continue reading »
Jun 30
by Golgotha
This year I have found myself looking for jobs on two separate occasions. As a result I have had a good number of interviews. One question that I found harder to answer than I had anticipated was when asked how good I am at JavaScript and CSS.
Why was this question that hard to answer? I actually feel that I am quite knowledgeable about both CSS and JavaScript. I’ve built probably close to a dozen websites using entirely CSS-based layouts over the last few years. In addition, I have used JavaScript quite often to enhance those websites, usually with Ajax and spiffy web widgets like the Comment Info Tip Plugin. I may not be as knowledgeable as Paul O’Brien when it comes to CSS or Jonathan Snook when it comes to JavaScript, but I certainly am competent. So again, what’s the problem?
The problem is the damn cross-browser problems that still trip a person up from time to time. Almost every time I ask Paul for his help with CSS it has to do with a cross-browser issue: something works in Firefox, but not in IE or vice versa. Same with JavaScript; think addEventListener method in Firefox and attachEvent for Internet Explorer. This is a bloody mess for the developer and I suppose makes me question my abilities at times.
Such cross-browser issues make it hard for a developer. I don’t know about you, but I’ve often spent more time trying to make a site work across all browsers than on the actual design of the site.
There are people that I know and respect that have chosen not to learn JavaScript at all because they were so put off by such difficulties. Also consider how difficult it’s been to get people to leave HTML table-based designs behind in favor of CSS layouts. It’s been slow at best. No doubt due much to the differences across browsers.
What’s your take? How has the difficulties in trying to achieve all browser support effected your attitude of CSS and JavaScipt?
Jun 17
by Raffles
In recent thread over at the SitePoint forums, someone asked how to have any sized image fit nicely into the viewport while maintaining its aspect ratio. The assumption is that all the content can fit in the viewport and no scrollbars are needed. While CSS is wonderful and magical, it doesn’t know the sizes of images and let us play with them to pixel perfection, so we must turn to good old JavaScript to maintain aspect ratio.
Click to continue reading »