3

I am trying to override the input type

input[type="number"] {

  width: 100px;

}

with the following css classes.

.choice_num{
    width: 83px;
    text-align:right;
    padding: 2px;
    font-weight: bold;
}

.choice_num_1{
    width: 82px;
    text-align:right;
    padding: 2px;
    font-weight: bold;
    margin-right: 2px;
}

.float_nums{
    width: 62px;
    text-align:right;
    padding: 2px;
    font-weight: bold;
}

but it doesn't seem to work. Any ideas?

This is the code that you asked (sorry it didn't occur to me to add it.)

<input type="number" class="choice_num" step="<?php echo $epilogi['posotita']; ?>" min="<?php echo $epilogi['posotita']; ?>" value="<?php echo $epilogi['posotita']; ?>" onchange="calculate()" id="a1" name="posotita">&nbsp;&nbsp;

<input type="text" class="tmxs" value="KG" readonly="readonly" name="monmetr">&nbsp;&nbsp;

<input type="number" class="choice_num_1" value="<?php echo $epilogi['timi']; ?>" id="a2" readonly="readonly">&nbsp;&nbsp;

<?php } ?>

<input type="number" class="float_nums" value="<?php echo number_format((float)$sum, 2, '.', ''); ?>" id="a3" readonly="readonly">
3
  • Please show us your html Commented Jul 24, 2020 at 8:56
  • 1
    Have a look at CSS specificity. The former has a higher specificity, and thus will not be overridden by the latter. Commented Jul 24, 2020 at 9:00
  • yes mate, I got it from the answers below. I really didn't think of that. Commented Jul 24, 2020 at 9:03

2 Answers 2

3

Just add input before them, like this,

input[type="number"] {
  background-color: orange
}

input.choice_num {
  background-color: blue
}

input.choice_num_1 {
  background-color: green
}

input.float_nums {
  background-color: red
}
<input type="number" />
<input type="number" class="choice_num" />
<input type="number" class="choice_num_1" />
<input type="number" class="float_nums" />

By doing it the specificity of the later selectors increase and thus ur css works,

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

1 Comment

why is necessary add that on elements input ???
3

Just add more priority to it. Fast way to do it:

Instead of .choice_num select input.choice_num

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.