I need to provide the user certain options to choose. I have a checkbox
, a checkbox text
, a dropdown
and another checkbox
. There will be a bunch of them and I need to put them down in such a way that they are put horizontally until it takes up the full screen and then the next group is aligned vertically by the first checkbox of previous group. Here is the jsfiddle I have shared https://jsfiddle.net/tmpceqy3/
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.2/skins/all.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.2/icheck.min.js"></script>
<div class="checkbox-inline">
<input type="checkbox">India
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">America
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">Australia
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">England
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">Holland
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">Greece
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">Egypt
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">France
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
<div class="checkbox-inline">
<input type="checkbox">Japan
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>   
<input type="checkbox">
</div>
Here is how it currently looks like
As you can see, I have a group of html elements per row (checkbox, checkbox text, dropdown, checkbox)
. I have used  
to create space between dropdown
and checkbox
since they both were appearing on top of another.
Now I want to put them horizontally until it takes the full screen. Then the next group should appear in the next line but vertically aligned by the first checkbox of each group in previous row.
I have tried something like display: flex
and got something like below
It’s able to split it into multiple lines but the checkboxes are screwed up.
How can I achieve the desired result?
4
Answers
Please add the class in parent like this and CSS, I have done changes in jsfield as well you could check there as well here is the link: https://jsfiddle.net/cgaL462s/ :
Made some changes in fiddle and got the desired results. Below there is link to the fiddle.
https://jsfiddle.net/9qfh0yum/
when using
flex
you need to add a flex value to the children. This allows them to know what space they should take up.Example below:
P.S. Make sur you use
name
id
andfor
attributes on your inputs so the browser knows what you you want to do.fiddle: https://jsfiddle.net/kvL8f5h0/1/
Change the width of the window to see how it will switch between the two stlyes.
HTML
CSS
Your fancier style for the input elements does not come through but that is not the question here. I put the labels in a label so I could style them a bit.
Your results may vary with the above noted difference.