Style sheets, include one style within another (not inheritance)

F

foldface

Hi

Given something like this:

<style type="text/css">
DIV.allowLeft {clear: left;}
DIV.left {float: left;}
DIV.leftBig {float: left; width: 300}
DIV.rightBig {float: right; width: 300}
</style>

Is there anyway of placing the 'width:300' bit into another declaration
(pardon my terminology) so that I only have to change it in one place,
e.g. something like this:

<style type="text/css">
bigWidth = 300;
DIV.allowLeft {clear: left;}
DIV.left {float: left;}
DIV.leftBig {float: left; bigWidth}
DIV.rightBig {float: right; bigWidth}
</style>

The width is only going to apply to some divs

Thanks
F
 
B

Bertilo Wennergren

<style type="text/css">
DIV.allowLeft {clear: left;}
DIV.left {float: left;}
DIV.leftBig {float: left; width: 300}
DIV.rightBig {float: right; width: 300}
</style>
Is there anyway of placing the 'width:300' bit into another declaration
(pardon my terminology) so that I only have to change it in one place,

"width:300" is an error (it has no meaning). You probably meant
"width:300px" (and some browsers will guess that - which they
shouldn't). You should howevere consider setting the width in "em"s
instead, particularily if the content is text.
e.g. something like this:
<style type="text/css">
bigWidth = 300;
DIV.allowLeft {clear: left;}
DIV.left {float: left;}
DIV.leftBig {float: left; bigWidth}
DIV.rightBig {float: right; bigWidth}
</style>

No variables in CSS. But you can do this:

<style type="text/css">
DIV.allowLeft {clear: left;}
DIV.left {float: left;}
DIV.leftBig, DIV.rightBig {width: 300px;}
DIV.leftBig {float: left;}
DIV.rightBig {float: right;}
</style>

You can also use multiple classes. Like this:

HTML:

<div class="leftBig whatever">...</div>
<div class="rightBig whatever">...</div>

CSS:

<style type="text/css">
DIV.allowLeft {clear: left;}
DIV.left {float: left;}
DIV.whatever {width: 300px;}
DIV.leftBig {float: left;}
DIV.rightBig {float: right;}
</style>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top