Forum Moderators: not2easy

Message Too Old, No Replies

A DIV with two classes sharing an attribute

         

cyates

1:08 pm on May 20, 2003 (gmt 0)

10+ Year Member



Hello,

First I will describe what I'm trying to accomplish. Then I will describe my first unsuccessful attempt. I have created a calendar system. The events added to the calendar have two attributes, layer and category. A layer is basically a set of events that may apply to your user account and thus be available. For example, department X will have a layer that department Z can't see. However, one user may have access to 5 or more different layers.

At the top of the calendar I have two drop down menus which list the layers and categories with a checkbox. If you uncheck the checkbox it should hide that layer or category.

I've accomplished this, however with a problem. My first solution:

1 - Create a DIV class for each layer and each category.
.layer_agency { }
.layer_department { }
.layer_personal { }
.category_birthdays { }
.category_holidays { }
.category_meetings { }
2 - Surround each event with a div that uses both the layer and category class that it belongs to.
<div class="layer_agency category_holidays">Memorial Day</div>
3 - When unchecking a layer, set the visibility attribute of the layer class to hidden. Same with category.

The problem: After you uncheck, and then check a category it then sets visibility to visible. Now if you uncheck a layer it wont effect that category because the visibility attribute of the category overrides the visibility attribute of the layer.

Is there a way to do this that I'm missing? I think if the browser would override the attribute when hidden instead of when visible, the way I'm attempting this would work. Any help would be greatly appreciated. Thanks.

BlobFisk

1:42 pm on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, cyates!

Have you tried using an ID instead of a class to control the visibility of the the element?

cyates

2:14 pm on May 20, 2003 (gmt 0)

10+ Year Member



No, because I thought a DIV couldn't have two ID's. It can have two classes however. Unless you mean using <div id="layer_agency"><div id="category_holidays">Memorial Day</div></div>? If so, no, I haven't tried that. I will.

BlobFisk

3:21 pm on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's not quite what I had in mind. I think that I may not understand fully your methodology for your layer and your category.

I have approached it that each div has a unique id, and that you can turn the visibility on and off by changing the visibility attribute of that div via your checkboxes.

cyates

3:42 pm on May 20, 2003 (gmt 0)

10+ Year Member



Nope, there is no unique id. An event has both a layer and a category. It can be any combonation of the choices of layers and categories. Therefore there can be multiple div tags with a specific layer or a specific category. When you uncheck/check that layer or category then all the events inside a div tag with that layer or category will become visible or invisible.

cyates

6:02 pm on May 20, 2003 (gmt 0)

10+ Year Member



It seems this may be a browser limitation. When an element has two classes, and both of the classes have a common attribute, it always defaults to the inner-most class' attribute value. Or so it seems to me. I've only tested in IE.

cyates

6:09 pm on May 20, 2003 (gmt 0)

10+ Year Member



I take that back, it doesn't matter what order the classes appear in the div tag, it uses the attribute in the last declared class in the style tag.

For example,


<style type="text/css">
.c1 { COLOR: red; }
.c2 { COLOR: blue; }
</style>
<div class="c1 c2">This is the string</div>

This would result in a blue string.


<style type="text/css">
.c2 { COLOR: blue; }
.c1 { COLOR: red; }
</style>
<div class="c1 c2">This is the string</div>

This would result in a red string.

BlobFisk

9:48 am on May 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, that's why I was inquiring about the ID route - much easier to control something like visibility on an ID... although, looking at your scenario, it could be tricky.

cyates

12:39 pm on May 21, 2003 (gmt 0)

10+ Year Member



Yeah, I tried using ID's but it said the object was null when I tried to change visibility. I'm guessing that when more than one div exists with the same ID it creates an array. I haven't tested this theory yet, I only had around 10 minutes to try using ID's yesterday. (I'm kinda new to CSS).

If that's the case, I guess I can create a JS routine to loop through the array and set the visibility. That may work...unless the browser handles the visibility the same way with nested div's.

BlobFisk

2:54 pm on May 21, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ID in CSS refers to a unique element, therefore there should be only one instance of an ID within your html - this is probably what is causing your errors now.

I wonder if this problem should be readdressed from a 1st principles standpoint. That is, go right back to the beginning and see if there is another way to approach it.