0

I have a block of html something like this:

<div class="message-box01">...</div>
<div class="message-box02">...</div>
<div class="message-box03">...</div>

The 2-digit number appended to 'message-box' is breaking my css because the definition is like so:

.message-box ul li {
  background: #fff;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 15px;
  font-size: 25px;
  text-align: center;
  padding-top: 15%;
  transition: all 0.2s ease-in-out;
}

So I'm wondering if there's a way to use a regex in the class definition, similar, I suppose, to what I'm seeing here: another css related page

to use pseudo-code:

.message-box[\d*] {
    ...
}

Or something like that.

Alternatively, is something like this possible:

[id^='messages-box'] ul li {
    list-style-type: none;
    float: left;
}
3
  • And what is supposed to change in each class? Why do not use a global class and ids for each of the elements? Commented Jun 1, 2016 at 13:22
  • excellent question, and one that I've asked the original page developer about. From what I can tell, those 2-digit ID's are somewhat extraneous but I can't be sure there's no relevance at all until I hear back from him. Commented Jun 1, 2016 at 13:38
  • Maybe you can set an ID more intuitive. For example: box01. Anyway, you will need to use message-box01 to change the styles for this element specifically so I do not think there is a lot of problems to add an ID. Commented Jun 1, 2016 at 13:44

1 Answer 1

6

If you have multiple classes with the same word you can use this

div[class^='message-box']{
  ...
}

The above code applies to every div whose class starts with message-box.

Sign up to request clarification or add additional context in comments.

2 Comments

brilliant, i've just found tis as well. Would something like this work? [id^='messages-box'] ul li { list-style-type: none; float: left; }
Is there a way to extract that number from css class name, padding-10 which will add padding of 10px, rather then writing multiple padding classes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.