I want to align the labels and as well as text-fields in this way:
But the output I get from my code is this:
And my code is:
<span class="questions">Your Date of birth: </span>
<input type="date" placeholder="DOB"/><br>
<span class="questions">Which Country You Are In:</span>
<select>
<option selected disabled>Select Country</option>
<option>India</option>
</select><br>
<span class="questions">In which University You Are In:</span>
<select>
<option selected disabled>Select University</option>
<option>AKTU</option>
</select><br>
<span class="questions">In which College You Are In:</span>
<select>
<option selected disabled>Select Your College</option>
<option>Raj kumar Goel Institute of Technology, Ghaziabad (RKGIT)</option>
</select><br>
<span class="questions">Your Mobile Number: </span>
<input type="tel" placeholder="Mobile Number"/><br>
<button class="btn">Proceed to Feeds.</button>
What should I add to CSS so that I get the required output or can I add before the <span> tag to adjust as the output required. Can anyone help me in this.
Try this:
.questions{
width:50%;
text-align:right;
display:inline-block;
}
input{width:150px;}
select{width:150px;}
<span class="questions">Your Date of birth: </span>
<input type="date" placeholder="DOB"/><br>
<span class="questions">Which Country You Are In:</span>
<select>
<option selected disabled>Select Country</option>
<option>India</option>
</select><br>
<span class="questions">In which University You Are In:</span>
<select>
<option selected disabled>Select University</option>
<option>AKTU</option>
</select><br>
<span class="questions">In which College You Are In:</span>
<select>
<option selected disabled>Select Your College</option>
<option>Raj kumar Goel Institute of Technology, Ghaziabad (RKGIT)</option>
</select><br>
<span class="questions">Your Mobile Number: </span>
<input type="tel" placeholder="Mobile Number"/><br>
<div align="center"> <button class="btn">Proceed to Feeds.</button><div>
Use form-horizontal class in form tag
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<form class="form-horizontal">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</form>
Watch this in fullpage
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$( function() {
$( "#datepicker" ).datepicker({
beforeShow: function(){
$("#abc").css('line-height', '14em')
},
});
} );
function chngecss(){
$("#abc").css('line-height', 'unset');
$('#datepicker').Close();
}
</script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h2>Horizontal form</h2>
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="dob">Your Date Of Birth :</label>
<div class="col-sm-5" id="abc">
<input class="form-control" type="text" id="datepicker" onblur="chngecss();" class="ui-datepicker" placeholder="DOB"/><br>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="country">In Which Country You Are In :</label>
<div class="col-sm-5">
<select class="form-control">
<option selected disabled>Select Your College</option>
<option>Raj kumar Goel Institute of Technology, Ghaziabad (RKGIT)</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="mobno">Your Mobile Number :</label>
<div class="col-sm-5">
<input type="text" class="form-control" id="mobno" placeholder="Enter Mobile Number">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-5">
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-5">
<input type="password" class="form-control" id="pwd" placeholder="Enter password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-5">
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-5">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</div>
Related
I have this form:
<div class="modal-body">
<form action="repository/add_new_task.php">
<div class="form-group">
<label for="street" class="col-form-label">Street</label>
<input type="text" class="form-control" id="street">
</div>
<div class="form-group">
<label for="phone" class="col-form-label">Phone</label>
<input type="text" class="form-control" id="phone">
</div>
<div class="form-group">
<label for="date" class="col-form-label">Date</label>
<div class="input-group date" id="datetimepicker" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" id="date" data-target="#datetimepicker">
<div class="input-group-append" data-target="#datetimepicker" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<div class="form-group">
<label for="price" class="col-form-label">Price</label>
<input type="text" class="form-control" id="price">
</div>
<div class="form-group">
<label for="comment" class="col-form-label">Comment</label>
<textarea type="text" class="form-control" rows="3" id="comment"></textarea>
</div>
<div class="form-group">
<label for="job-type" class="col-form-label">Comment</label>
<select class="form-control" id="job-type">
<option value="0">Repair</option>
<option value="1">Multistory Pull In</option>
<option value="2">Multistory Weld</option>
<option value="3">Private Residence</option>
</select>
</div>
<button type="submit" class="btn btn-primary btn-block" name="new-task-submit">Create task</button>
</form>
</div>
All I need to do is to make button disabled until all the fields (including datepicker and textarea) have values in them.
I tried following the answer in this post and while it worked I struggles to make it work for my datepicker and textarea. Can someone please help me figure this out
With just css you can use pointer events and make the button unclickable.
form:invalid [type="submit"] {
pointer-events: none;
border: 1px solid #999999;
background-color: #CCCCCC;
color: #666666;
}
<form>
<input type="text" required />
<input type="text" required />
<input type="text" required />
<input type="submit" />
You can use oninput and .disabled like so:
var field1 = document.getElementById("date");
var field2 = document.getElementById("phone");
var field3 = document.getElementById("price");
var field4 = document.getElementById("comment");
var field5 = document.getElementById("job-type");
var button = document.getElementById("btn");
function validate(){
if(!isEmpty(field1)&&!isEmpty(field2)&&!isEmpty(field3)&&!isEmpty(field4)&&!isEmpty(field5)){
btn.disabled=false;
}else{
btn.disabled=true;
}
}
function isEmpty(element){
if(element.value.length==0){
return true;
}else{
return false;
}
}
<div class="modal-body">
<form action="repository/add_new_task.php">
<div class="form-group">
<label for="street" class="col-form-label">Street</label>
<input type="text" class="form-control" id="street" oninput="validate()">
</div>
<div class="form-group">
<label for="phone" class="col-form-label">Phone</label>
<input type="text" class="form-control" id="phone" oninput="validate()">
</div>
<div class="form-group">
<label for="date" class="col-form-label">Date</label>
<div class="input-group date" id="datetimepicker" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input" id="date" data-target="#datetimepicker" oninput="validate()">
<div class="input-group-append" data-target="#datetimepicker" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
</div>
</div>
</div>
<div class="form-group">
<label for="price" class="col-form-label">Price</label>
<input type="text" class="form-control" id="price" oninput="validate()">
</div>
<div class="form-group">
<label for="comment" class="col-form-label">Comment</label>
<textarea type="text" class="form-control" rows="3" id="comment" oninput="validate()"></textarea>
</div>
<div class="form-group">
<label for="job-type" class="col-form-label">Comment</label>
<select class="form-control" id="job-type" onchange="validate()">
<option value="0">Repair</option>
<option value="1">Multistory Pull In</option>
<option value="2">Multistory Weld</option>
<option value="3">Private Residence</option>
</select>
</div>
<button type="submit" id="btn" class="btn btn-primary btn-block" name="new-task-submit" disabled>Create task</button>
</form>
</div>
If the user has not entered any text into any of the fields, the button will be disabled automatically.
I can't figure out how to center these rows in the middle of the page. I got the template from Bootstrap and was modifying it to fit my webpage. I'd like for the rows to be centered just like the text above it. This used to be a checkout form example but I've removed the items to the right of the rows.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="col-md-8 order-md-1">
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName">First name</label>
<input type="text" class="form-control" id="firstName" placeholder="" value="" required>
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="lastName">Last name</label>
<input type="text" class="form-control" id="lastName" placeholder="" value="" required>
<div class="invalid-feedback">
Valid last name is required.
</div>
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="birthmonth">Birthday</label>
<select class="custom-select d-block w-100" id="birthmonth" required>
<option value="">Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<div class="invalid-feedback">
Please select a valid month.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="zip">Day</label>
<input type="text" class="form-control" id="birthday" placeholder="" required>
<div class="invalid-feedback">
Day is required.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="birthyear">Year</label>
<input type="text" class="form-control" id="birthyear" placeholder="" required>
<div class="invalid-feedback">
Year is required.
</div>
</div>
</div>
<div class="mb-3">
<label for="country">University</label>
<select class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option>UC Berkeley</option>
<option>UC Davis</option>
<option>UC Irvine</option>
<option>UCLA</option>
<option>UC Riverside</option>
<option>UC San Francisco</option>
<option>UC Santa Barbara</option>
<option>UC Santa Cruz</option>
</select>
<div class="invalid-feedback">
Please select a valid university.
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="country">Country</label>
<select class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option>United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="state">State</label>
<select class="custom-select d-block w-100" id="state" required>
<option value="">Choose...</option>
<option>California</option>
</select>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="zip">Zip</label>
<input type="text" class="form-control" id="zip" placeholder="" required>
<div class="invalid-feedback">
Zip code required.
</div>
</div>
</div>
<div class="mb-3">
<label for="email">Password</label>
<input type="email" class="form-control" id="Password" placeholder="Password">
<div class="invalid-feedback">
Please enter a valid email address for shipping updates.
</div>
</div>
<div class="mb-3">
<label for="address">Repeat Password</label>
<input type="text" class="form-control" id="Password" placeholder="Password" required>
<div class="invalid-feedback">
Please enter the same password.
</div>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit">Submit</button>
</div>
Like #Klooven said, adding justify-content-center will fix it.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8 order-md-1">
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName">First name</label>
<input type="text" class="form-control" id="firstName" placeholder="" value="" required>
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="lastName">Last name</label>
<input type="text" class="form-control" id="lastName" placeholder="" value="" required>
<div class="invalid-feedback">
Valid last name is required.
</div>
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="birthmonth">Birthday</label>
<select class="custom-select d-block w-100" id="birthmonth" required>
<option value="">Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<div class="invalid-feedback">
Please select a valid month.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="zip">Day</label>
<input type="text" class="form-control" id="birthday" placeholder="" required>
<div class="invalid-feedback">
Day is required.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="birthyear">Year</label>
<input type="text" class="form-control" id="birthyear" placeholder="" required>
<div class="invalid-feedback">
Year is required.
</div>
</div>
</div>
<div class="mb-3">
<label for="country">University</label>
<select class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option>UC Berkeley</option>
<option>UC Davis</option>
<option>UC Irvine</option>
<option>UCLA</option>
<option>UC Riverside</option>
<option>UC San Francisco</option>
<option>UC Santa Barbara</option>
<option>UC Santa Cruz</option>
</select>
<div class="invalid-feedback">
Please select a valid university.
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="country">Country</label>
<select class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option>United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="state">State</label>
<select class="custom-select d-block w-100" id="state" required>
<option value="">Choose...</option>
<option>California</option>
</select>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="zip">Zip</label>
<input type="text" class="form-control" id="zip" placeholder="" required>
<div class="invalid-feedback">
Zip code required.
</div>
</div>
</div>
<div class="mb-3">
<label for="email">Password</label>
<input type="email" class="form-control" id="Password" placeholder="Password">
<div class="invalid-feedback">
Please enter a valid email address for shipping updates.
</div>
</div>
<div class="mb-3">
<label for="address">Repeat Password</label>
<input type="text" class="form-control" id="Password" placeholder="Password" required>
<div class="invalid-feedback">
Please enter the same password.
</div>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit">Submit</button>
</div>
</div>
</div>
use margin: 0 auto; in this
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<title></title>
</head>
<body>
<div class="container">
<div class="row ">
<div class="col-md-8 col-offset-md-2 order-md-1" style="margin:0 auto">
<div class="row">
<div class="col-md-6 mb-3">
<label for="firstName">First name</label>
<input type="text" class="form-control" id="firstName" placeholder="" value="" required>
<div class="invalid-feedback">
Valid first name is required.
</div>
</div>
<div class="col-md-6 mb-3">
<label for="lastName">Last name</label>
<input type="text" class="form-control" id="lastName" placeholder="" value="" required>
<div class="invalid-feedback">
Valid last name is required.
</div>
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="birthmonth">Birthday</label>
<select class="custom-select d-block w-100" id="birthmonth" required>
<option value="">Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<div class="invalid-feedback">
Please select a valid month.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="zip">Day</label>
<input type="text" class="form-control" id="birthday" placeholder="" required>
<div class="invalid-feedback">
Day is required.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="birthyear">Year</label>
<input type="text" class="form-control" id="birthyear" placeholder="" required>
<div class="invalid-feedback">
Year is required.
</div>
</div>
</div>
<div class="mb-3">
<label for="country">University</label>
<select class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option>UC Berkeley</option>
<option>UC Davis</option>
<option>UC Irvine</option>
<option>UCLA</option>
<option>UC Riverside</option>
<option>UC San Francisco</option>
<option>UC Santa Barbara</option>
<option>UC Santa Cruz</option>
</select>
<div class="invalid-feedback">
Please select a valid university.
</div>
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="country">Country</label>
<select class="custom-select d-block w-100" id="country" required>
<option value="">Choose...</option>
<option>United States</option>
</select>
<div class="invalid-feedback">
Please select a valid country.
</div>
</div>
<div class="col-md-4 mb-3">
<label for="state">State</label>
<select class="custom-select d-block w-100" id="state" required>
<option value="">Choose...</option>
<option>California</option>
</select>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="zip">Zip</label>
<input type="text" class="form-control" id="zip" placeholder="" required>
<div class="invalid-feedback">
Zip code required.
</div>
</div>
</div>
<div class="mb-3">
<label for="email">Password</label>
<input type="email" class="form-control" id="Password" placeholder="Password">
<div class="invalid-feedback">
Please enter a valid email address for shipping updates.
</div>
</div>
<div class="mb-3">
<label for="address">Repeat Password</label>
<input type="text" class="form-control" id="Password" placeholder="Password" required>
<div class="invalid-feedback">
Please enter the same password.
</div>
</div>
<hr class="mb-4">
<button class="btn btn-primary btn-lg btn-block" type="submit">Submit</button>
</div>
</div>
</div>
</body>
</html>
Would someone please tell me what is wrong with this?
.container {
margin-top: 10px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="panel panel-primary">
<div id="panel-head" class="panel-heading">
Edit Widget
</div>
<div class="panel-body">
<div class="row"><label for="title" class="col-sm-1 control-label">Title</label>
<div class="col-sm-5"><input type="text" id="title" required="required" class="form-control"></div>
<label for="widget_type_id" class="col-sm-1 control-label">Widget Type</label>
<div class="col-sm-5"><select id="widget_type_id" class="form-control">
<option disabled="disabled" value="">Please select one</option>
<option value="1">
2D column
</option>
<option value="2">
Multi-series 2D column
</option>
<option value="3">
Multi-series 3D column and line
</option>
<option value="4">
Gauge
</option>
<option value="5">
Datatable
</option>
<option value="6">
Counter
</option>
</select></div>
</div>
<div class="row">
<label for="link" class="col-sm-1 control-label">Link</label>
<div class="col-sm-5">
<input type="text" id="link" class="form-control">
</div>
<label for="font_size" class="col-sm-1 control-label">Font Size</label>
<div class="col-sm-2">
<input type="text" id="font_size" class="form-control">
</div>
</div>
<div class="row">
<label for="caption" class="col-sm-2 control-label">caption</label>
<div class="col-sm-4"><input type="text" id="caption" class="form-control"></div>
</div>
<div class="row">
<label for="subcaption" class="col-sm-2 control-label">subcaption</label>
<div class="col-sm-4">
<input type="text" id="subcaption" class="form-control">
</div>
</div>
<div class="row">
<label for="yaxisname" class="col-sm-2 control-label">yaxisname</label>
<div class="col-sm-4"><input type="text" id="yaxisname" class="form-control"></div>
</div>
</div>
</div>
There is not any padding between the caption, subcaption and yaxisname fields.
Give form-group instead of row and add <form class="form-horizontal editform">.
.container {
margin-top: 10px;
}
.editform.form-horizontal .control-label {
text-align: left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="panel panel-primary">
<div id="panel-head" class="panel-heading">
Edit Widget
</div>
<div class="panel-body">
<form class="form-horizontal editform">
<div class="form-group"><label for="title" class="col-sm-1 control-label">Title</label>
<div class="col-sm-5"><input type="text" id="title" required="required" class="form-control"></div>
<label for="widget_type_id" class="col-sm-1 control-label">Widget Type</label>
<div class="col-sm-5"><select id="widget_type_id" class="form-control">
<option disabled="disabled" value="">Please select one</option>
<option value="1">
2D column
</option>
<option value="2">
Multi-series 2D column
</option>
<option value="3">
Multi-series 3D column and line
</option>
<option value="4">
Gauge
</option>
<option value="5">
Datatable
</option>
<option value="6">
Counter
</option>
</select></div>
</div>
<div class="form-group">
<label for="link" class="col-sm-1 control-label">Link</label>
<div class="col-sm-5">
<input type="text" id="link" class="form-control">
</div>
<label for="font_size" class="col-sm-1 control-label">Font Size</label>
<div class="col-sm-2">
<input type="text" id="font_size" class="form-control">
</div>
</div>
<div class="form-group">
<label for="caption" class="col-sm-2 control-label">caption</label>
<div class="col-sm-4"><input type="text" id="caption" class="form-control"></div>
</div>
<div class="form-group">
<label for="subcaption" class="col-sm-2 control-label">subcaption</label>
<div class="col-sm-4">
<input type="text" id="subcaption" class="form-control">
</div>
</div>
<div class="form-group">
<label for="yaxisname" class="col-sm-2 control-label">yaxisname</label>
<div class="col-sm-4"><input type="text" id="yaxisname" class="form-control"></div>
</div>
</form>
</div>
</div>
See this:
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.container {
margin-top: 10px;
}
.form-group {
margin-bottom: 10px;
display: inline-block;
width: 100%;
}
<div class="panel panel-primary">
<div id="panel-head" class="panel-heading">
Edit Widget
</div>
<div class="panel-body">
<div class="row">
<div class="form-group">
<label for="title" class="col-sm-1 control-label">Title</label>
<div class="col-sm-5"><input type="text" id="title" required="required" class="form-control"></div>
<label for="widget_type_id" class="col-sm-1 control-label">Widget Type</label>
<div class="col-sm-5"><select id="widget_type_id" class="form-control">
<option disabled="disabled" value="">Please select one</option>
<option value="1">
2D column
</option>
<option value="2">
Multi-series 2D column
</option>
<option value="3">
Multi-series 3D column and line
</option>
<option value="4">
Gauge
</option>
<option value="5">
Datatable
</option>
<option value="6">
Counter
</option>
</select></div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="link" class="col-sm-1 control-label">Link</label>
<div class="col-sm-5">
<input type="text" id="link" class="form-control">
</div>
<label for="font_size" class="col-sm-1 control-label">Font Size</label>
<div class="col-sm-2">
<input type="text" id="font_size" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="caption" class="col-sm-2 control-label">caption</label>
<div class="col-sm-4"><input type="text" id="caption" class="form-control"></div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="subcaption" class="col-sm-2 control-label">subcaption</label>
<div class="col-sm-4">
<input type="text" id="subcaption" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<label for="yaxisname" class="col-sm-2 control-label">yaxisname</label>
<div class="col-sm-4"><input type="text" id="yaxisname" class="form-control"></div>
</div>
</div>
</div>
</div>
This is example HTML for Form component with their default classes provided by Bootstrap.
<form>
<div class="form-group">
<label for="exampleFormControlInput1">Email address</label>
<input type="email" class="form-control" id="exampleFormControlInput1" placeholder="name#example.com">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Example select</label>
<select class="form-control" id="exampleFormControlSelect1">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlSelect2">Example multiple select</label>
<select multiple class="form-control" id="exampleFormControlSelect2">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Example textarea</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
</form>
Ref. Link - http://getbootstrap.com/docs/4.0/components/forms/
Try to use their default classes and if you need any customization, add your custom classes to elements and override the styles.
You can do one thing, first of all you can use form tag as parent class and then apply margin top to all label, instead to container class. or your can give a class to label tag like .customlabel and than use this class and add property. for example.
form label{
float:left;
with:100%;
margin-top:10px;
}
.customlabel {
float:left;
with:100%;
margin-top:10px;
}
For some reason bootstrap's CSS manages to hide some (but not all) of my hrs at certain widths.
If you go to This fiddle and expand the output pane to be wide enough, you'll notice that the hrs between "attachment", "add attachment", and "Department" all vanish. Why?
How can I get them to show up at any width?
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="body-content">
<form action="/Reports/Edit/5" method="post" novalidate="novalidate"> <div class="form-horizontal">
<h4>Report</h4>
<hr>
<div class="form-group">
<label class="control-label col-md-2" for="ShortageFilledDate">Date Shortage Filled</label>
<div class="col-md-10">
<input name="ShortageFilledDate" class="form-control text-box single-line" id="ShortageFilledDate" type="datetime" value="" data-val="true" data-val-date="The field Date Shortage Filled must be a date.">
<span class="field-validation-valid text-danger" data-valmsg-replace="true" data-valmsg-for="ShortageFilledDate"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="ReplanClosedDate">Date Replan Closed</label>
<div class="col-md-10">
<input name="ReplanClosedDate" class="form-control text-box single-line" id="ReplanClosedDate" type="datetime" value="" data-val="true" data-val-date="The field Date Replan Closed must be a date.">
<span class="field-validation-valid text-danger" data-valmsg-replace="true" data-valmsg-for="ReplanClosedDate"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Save">
</div>
</div>
</div>
</form>
<hr>
<div class="col-md-2">attachment:</div><div class="col-md-10">logo.png</div>
<hr>
<form action="/Reports/AddAttachment" enctype="multipart/form-data" method="post"><input name="reportId" id="reportId" type="hidden" value="5"> <div class="form-group">
<label class="control-label col-md-2" for="Add_Attachment">Add Attachment</label>
<div class="col-md-10">
<input name="upload" id="attachment" type="file">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Upload Attachment">
</div>
</div>
</form>
<hr>
<form action="/Reports/SendToDepartment" method="post"><input name="ReportId" id="ReportId" type="hidden" value="5"> <div class="form-group">
<label class="control-label col-md-2" for="Department">Department</label>
<div class="col-md-10">
<select name="Department" class="form-control" id="Department"><option value="">Select Next Department Location</option>
<option value="0">Production</option>
<option value="1">DMRClerk</option>
<option value="2">QualityEngineer</option>
<option value="3">Stockroom</option>
<option value="4">Purchasing</option>
<option value="5">Shipping</option>
<option value="6">Archive</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="Comments">Comments</label>
<div class="col-md-10">
<textarea name="Comments" id="Comments" rows="3" cols="200"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Send to Department">
</div>
</div>
</form>
<div>
Back to List
</div>
<hr>
<footer>
<p class="text-center">© 2016</p>
</footer>
</div>
</body>
It is because when not in smaller views (xs) the classes uses float:left
so the hr is being used after those classes, therefore must cleared before.
you can use bootstrap class clearfix for that
.body-content hr {
border-color: red
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<body>
<div class="body-content">
<form action="/Reports/Edit/5" method="post" novalidate="novalidate">
<div class="form-horizontal">
<h4>Report</h4>
<hr>
<div class="form-group">
<label class="control-label col-md-2" for="ShortageFilledDate">Date Shortage Filled</label>
<div class="col-md-10">
<input name="ShortageFilledDate" class="form-control text-box single-line" id="ShortageFilledDate" type="datetime" value="" data-val="true" data-val-date="The field Date Shortage Filled must be a date.">
<span class="field-validation-valid text-danger" data-valmsg-replace="true" data-valmsg-for="ShortageFilledDate"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="ReplanClosedDate">Date Replan Closed</label>
<div class="col-md-10">
<input name="ReplanClosedDate" class="form-control text-box single-line" id="ReplanClosedDate" type="datetime" value="" data-val="true" data-val-date="The field Date Replan Closed must be a date.">
<span class="field-validation-valid text-danger" data-valmsg-replace="true" data-valmsg-for="ReplanClosedDate"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Save">
</div>
</div>
</div>
</form>
<hr>
<div class="col-md-2">attachment:</div>
<div class="col-md-10">logo.png
</div>
<div class="clearfix"></div>
<hr>
<form action="/Reports/AddAttachment" enctype="multipart/form-data" method="post">
<input name="reportId" id="reportId" type="hidden" value="5">
<div class="form-group">
<label class="control-label col-md-2" for="Add_Attachment">Add Attachment</label>
<div class="col-md-10">
<input name="upload" id="attachment" type="file">
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Upload Attachment">
</div>
</div>
</form>
<div class="clearfix"></div>
<hr>
<form action="/Reports/SendToDepartment" method="post">
<input name="ReportId" id="ReportId" type="hidden" value="5">
<div class="form-group">
<label class="control-label col-md-2" for="Department">Department</label>
<div class="col-md-10">
<select name="Department" class="form-control" id="Department">
<option value="">Select Next Department Location</option>
<option value="0">Production</option>
<option value="1">DMRClerk</option>
<option value="2">QualityEngineer</option>
<option value="3">Stockroom</option>
<option value="4">Purchasing</option>
<option value="5">Shipping</option>
<option value="6">Archive</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="Comments">Comments</label>
<div class="col-md-10">
<textarea name="Comments" id="Comments" rows="3" cols="200"></textarea>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input class="btn btn-default" type="submit" value="Send to Department">
</div>
</div>
</form>
<div>
Back to List
</div>
<hr>
<footer>
<p class="text-center">© 2016</p>
</footer>
</div>
<script src="Scripts/jquery-1.10.2.js"></script>
<script src="Scripts/bootstrap.js"></script>
</body>
This is just another pitfall of the bootstrap framework(one of the reasons why I kinda hate using bootstrap).
When bootstrap is included in an application, the styles in bootstrap.css voluntarily/involuntarily overrides your HTML elements. This is exactly what happened to your <hr> tags. As you can see in a browser debugger your HRs now will have the following piece of code coming from bootstrap.css line 1140.
//coming from bootstrap.css line:1140
hr {
margin-top: 20px;
margin-bottom: 20px;
border: 0; //this is causing the issue
border-top: 1px solid #eee;
}
//coming from bootstrap.css line:1140
The border: 0 is causing the issue in this case, Nonetheless I would suggest not using <hr> & start using properties like border-bottom or so to get the separator effect.
I am trying to build a form which has structure like given in the screen below
Amount control group has three input elements but the right edge of last element has to be aligned with Frequency object's input..
I can't make it in bootstrap somehow, can anyone please help me out?
Code here :
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="mDrugAmount">Amount </label>
<div class="controls">
<input class="input-small" data-bind="value: Dose" type="text">
<select class="input-mini">
<option value=""> </option>
<option value="">mg</option>
<option value="">mL</option>
</select>
<select class="input-mini">
<option value=""> </option>
<option value="">IM</option>
<option value="">IV</option>
<option value="">subcut</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="mDrugFrequency">Frequency </label>
<div class="controls">
<select>
<option value=""> </option>
<option value="">4 hourly</option>
<option value="">6 hourly</option>
<option value="">8 hourly</option>
<option value="">alto die</option>
<option value="">bd</option>
<option value="">bd</option>
<option value="">daily</option>
<option value="">infusion</option>
<option value="">mane</option>
<option value="">nocte</option>
<option value="">qid</option>
<option value="">tds</option>
<option value="">weekly</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="mCommenceDate">Commence </label>
<div class="controls">
<input type="text" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="mPrescriptionDate">Until </label>
<div class="controls">
<input type="text" value="">
</div>
</div>
<div class="control-group submit-row">
<div class="control-label">
Submit
</div>
<div class="control-label">
Cease
</div>
<div class="control">
</div>
</div>
</form>
Here is my JSFiddle - http://jsfiddle.net/az6zpha3/1/
i have updated the fiddle
http://jsfiddle.net/az6zpha3/6/
you can change the class Name if it is conflicting with bootstrap
.form-horizontal{
width:400px;
}
.input-mini{
min-width:30%;
}
HTML
i have changed class name "input-small" to "input-mini"
<form class="form-horizontal" _lpchecked="1">
<div class="control-group">
<label class="control-label" for="mDrugAmount">Amount </label>
<div class="controls">
<input class="input-mini" data-bind="value: Dose" type="text">
<select class="input-mini"><option value=""> </option><option value="">mg</option><option value="">mL</option></select>
<select class="input-mini"><option value=""> </option><option value="">IM</option><option value="">IV</option><option value="">subcut</option></select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="mDrugFrequency">Frequency </label>
<div class="controls">
<select><option value=""> </option><option value="">4 hourly</option><option value="">6 hourly</option><option value="">8 hourly</option><option value="">alto die</option><option value="">bd</option><option value="">bd</option><option value="">daily</option><option value="">infusion</option><option value="">mane</option><option value="">nocte</option><option value="">qid</option><option value="">tds</option><option value="">weekly</option></select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="mCommenceDate">Commence </label>
<div class="controls">
<input type="text" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="mPrescriptionDate">Until </label>
<div class="controls">
<input type="text" value="">
</div>
</div>
<div class="control-group submit-row">
<div class="control-label">
Submit
</div>
<div class="control-label">
Cease
</div>
<div class="control">
</div>
</div>
</form>