Done this.
<h1 class="textcolor1 + text1">Heading 1</h1>
Seems to work for me (IE6). Don't now if this is a "legal" way to do it though.
BR MaB
Main Topics
Browse All TopicsI'm sure this must be pretty simple ...
I have this classes:
.textcolor1 {
color: #1B3E75;
}
.text1 {
font-size: 10pt;
text-decoration: none;
}
And now I wanna define H1 and I want it to have the values contained in .textcolor1 and .text1 ...
Is this possible?
I don't wanna write it all again ...
H1 {
color: #1B3E75;
font-size: 10pt;
text-decoration: none;
}
What I'm searching is that if there is a way to define H1 based on other elements...
Thx in advance!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Match a style to multiple selectors using a comma:
h1, .textcolor1 {
color: #1B3E75;
}
h1, .text1 {
font-size: 10pt;
text-decoration: none;
}
but don't use "pt": http://css-discuss.incutio
If you're not adding any "additional styles" to the h1 tag - you can use multiple class names in the tag itself.
Just separate the class names by spaces:
<html>
<head>
<style type="text/css">
.textcolor1 {
color: #1B3E75;
}
.text1 {
font-size: 10pt;
text-decoration: none;
}
</style>
</head>
<body>
<h1 class="textcolor1 text1">15 pixel text</h1>
</body>
Sure:
Doing this:
h1, .textcolor1 {
color: #1B3E75;
}
h1, .text1 {
font-size: 10pt;
text-decoration: none;
}
<h1>Modified Text</h1>
can also be done like this, without adding the h1, to the beginning of each of the styles:
.textcolor1 {
color: #1B3E75;
}
.text1 {
font-size: 10pt;
text-decoration: none;
}
<h1 class="textcolor1 text1">Modified Text</h1>
There is no way, in CSS, to say:
Everything that matches this pattern should be treated as if it also matched that pattern.
You can't inherit one style into another. The only inheritence in CSS is on properties, and they inherit from the parent element in the HTML document. (i.e. <a><b>x</b></a> a { color: red; } b { color: inherit; } - <b> inherits color: red from <a>)
That's why " ... the only thing is I think "inherit" is not the best term to apply here"
Actually you can do 'inheritance' so to speak in one other way at least:
.red { color: red;}
.blue { color: blue;}
<P class='red blue'>turns out blue</P>
see: http://www.experts-exchang
So what I'm after here is to see if I can now put them all together in one class.
When you say that "There is no way" do you mean 1) There is no way or 2) There is no way I know of ?
There is a way that I'm avoiding which is in PHP define a variable like:
$h1 = "color1 text1 bold undeline";
and in every <h1 class='<?=$H1?>'> but I was trying to learn if there is a way to do this only with CSS.
>>>When you say that "There is no way" do you mean 1) There is no way or 2) There is no way I know of ?
Obviously they are the same until you can prove there is a way. The comment makes this look more like an exercise to test rather than a question looking for a solution. If you the only acceptable resolution is to prove it cannot be done the way you want, then there can never be a resolution because such a negative can never be proved, and sometime in the future you may be able to do it the way you desire.
However if this really a search for alternative methods of generating style rules: then this rather inefficient dynamic application of styles client side scripting is, if nothing else, a different way of doing the sheet dynamically:
This looks like not much more than an excercise in
Use the DOM level 2 CSS interface to add the appropriate rule to a style
sheet in the document's HEAD.
IE does it this way:
<html>
<head>
<title>Demo</title>
<!-- style type="text/css">
body {text-align:center; }
</style -->
<script language="JavaScript">
<!--
function addRule(selector, declaration)
{
var sheet=document.styleSheets
sheet.addRule(selector,dec
}
//-->
</script>
</head>
<body>
<h3> this is h3 and won't change</h3>
<h1> this is h1 and will change </h1>
<p>
<a href="JavaScript:addRule('
this is the link to change it
</a>
</body>
</html>
for mozilla:
<html>
<head>
<title>style addition - Mozilla</title>
<script>
function change() {
var s=document.styleSheets[0];
s.insertRule("h1 {background-color:green}",
}
</script>
<style>
h2 {
background-color:blue;
}
</style>
</head>
<body>
<h2>Test Page</h2>
<h1>change</h1>
<form>
<input type='button' value='change' onclick='change()'>
</form>
</body>
</html>
Unfortunately, the cssRules objects that are exposed do not give enough access to the inner style declarations to migrate across in CSS2.
I don't know about the others in the thread, but when I say "there is no way"; it means "there is no way; but tomorrow is another day".
Right now there is no way but if the CSS3 proposals for scripted attributes get adopted all manner of things will become possible.
Cd&
I would say that dorward was the first to answer this question with this solution:
>Match a style to multiple selectors using a comma:
>
>h1, .textcolor1 {
> color: #1B3E75;
>}
>
>h1, .text1 {
> font-size: 10pt;
> text-decoration: none;
>}
>
>
>but don't use "pt": http://css-discuss.incutio
I would like to know why Drift3r doesn't find that a good solution. Otherwise i think the Q should be closed with points to dorward.
BR MaB
Mab was the first to try and understand the problem. Dorward was the first to say "it can't be done". COBOLdinosaur gave an alternative way to fix it.
I decided to split the points.
I accepted COBOl's answer cuz it's the answer that leaves space to solve the problem in the future.
Hope everyone agrees ...
Business Accounts
Answer for Membership
by: MaBPosted on 2004-02-04 at 23:04:40ID: 10278370
I don't think you can inherit (or add together) two classes. You can reuse one though.
1</h1>
<h1 class="textcolor1">Heading
I will try to find a way round the "double classes" problem....
BR MaB