I am trying to override the width in the form-control class of Bootstrap 3.
Snippet:
<div class="col-xs-2">
<label for="input-lastname" class="">Last Name</label>
<input type="text" name="lastname" class="form-control my-form-inline" id="input-lastname" value="<?php echo isset($_GET['lastname']) ? $_GET['lastname'] : 'empty'; ?>">
</div>...
I have this:
.form-control {
min-width: 0;
width: 25px;
color:red;
}
width
never works but the color:red
does. Using the developer tools in Chrome, I see where .form-control
.form-inline
have width:auto
. As soon as I uncheck width
in those classes, I get my custom class.
I have my custom css as the last file loaded, so the order should be right.
I have tried:
.form-control, .my-form-inline {
min-width: 0;
width: 25px;
color:red;
}
.form-control {
min-width: 0;
width: 25px;
color:red;
}
.form-control, .form-inline, .my-form-inline{
min-width: 0;
width: 25px;
color:red;
}
I seem to be able to override everything but the width. My form's class is form-inline
.
I have tried putting the form controls in a div with col-md-2
(and xs), but it only seems to affect the label, not the input. I can never override the width:auto
unless I do it inline on the control in the HTML. Removing the form-control
class also allows me, as expected, to get my custom class.
EDIT: For whatever reason, the forms.less mixin is winning over the style I load last.
EDIT: The problem has to do with my specificity vs. Bootstrap's. I have this inline in the header:
@media (min-width: 768px) {
.form-inline .form-control {
display: inline-block;
width: auto;
vertical-align: middle;
}
.my-form-inline
{
min-width: 0;
width: 25px;
color:red;
}
}
But the width is still overridden by some specificity I cannot find.
There are two main ways you can override Bootstrap CSS: Override using a higher specificity selector and properties via CSS. Using Bootstrap Sass variables (recommended)
To override the CSS properties of a class using another class, we can use the ! important directive. In CSS, ! important means “this is important”, and the property:value pair that has this directive is always applied even if the other element has higher specificity.
To create a custom checkbox, wrap a container element, like <div>, with a class of .custom-control and .custom-checkbox around the checkbox. Then add the .custom-control-input to the input with type="checkbox".
Try to add !important
after width property value
as:
.form-control {
min-width: 0;
width: 25px !important;
color:red;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With