Old 13-04-2008, 02:51   #1 (permalink)
turbo_j
Registered User
 
Join Date: Feb 2007
Posts: 8
Combining divs and classes

How do I reuse a block of code put in a class, sort of like the code below ?

.reusable {
float:left;
width:178px;
padding:8px;
margin:0 3px 0 0;
}
#container, .reusable {
background: url(../images/sb.jpg) no-repeat top left;
background-color:#e0f2ff;
}

thanks
  Reply With Quote
Old 13-04-2008, 05:06   #2 (permalink)
LukeV
Best custom title ever.
 
Join Date: Apr 2008
Posts: 95
No that wouldn't work. I think.

No it shouldn't. if you have a div with an id you can't just add styles from a class in the way you did there.
You'll have to retype the styles I'm afraid.
  Reply With Quote
Old 13-04-2008, 05:12   #3 (permalink)
seen.to
unusual suspect ™
 
seen.to's Avatar
 
Join Date: Jul 2004
Location: DE, USA
Posts: 2,511
Not quite sure what the OPs intention is. If it is just to apply both sets of styles to a single element then <div id="container" class="reusable"> would be fine.

If you want to apply everything contained within 'reusable' but only that contained within 'container' to your container div then you would switch what you have slightly to:

#container, .reusable {
float:left;
width:178px;
padding:8px;
margin:0 3px 0 0;
}

#container {
background: url(../images/sb.jpg) no-repeat top left;
background-color:#e0f2ff;
}

If you mean something else then explain your question better
__________________
  Reply With Quote
Old 13-04-2008, 11:45   #4 (permalink)
LukeV
Best custom title ever.
 
Join Date: Apr 2008
Posts: 95
Well I figured by the name of the class "reusable" that he wanted to reuse the style in the reusable class on an id which doesn't work that way. But I could have understood wrong :P
  Reply With Quote
Old 13-04-2008, 19:11   #5 (permalink)
turbo_j
Registered User
 
Join Date: Feb 2007
Posts: 8
I wanted something like function in other languages, something that you can reuse throughout
the code without having to type it again, doesn't matter if it is ID or class, give me some example where I can write something like:

.one class, second class, third class {
something unique that contains all three
}
  Reply With Quote
Old 13-04-2008, 19:39   #6 (permalink)
turbo_j
Registered User
 
Join Date: Feb 2007
Posts: 8
.monster, .one class, .second class, .third class {
monster contains something unique + all three classes
}
  Reply With Quote
Old 21-04-2008, 07:37   #7 (permalink)
paulmsmith
Paul Michael Smith
 
paulmsmith's Avatar
 
Join Date: Apr 2008
Location: Manchester, UK
Posts: 6
I think I know what you're asking turbo and in that case the answer is yes but not in the way you mean.

- Here are common attributes and their values for the three selectors.
#selector1, #selector2, .selector3 a {
attribute: val;
attribute: val;
attribute: val;
}

- Here you speficify the unique attributes/vals individually for the three selectors.
#selector1 { attribute: val; }
#selector2 { attribute: val; }
.selector3 a { attribute: val; }

Not the same as a function where you could pass in a different value for an attribute (as I understand what you want?) but you can override values from the common shared selectors within the unique selectors you have specified after.

Its the way the "Cascade" works in CSS. Its helps not think of CSS as a scripting language because its not that at all. It takes some time to understand the basics but once you have them down you can find nice ways to achieve what you want.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8