Forum Moderators: not2easy

Message Too Old, No Replies

Quick CSS class question

Wondering how to inherit values

         

letsgetsilly

4:12 pm on May 31, 2006 (gmt 0)

10+ Year Member



I've got a "mainbody" class in my CSS sheets, but I have different sheets with different fixed heights, but the rest of the values are true for the main body.

If I were to do something like

mainbody.page1{
height:XXpx;
}

Would that code inherit the mainbody class?

Then to reference in the html code, just use

class="page1"

many thanks for the great help here.

johnl

8:00 pm on May 31, 2006 (gmt 0)

10+ Year Member



hi,

if you have got a class mainbody with mainbodyattributes and another class page1 with page1attributes and want some elements to have as well mainbodyattributes as page1attributes you might use both classes like in:


<div name="complex" class="mainbody page1">

and use the selectors .mainbody and .page1

So if you declare


.mainbody {color: red;}
.page1 {height: 12px;}

the div named "complex" will be red and have a height of 12px;

Your suggested selector


mainbody.page1

will not work in the intended way, because it will select an element called mainbody and not an element with class mainbody. To select all elements which belong as well to class mainbody as to class page1 you might write:


.mainbody.page1

Hope it helps (and also that I remembered correctly).

letsgetsilly

8:12 pm on May 31, 2006 (gmt 0)

10+ Year Member



Thanks so much for your reply, I'll try out your suggestions, they look good! No worries if you haven't remembered correctly.

letsgetsilly

8:15 pm on May 31, 2006 (gmt 0)

10+ Year Member



To call the class "page1" from

.mainbody.page1

class="page1"? Assuming there are no independent classes by the name page1?

johnl

8:28 pm on May 31, 2006 (gmt 0)

10+ Year Member



hi,
it's not clear to me what you mean by:

To call the class "page1" from
.mainbody.page1

.mainbody.page1 is a selector and selects any element which belongs to both classes.
.mainbody is also a selector and selects any element which belongs to class mainbody.

If you still are puzzled, perhaps it helps to post some code (html as well as css - but only enough of either to clear your problems).