Alternate row colors with jQuery
Well, a little Googling and I came upon this website.
This is an excerpt from the book Learning jQuery. Need to try and get my boss to buy that one.
Well, a little Googling and I came upon this website.
This is an excerpt from the book Learning jQuery. Need to try and get my boss to buy that one.
For some unclear reason some parts of the content did not show. It was just gone.
After some googling around I found that this is a pretty well known phenomena, and is named the Peekaboo bug.
Now if you google "Peekaboo bug" you'll find plenty of help. The first solution that I stumbled across that helped me was to add a line-height attribute to the element surrounding all the content that was disappearing.
To give propper credit, I found the solution here.
Let's look at what we did. We had this part of css...
...where the transparent background png would not work in IE6.
What we did was change it to this:
Here we use a IE hack to set background to none, and uses the IE only AlphaImageLoader filter to provide the png background.
So far, so good.
The #banner element has a set height in our example here. But if you try this on an element which have no set heigth, the background will not show. What usually makes the trick here is to add height: 100%; to the fix like so:
When using this fix you will often experience that url's will not be clickable, and form elements and text is not selectable.
What I have found to work is to first create a inner element. So if your html code was so:
This needs to be changed to:
Then change your css to something like this:
The most important thin here as I understand is the relative positioning of the innerbanner element, but the other attributes might help as well, so I always leave them in there.
The code css code above is ugly, messy and it will not validate. I suggest you make a separate css file called something like ie6_or_less.css and put the IE hack css into it.
Then in your html template call it like this:
This conditional statement within html comments makes sure that only IE browsers version 6 or less will load and use the ugly code.
That wrapps it up for this round.
The last time we saw how we can make use of transparent png's as backgrounds in our site layouts, included in our .css files. But what if we want to use png in our html source like so:
Here's the way I prefer to deal with such situations. This method is a "implement once, work on all images" kinda thing.
The downside, but one I'm willing to live with, is that the IE user has to have JavaScript enabled.
First create a pngfix.js file and paste the following into it:
Then in the head of your page you do this:
As much as I wish I was smart enough to come up with this my self, the credit goes to Bob Osola who in turn is crediting more people on his site.
Personally I like to use png's in my site designs, often to create a glow effect on a element laying on top of a gradient and/or patterned background, you can see it here on my blog as well. Here's the css code for the top part of the blog:
Now let's see how this looks in IE 6:
Not very pretty. To fix this I added the following css:
Adding * html before the #banner id selector is a hack that makes only IE read this piece of css, and here we use a IE specific filter to put the background png in, and doing this the png will maintain it's transparency.
The only little problem with this is if you in your css have specified a background color or image for body. For example you have a black background for the site, but the content is black text in a div with a white background.
Now what happens is that TinyMCE will use the black background from the body as a background in the editor window.
The solution is quick and easy. In your css include the follwing code:
Happy FarCry'ing
So far so good. Now I wanted to make some borders around the cells. What I've previously been doing is to set a cellspacing of 1 pixel on my table, make a background color for the table (the same color as I want for borders, and then another background color for th and td elements. Something like this:
Now that works. There's no invalid code. It's easy to read and manipulate. However, it felt wrong to use a table background color to make a border color. I thought there had to be a better/cleaner way of doing this with CSS only. And so together with my colleague we started looking (using The Google*) and he found a simple css attribute neither of us have used before (and we use a lot of css).
Better to show than to tell. Here's the code how it looks now:
So we did not save much code right away. But now all aspects of the formating is controlled by the css. And when dealing with many tables using the same css we will have saved code, and eased the managability.