1

Maybe the answer is simple but I can't figure it out... sorry for the noobish question.

I have several html elements using the same css classes :

<a class="class1 class2 class3"></a>

How can I specify only one common class for all my elements ?

<a href="commonclass"></a>

thanks

4
  • 1
    Those are HTML classes (CSS doesn't have classes, although it does have class selectors). I have no idea what you are trying to achieve though.
    – Quentin
    Commented Feb 11, 2013 at 11:17
  • 2
    @MM. — I've no idea what you expect to be done with jQuery, but I can't see anything in the question that suggests "Adding JavaScript" would be beneficial.
    – Quentin
    Commented Feb 11, 2013 at 11:20
  • so you are trying to create an "alias"? I think there is not a simple solution for this: stackoverflow.com/questions/2718642/… Commented Feb 11, 2013 at 11:21
  • Yes, what I'm looking for is similar to an alis... I have this .help { float: right; } I want to display a jquery icon this way : <a href="#" class="help ui-icon ui-icon-help ui-state-default ui-corner-all" id="helppnom"></a> I would like to shorten the class attribute in my link since I have the same link several times. Is there a way to do that or do I have to set the classes each time ?
    – ThEBiShOp
    Commented Feb 11, 2013 at 11:52

4 Answers 4

1
  1. Apply css for all elements then use * Universal Selector

    * { padding: 0; margin: 0; }
    
  2. Apply css for all a elements in a document, then use Tag Selector

    a { color: red; }
    

30 CSS Selectors

1

Take the styles from class1 etc. and put them into a seperate class.

.class1 {
  color: green;
}
.class2 {
  border: 1px solid black;
}

Will then become:

.combined {
  color: green;
  border: 1px solid black;
}
0

I suppose you are looking for macro-like facilities such as found in some CSS frameworks like LESS, where you can define the properties for class1 and class2 as a sort of macro or quasi-class, then define what you call commonclass in terms of them.

0
0

I'm not sure if you want to use the same css rule for "several html elements" or "all my elements". If you want to use the same css rule for several elements, put a comma between the elements, like this:

a, li, p { color:red; }

Not the answer you're looking for? Browse other questions tagged or ask your own question.