| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
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 |
|
|
|
|
|
#3 (permalink) |
|
unusual suspect ™
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 |
|
|
|
#5 (permalink) |
|
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 } |
|
|
|
#7 (permalink) |
|
Paul Michael Smith
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. |
|
![]() |