I have the following form.
.form-control{
border-radius: 100vw;
margin-bottom: .75rem;
text-decoration: none;
appearance: none;
padding: 0.375rem 1.5rem !important;
position: relative;
}
.form-control:required::after{
content: '*';
font-size: 1.5rem;
color: #417A5F;
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 10px;
}
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div id="modalForm">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5>Form</h5>
</div>
<div class="modal-body">
<input type="text" class="form-control form-input" id="fname" placeholder="First Name" required>
<input type="text" class="form-control form-input" id="lname" placeholder="Last Name" required>
<select name="gender" class="form-control" id="gender" required>
<option value="Null" selected hidden>Gender</option>
<option value="M">Male</option>
<option value="F">Female</option>
</select>
<input type="date" name="dob" id="dob" class="form-control" placeholder="Date of Birth" required>
<input type="tel" name="phone" id="phone" class="form-control" placeholder="Phone Number" required>
<input type="email" name="email" id="email" class="form-control" placeholder="Email" required>
<input type="tel" name="zipcode" id="zipcode" class="form-control" placeholder="Zip Code">
<input type="text" name="street" id="street" class="form-control" placeholder="Address" required>
<input type="text" name="city" id="city" class="form-control" placeholder="City" required>
<select name="state" class="form-control" id="state" required>
<option value="Null" selected hidden>State</option>
</select>
</div>
<div class="modal-footer">
<button class="btn btn-primary">Button</button>
</div>
</div>
</div>
</div>
And currently I have the problem with the :required selector, because apparently it only recognizes one input of all those that are also in required. What could be happening?
Sr1871's answer is valid but some input types break the rule. Here is a list of how it affects
In these cases, extra elements and CSS are usually used. No js needed. For example we could use an extra div and the selector :has
This example would not be valid yet for Firefox as it does not have support enabled by default for these selectors.
https://developer.mozilla.org/en-US/docs/Web/CSS/:has#browser_compatibility
The problem is that the
pseudo-element
and only work on containing tags, and since input can't contain other elements, it doesn't:before
.:after
That is why it only appears in theselect
, since it does contain:after
given that it can contain other elements.You can verify that by removing the
:after
applies to all elements.Pseudo-selectors
:before
and:after
only work with tags that have a start and a close, for example ,<span></span>
they don't work with tags that don't have a close, for example<input stype="text">
So it would be best to come up with a javascript-based solution, since you're using Bootstrap I guess you're also using jQuery, so you can try something like this.
leaving something like this
However, what I recommend is that you do not complicate your life, simply add a label with your text without resorting to other methods.