Dropdown changes its size when page size is changed - html

I have a select element in my form. When i zoom in or zoom out my browser ,the select element gets resized and changes its position. Kindy help me out. I will attach the code also.
<div class="form-group">
<select class="form-control" style="height:50px;" id="search_color">
<option value=" " hidden>Color</option>
<option value="0">Red</option>
<option value="1">Green</option>
<option value="2">Blue</option>
<option value="3">Yellow</option>
<option value="4">Orange</option>
<option value="5">Purple</option>
<option value="6">Grey</option>
<option value="7">Multicolor</option>
</select>
</div>

Basically, bootstrap classes have some behavior that varies depending on the size of the screen. In your case, You can actually apply a basic HTML center tag to override bootstrap class behavior and retain your dropdown option to the center of the screen.
Try this one:
<div class="form-group">
<center>
<select class="form-control" style="height:50px;" id="search_color">
<option value=" " hidden>Color</option>
<option value="0">Red</option>
<option value="1">Green</option>
<option value="2">Blue</option>
<option value="3">Yellow</option>
<option value="4">Orange</option>
<option value="5">Purple</option>
<option value="6">Grey</option>
<option value="7">Multicolor</option>
</select>
</center>
</div>

Related

Dropdown is not showing after a page reloads

I have three dropdowns in my page, two of them are shown perfectly while the other one is not appearing, and when looking at the element in page it gets loaded with the "style="display: none;" value even if I'm forcing it with style="display: inline;".
Here's the code:
<div class="dropdown">
<div id="myBrokenDropdown" class="dropdown-content">
<select class='filter' id="notWorkingOne">
<option value=""> Select</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</div>
<!--select button-->
<div id="select1" class="dropdown-content">
<select class='filter' id="select1Works" data-col="1">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</div>
<div id="select2" class="dropdown-content">
<select class='filter' id="select2Works" data-col="5">
<option value=""> Select</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
</div>
</div>
Also, in jquery I can hide/Show the two dropdowns with the following code:
$('#select1Works').hide();
$('#select2Works').hide();
$('#notWorkingOne').hide();
$(document).ready(function() {
$("input[type='radio']").on('change', function() {
$("#select1Works").toggle($("[name=radioButton]").index(this) === 0);
$("#select2Works").val("").trigger("change");
$("#select2Works").toggle($("[name=radioButton]").index(this) === 1);
$("#select1Works").val("").trigger("change");
if ($('#select1Works').is(':visible') || $('#select2Works').is(':visible')) {
$('#notWorkingOne').show();
}
})
});
Why is the "myBrokenDropdown" not showing?
Thank you very much
It was an issue with a selector in my actual code, I missed a '#'.

Bootstrap form dropdown validation

I've been working on this bootstrap dropdown and the form still submits even though nothing has been selected. The inputs work. When left blank the form doesnt submit, but doesn't work in the dropdown selects. Any ideas? I've tried required, required="true", and required="required" on the select element.
https://getbootstrap.com/docs/4.0/components/forms/#validation
<div class="form-group--custom form-group">
<select class="form-control selectpicker" data-style="btn btn-link" id="C_Salutation" name="C_Salutation" title="Title" value="">
<option value="" disabled selected style="display: none;" id="C_Country-Placeholder">Business Markets Served*</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>
I can't see required in your code?
What about using required this way...
https://www.w3schools.com/tags/att_select_required.asp
<div class="form-group">
<select class="form-control" required>
<option value disabled selected>Business Markets Served*</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>

bootstrap select elements with fixed width do not display inline

I have the following list (where ... represents more):
<div class="form-group">
<label class="control-label col-sm-2" for="event_End Time">End time</label>
<div class="col-sm-10">
<select class="form-control" id="event_endtime_1i" name="event[endtime(1i)]" required="required" style="width: 20px">
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
...
</select>
<select class="form-control" id="event_endtime_2i" name="event[endtime(2i)]" required="required" style="width: 20px">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
...
</select>
<select class="form-control" id="event_endtime_3i" name="event[endtime(3i)]" required="required" style="width: 20px">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
...
</select>
— <select class="form-control" id="event_endtime_4i" name="event[endtime(4i)]" required="required" style="width: 20px">
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
...
</select>
: <select class="form-control" id="event_endtime_5i" name="event[endtime(5i)]" required="required" style="width: 20px">
<option value="00">00</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
...
</select>
</div>
</div>
I want the nice styling that the form-control css declaration offers, but the problem is that it appears to display the select element as a block and not inline, because the result looks like this:
The select elements are supposed to be sitting next to each other but they are not even though I specified a really really small width, just to prove my point:
http://www.bootply.com/rmtvHeYqFa
What is the correct way to display form-control declarations inline in bootstrap, so my select elements sit next to each other nicely?
Simple fix: You can override the .form-control class to use display: inline
.form-control { display: inline; }
Here's a bootply showing the change
I will add though that this will override ALL your .form-control classes in your project, so, you might instead want to give the elements you want inline another class, and give that class the property display: inline instead - you might need to add !important to override bootstrap in this case e.g.
.new__class { display: inline !important; }
But avoid using !important if you can

How can I get the label to stay at the top of the select element?

With this html:
<h2>Where (Location / Station)</h2>
<label for="selwhere">Select the locations for the job type selected above</label>
<select name="selwhere" id="selwhere" multiple="multiple">
<option value="linecook">Line cook</option>
<option value="barrista">Barrista</option>
<option value="securityguard">Security Guard</option>
<option value="fignipper">Nipper of Figs</option>
</select>
My label drops to the bottom of the select element:
I want it at the top, instead. What html or CSS do I need for that?
Just use vertical-align:top:
label {
vertical-align: top;
}
<label for="selwhere">Select the locations for the job type selected above</label>
<select name="selwhere" id="selwhere" multiple="multiple">
<option value="linecook">Line cook</option>
<option value="barrista">Barrista</option>
<option value="securityguard">Security Guard</option>
<option value="fignipper">Nipper of Figs</option>
</select>

bootstrap 3 show label in inline selectbox

I set label for select box menu in bootstrap 3 like this :
<div class="col-lg-2">
<label>Filter</label>
<select class="form-control" name="sort">
<option value="1">1</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
</select>
</div>
in output in see label in top of select box menu:
I need to show label inline of select box menu like this :
how do show label in inline ?!
DEMO JSFIDDLE
You need put your label and your select inside of a "group", so we have this:
<div class="form-group">
<label for="sort" class="col-sm-2 control-label"> Filter </label>
<div class="col-sm-10">
<select class="form-control" name="sort" id="sort">
<option value="1">1</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
</select>
</div>
</div>
You want form-inline - This example works in full screen mode (not sure why this code snippet wraps when not in full screen mode) but give it a whirl it should work for you.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form class="form-inline">
<div class="form-group">
<label for="dashboard-filter">Filter By</label>
<select id="dashboard-filter" class="form-control">
<option>1</option>
<option>2</option>
</select>
</div>
</form>
Docs are here: https://getbootstrap.com/docs/3.4/css/#forms-inline