In below code, I want "Search By" in 1 line, the 2 radio buttons in next line just below, "Search Text" & text Box in 3rd line and Submit button in last line. I’ve used flexbox. Currently everything is coming in 1 single line.
body {
background: #ccc;
font-family: 'Garamond', sans-serif;
color: #000080;
}
h2 {
width: 25%;
text-align: center;
margin: auto;
padding: 15px;
}
.mytabs {
display: flex;
/*property of flex container to use flexbox*/
flex-wrap: wrap;
max-width: 1000px;
margin: 25px auto;
}
.mytabs input[type="radio"] {
display: none
}
.mytabs label {
padding: 25px;
font-weight: bold;
background: #e2e2e2;
font-size: 20px;
}
.mytabs .tab {
width: 100%;
background: #fff;
order: 1;
display: none;
}
.mytabs input[type='radio']:checked+label+.tab {
display: block;
}
.mytabs input[type="radio"]:checked+label {
background: #fff;
}
.form-group {
display: flex;
align-items: center;
justify-content: center;
margin: 40px 40px;
font-size: 20px;
}
.form-group input[type="radio"] {
display: block;
}
.form-group label {
padding: 5px;
margin: 5px;
font-weight: normal;
background: #fff;
font-size: 20px;
}
input[type=text] {
padding: 6px 8px;
margin: 8px 0;
box-sizing: border-box;
border: 1px solid navy;
border-radius: 4px;
}
<br><br>
<h2>Tool</h2>
<div class="mytabs">
<input type="radio" id="tabfree" name="mytabs" checked="checked">
<label for="tabfree">Tab1</label>
<div class="tab">
<form action="/submitu">
<div class="form-group">
<p>Search By :</p>
<input type="radio" id="user" name="srchusr" value="UserID" checked/>
<label for="user">Option1</label>
<input type="radio" id="group" name="srchusr" value="Group" />
<label for="group">Option2</label>
<label for="srchtxt">Search Text :</label><br>
<input type="text" id="srchtxt" name="srchtxt" value=""><br>
<input type="submit" value="Submit">
</div>
</form>
</div>
<input type="radio" id="tabsilver" name="mytabs">
<label for="tabsilver">Tab2</label>
<div class="tab">
<p>Tab2 Data</p>
</div>
</div>
2
Answers
Use
flex-direction:column
to have the elements vertically instead of horizontally, and wrap some elements in a div withdisplay:flex
, so that they are in 1 line.In the snippet below, i highlighted the changes I made to your code with "!!!" comments.
You can use grid. To structure a page, or a form, grid is really useful.