1

Consider the following HTML and CSS codes

I can't figure out why the button text is not red, and I also don't know how to let the parent override the button's color:

.red {
  color: red !important;
}
<div class="red">
  <button>Should be red</button>
</div>

2 Answers 2

3

The button has an explicit color defined by the browser's stylesheet. You can change the button's color to inherit, and then it would get the color from the parent:

button {
  color: inherit;
}

.red {
  color: red;
}
<div class="red">
  <button>Should be red</button>
</div>

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

Comments

0

If your project uses a single type of button with the same styles, you can use the following CSS code:

button {
  color: red;
}

If you have different types of buttons, assign a different class to each button and define the styles separately. For example:

HTML:

<button class="btn1"></button>

CSS:

.btn1 {
  color: red;
}

Comments

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.