views:

261

answers:

3

Hello, I am making a website that uses nothing but jquery-ui for theming.

Well, in my application I need to do alternating colors per row on a list. Right now all of the rows are just the color of .ui-widget-content. Well, I can apply a class on alternating rows with no problem, but I want for the alternating color to be a very transparent version of the background color in .ui-widget-header. How would I do this using nothing but html jquery and CSS? (I'm really hoping to not have to use javascript in order to do this little trick though)

+2  A: 

Assuming that I didn't misunderstand your question, and that you can use a separate CSS class for alternate rows like .ui-widget-content-alt, you may want to use the following CSS:

.ui-widget-content, .ui-widget-content-alt {
    background-color: #000;
}

.ui-widget-content-alt {
    filter: alpha(opacity=20);
    opacity: 0.2;
}
  • The opacity property is the CSS standard for opacity values, and works in Firefox, Safari, Chrome and Opera.
  • The filter property is for IE.

You may want to check the following article for compatibility of the opacity property with older browsers:

Daniel Vassallo
My problem with that is that it tends to make the text also transparent and hard to read.. hmm... I'm not sure quite how to do this
Earlz
A: 

There is no standard way of doing it.

You can use css opacity and fiter to achieve it.

Something like the following would give you 80% black transparent color

    .someClass { background-color:#000; -moz-opacity: 0.8; opacity:.80;filter: alpha(opacity=80);}

Using this will cause your CSS to fail compliance checks.

Jeff
+1  A: 

The easiest way to do this is to create a small flat image in Photoshop, Fireworks, etc. and set the color / opacity there. The above solutions will allow for transparency but they are 1) Not standards-compliant and 2) May cause the text contained in the div to also be transparent (usually an undesirable result in design).

So...

.ui-widget-content-alt {
background: transparent url(images/my_80%transparent_black_bg.png) top left repeat;
}
.ui-widget-content {
background: transparent url(images/my_80%transparent_white_bg.png) top left repeat;
}
Brian
Dude, That is awesome and a great idea.. I'll accept it if I can get this to work, I'm pretty sure I can though.
Earlz
Wait, actually I'm not sure... I forgot how transparency worked in pictures for some reason.. hmm...
Earlz
What image editing program are you using? Photoshop?
Brian
I know how to make such a thing, I mean I forgot that you must actually set a color to be transparent against.. Like you can't just select a transparency value, like how `opaque` would work. and note, `ui-widget-content` is an autogenerated css class, I can't just modify it.
Earlz
Even if the class is autogenerated you should be fine. You're not messing with javascript in this solution, you're just altering CSS and uploading a background image for the CSS to grab... Just create a 10x10 pixel pure black or pure white image and set it's opacity in Photoshop. the "top left repeat" ensures it will stretch the full width and height of the DIV.
Brian
Ok, I got it figured out.. You just have to do something like `alternating-row div{}` and in it have the background transparent images. And apply the images on both rows(black/white alternating) in case of a black/white out condition with the existing background color.
Earlz