Question:
I am using bootstrap select in my page and I need it to be empty by default (and value="")
when the page loads (it is a required field so when the user submits the form, the validation message will appear in case it’s empty).It actually works but it looks weird/odd/too flat:

And this would be the desired result:

I have used this attribute to make the select look empty:
data-none-selected-text=""
and it actually looks empty but too flat.If I remove that attribute, I’ll get this
Nothing selected
placeholder which I don’t want:
How can I make the design consistent and keep the same size whether something is selected or not?
body {
background-color: lightblue !important;
}
<head>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Bootstrap Select CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.14/dist/css/bootstrap-select.min.css">
</head>
<body>
<div class="container-fluid">
<div class="row mt-3">
<div class="col-sm">
Project Manager <span style="color:red;">*</span>
</div>
<div class="col-sm">
<select class="selectpicker show-tick w-100" data-none-selected-text="" multiple data-max-options="2" aria-label="Project Manager" required>
<option value="Michal Jackson">Michael Jackson</option>
<option value="Michael Jordan">Michael Jordan</option>
<option value="Luke Skywalker">Luke Skywalker</option>
<option value="Rafael Nadal">Rafael Nadal</option>
<option value="Cristiano Ronaldo">Cristiano Ronaldo</option>
<option value="Albert Einstein">Albert Einstein</option>
</select>
</div>
</div>
</div>
<!-- Popper.js 5.0.2 JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.9.2/umd/popper.min.js"></script>
<!-- Bootstrap 5.0.2 JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<!-- jQuery CDN -->
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<!-- Bootstrap Select JS BETA VERSION, UPDATE TO A STABLE VERSION COMPATIBLE WITH BS5 ONCE IT IS RELEASED-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.14.0-beta2/js/bootstrap-select.min.js"></script>
</body>
Answer:
You can overwrite default bootstrap class and make an exception for this scenario..dropdown-toggle {
height: 50px;
}
If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com
Leave a Review