I have an HTML form. I want the first label asking a question and the list of radio buttons with corresponding labels to appear in one-line. And the second label asking a question and the list of check boxes with corresponding labels to appear in one-line. I have posted my code below. Tell me what do I need to add and how to to the styling in CSS.
.jumbotron{
position:relative;
background : #000 url(background.jpg) center center;
background-size: cover;
overflow:hidden;
margin-bottom:0px;
}
.box{
position:relative;
background-color:#5DBCD2;
width:90%;
margin-top:0.5%;
height:98.5%;
margin-bottom:1%;
margin-left:5%;
margin-right:5%;
}
.navbar{
min-height: 60px;
margin-bottom:0px;
}
.navbar-inverse{
background-color:#00FF00;
border-color:#00FF00;
font-size:150%;
font-weight:bold;
}
.navbar-inverse .navbar-nav>li>a {
color:#000000;
}
.navbar-inverse .navbar-brand {
color: #ff0000;
font-weight: bold;
font-size:150%;
}
.navbar-inverse .navbar-nav>.active>a, .navbar-inverse .navbar-nav>.active>a:focus, .navbar-inverse .navbar-nav>.active>a:hover{
background-color:#800080;
}
#index .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.index, #experience .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.experience, #video .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.video ,#hkust .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.hkust ,#feedback .navbar-inverse>.container-fluid>.navbar-collapse>.navbar-nav>.feedback
{
background-color:#ff69b4;
}
.text
{
padding-top:0.5%;
padding-bottom:0.5%;
text-align: center;
}
.form
{
border-radius: 25px;
background-color:#f4f9a6;
margin-left:5%;
margin-right:5%;
width:90%;
height:80%;
margin-top:0.5%;
margin-bottom:1%;
padding-left:10%;
padding-right:10%;
padding-top:10px;
padding-bottom:20px;
}
input[type="text"] {
width: 70%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<b class="navbar-brand">Vivek's Site</b>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li class="index">Home</li>
<li class="experience">Experience</li>
<li class="video">Videos</li>
<li class="hkust">HKUST Life</li>
<li class="feedback">Feedback</li>
</ul>
</div>
</div>
</nav>
<div class="jumbotron">
<div class="box">
<div class="text">
<h1><u>Feedback Form</u></h1>
</div>
<div class="form">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="email">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="name" placeholder="Enter name">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="position">Position:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="position" placeholder="Enter position">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="organization">Organization:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="organization" placeholder="Enter organization">
</div>
</div>
<div class="align1">
<div class="form-group">
<label class="control-label col-sm-2" for="rate">Please rate the site:</label>
<div class="col-sm-offset-2 col-sm-10">
<div class="radio">
<label><input type="radio" name="optradio1">Excellent</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio2">Very Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio3" >Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio4">Fair</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio5">Poor</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="part">Best Part of Site :</label>
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox" value="home">Home</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="experience">Experience</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="video">Videos</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="hkust">HKUST Life</label>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="part">Best Aspect of Site :</label>
<select class="form-control" id="sel1">
<option>Select</option>
<option value="content">Content</option>
<option value="friendly">User-friendliness</option>
<option value="accessible">Accessibility</option>
<option value="interactive">Interactivity</option>
<option value="design">Design</option>
<option value="time">Load Time</option>
<option value="compatible">Browser Compatibility</option>
</select>
</div>
<div class="form-group">
<label for="comment">Comments for improvement: </label>
<textarea class="form-control" rows="5" id="comment"></textarea>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
</form>
</div>
</div>
</div>
Namaste vivek,
here are some of changes i made in your markup, no change in your CSS. Its just about your column structure.
Hope it helps you. You can do the same with checkboxes!
<div class="form-group">
<label class="control-label col-sm-2" for="rate">Please rate the site:</label>
<div class="col-sm-10">
<div class="radio col-md-2">
<label><input type="radio" name="optradio1">Excellent</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio2">Very Good</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio3" >Good</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio4">Fair</label>
</div>
<div class="radio col-md-2">
<label><input type="radio" name="optradio5">Poor</label>
</div>
</div>
</div>
I am not sure I understood you well, but I did this FIDDLE for you.
This is the css I added:
/* makes all checkboxes and radio buttons stick to each other */
.radio-container, .radio,
.checkbox-container, .checkbox {
display: inline-block;
float: left;
}
.checkbox:last-child, .radio:last-child{
clear: right;
display: block;
}
.control-label {
display: block;
float: none;
}
.label {
display: block;
clear: left;
float: left!important;
}
and in your html I added the classes defined above in this part:
<div class="form-group">
<label class="label control-label col-sm-2" for="rate">Please rate the site:</label>
<div class="radio-container col-sm-offset-2 col-sm-10">
<div class="radio">
<label><input type="radio" name="optradio1">Excellent</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio2">Very Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio3" >Good</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio4">Fair</label>
</div>
<div class="radio">
<label><input type="radio" name="optradio5">Poor</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="label control-label col-sm-2" for="part">Best Part of Site :</label>
<div class="checkbox-container col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label><input type="checkbox" value="home">Home</label>
</div>
<div class="checkbox">
<label><input type="checkbox" value="experience">Experience</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="video">Videos</label>
</div>
<div class="checkbox ">
<label><input type="checkbox" value="hkust">HKUST Life</label>
</div>
</div>
</div>
<div class="form-group">
<label class="label control-label col-sm-2" for="part">Best Aspect of Site :</label>
Related
I'm not strong in frontend development :) I'm using bootstrap for created a form. But it isn't look fine. How could I align my input form in one column?
<form>
<div class="form-group form-inline">
<label for="exampleInputPrice" class="personal-form-labels">Purchase Price</label>
<input type="text" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
<div class="form-group form-inline">
<label for="exampleInputLoan" class="personal-form-labels">Loan Amont</label>
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
<div class="col-md-12 text-center block-buttons">
<button type="submit" class="btn btn-primary btn-lg">Continue</button>
</div>
</form>
enter image description here
Use of display:table-*
table {
border-collapse: separate;
}
.form-inline {
display: table-row;
}
.form-inline label, .form-inline input {
display: table-cell;
margin: 0 0 5px 10px;
}
<form>
<div class="form-group form-inline">
<label for="exampleInputPrice" class="personal-form-labels">Purchase Price</label>
<input type="text" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
<div class="form-group form-inline">
<label for="exampleInputLoan" class="personal-form-labels">Loan Amont</label>
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
<div class="col-md-12 text-center block-buttons">
<button type="submit" class="btn btn-primary btn-lg">Continue</button>
</div>
</form>
Try like this , bootstrap Horizontal form not support in bootstrap -4
Not supported ,use bootstrap 3
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<form class="form-horizontal" action="/action_page.php">
<div class="form-group">
<label class="control-label col-sm-2" for="Purchase Price">Purchase Price</label>
<div class="col-sm-4">
<input type="email" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="Loan Amont">Loan Amont</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Continue</button>
</div>
</div>
</form>
bootsrap-3 doc https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_form_horizontal&stacked=h
If you are using bootstrap 4 Try This :
<form>
<div class="form-group row">
<label for="exampleInputPrice" class="col-sm-2 col-form-label">Purchase Price</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="exampleInputPrice" placeholder="$$$">
</div>
</div>
<div class="form-group row">
<label for="exampleInputLoan" class="col-sm-2 col-form-label">Loan Amont</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="exampleInputLoan" placeholder="$$$">
</div>
</div>
<div class="form-group form-inline">
<button type="submit" class="btn btn-primary btn-lg">Continue</button>
</div>
</form>
https://jsfiddle.net/sv2j08dd/3/
Modulation:
Glass thickness:
css:
.inputs span{ display: inline-block; width: 60%; padding: 0 0 15px 0; }
.inputs span input{ width: 30%; float: left; height:25px;padding: 0 5px;}
.inputs{width: 100%;float: left;padding: 0 25px; box-sizing: border-box;}
.inputs label{width: 20%;float: left;}
I'm creating a website with Bootstrap 4, and at least in Chrome on Windows 10, the checkboxes are shown a bit too high in a line:
These are <input type="checkbox"> elements enclosed in <label>s.
I would like to move the checkbox itself down by 3px or so. Is this possible with CSS?
Using a flexbox is an option.
.container {
display: flex;
align-items: center;
}
.row {
display: flex;
justify-content: space-between;
width: 100%;
}
<div class="main">
<div class="row">
<div class="container">
<label for="checkbox1">Checkbox 1</label>
<input type="checkbox" name="checkbox1">
</div>
<div class="container">
<label for="checkbox2">Checkbox 2</label>
<input type="checkbox" name="checkbox2">
</div>
<div class="container">
<label for="checkbox3">Checkbox 3</label>
<input type="checkbox" name="checkbox3">
</div>
<div class="container">
<label for="checkbox4">Checkbox 4</label>
<input type="checkbox" name="checkbox4">
</div>
</div>
<div class="row">
<div class="container">
<label for="checkbox5">Checkbox 5</label>
<input type="checkbox" name="checkbox5">
</div>
<div class="container">
<label for="checkbox6">Checkbox 6</label>
<input type="checkbox" name="checkbox6">
</div>
<div class="container">
<label for="checkbox7">Checkbox 7</label>
<input type="checkbox" name="checkbox7">
</div>
<div class="container">
<label for="checkbox8">Checkbox 8</label>
<input type="checkbox" name="checkbox8">
</div>
</div>
</div>
Try using vertical-align: middle;
input[type="checkbox"] {
vertical-align: middle;
}
<div class="test">
text <input type="checkbox" name="">
</div>
I am trying to put a checkbox, label and input box next to each other.
I separated it into divs and and put divs side-by-side.
I was able to get the buttons center but they are to close together which I am trying to fix too.
My question is how can I get <div class="col-centered border"> into a smaller border and put a checkbox, label and input box next to each other. In the end I want the buttons and all as a container.
html
<div class="col-centered border">
<form>
<div class="first">
<div class="form-group">
<input type="checkbox" class="form-check-input">
<label for="ssn">SSN:</label>
<input type="text" class="form-control-file" id="ssn" placeholder="Social Security Number">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="lastname">Lastname:</label>
<input type="text" class="form-control-file" id="lastname" placeholder="Password">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="role">Role:</label>
<input type="text" class="form-control-file" id="role" placeholder="Password">
</div>
</div>
<div class="second">
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="userId">User ID:</label>
<input type="text" class="form-control-file" id="userId" placeholder="User Id">
</div>
<div class="form-group row">
<input type="checkbox" class="form-check-input">
<label for="office">Office</label>
<input type="text" class="form-control-file" id="office" placeholder="Office">
</div>
<input type="checkbox">Include Subordinates
</div>
<div class="center-block lower-button">
<div class="center-block">
<button type="submit" class="btn btn-default btn-md left-button">Search</button>
<button type="submit" class="btn btn-default btn-md right-button">Reset</button>
</div>
</div>
</form>
</div>
css
.first {
width: 100px;
float: left;
padding-left: 450px;
}
.second {
width: 200px;
float: right;
padding-right: 950px;
}
.col-centered{
padding-top: 30px;
float: none;
margin: 0 auto;
}
.btn-beside {
position: center;
left: 100%;
top: 0;
margin-left: -10px;
}
.lower-button{
padding-top:250px;
padding-left:575px;
}
.left-button{
padding-right: -14px;
}
.form-group{
text-align: center;
}
I am using bootstrap
Here's a Fiddle for you to take inspiration from.
HTML
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="input-group">
<span class="input-group-addon">
<input type="checkbox">
</span>
<span class="input-group-addon">
<label for="tbox">My Label</label>
</span>
<input type="text" id="tbox" class="form-control">
</div>
</div>
</div>
</div>
As per the official documentation for Bootstrap.
I am using bootstrap btn-group class for radio buttons.They are not working on live server.My site is under development example.com .Although they work on a separate html page.
<div class="row">
<section class="col-lg-2 col-xs-3">
<label>Gender:</label></section>
<section class="col-lg-4 col-xs-8">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary control-label input-group">
<input type="radio" name="gender" id="option2" autocomplete="off" value="male">Male
</label>
<label class="btn btn-primary ">
<input type="radio" name="gender" id="option3" autocomplete="off" value="female" checked> Female
</label>
</div>
</section>
</div>
$(document).ready(function(){
$('.gender').on('click', function() {
$('.checked').removeClass('checked');
$(this).addClass('checked');
});
});
#import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');
.checked {
background-color: #286090;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<section class="col-lg-2 col-xs-3">
<label>Gender:</label>
</section>
<section class="col-lg-4 col-xs-8">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary control-label input-group gender">
<input type="radio" name="gender" id="option2" autocomplete="off" value="male">Male
</label>
<label class="btn btn-primary gender">
<input type="radio" name="gender" id="option3" autocomplete="off" value="female" checked> Female
</label>
</div>
</section>
</div>
.btn > input[type="radio"] {
display: none;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="row">
<section class="col-lg-2 col-xs-3">
<label>Gender:</label></section>
<section class="col-lg-4 col-xs-8">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-primary control-label input-group">
<input type="radio" name="gender" id="option2" autocomplete="off" value="male">Male
</label>
<label class="btn btn-primary ">
<input type="radio" name="gender" id="option3" autocomplete="off" value="female" checked> Female
</label>
</div>
</section>
</div>
Add
.btn > input[type="radio"] {
display: none;
}
in your css
I'm trying to show div when one of the selects in group is checked and hide when not. I thought this should work, but it's not working.
https://jsfiddle.net/47ctm349/2/
#form-group-osobko {
display: none;
}
#odber-1:checked+#form-group-osobko {
display: block;
}
<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="odber">Způsob platby</label>
<div class="col-md-4">
<div class="checkbox">
<label for="odber-0">
<input type="checkbox" name="odber" id="odber-0" value="1"> Dobírka
</label>
</div>
<div class="checkbox">
<label for="odber-1">
<input type="checkbox" name="odber" id="odber-1" value="2"> Hotově při osobním odběru
</label>
</div>
<div class="checkbox">
<label for="odber-2">
<input type="checkbox" name="odber" id="odber-2" value="3"> Platba předem na účet
</label>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group" id="form-group-osobko">
<label class="col-md-4 control-label" for="osobniodber">Místo osobního odběru</label>
<div class="col-md-4">
<input id="osobniodber" name="osobniodber" type="text" placeholder="14900,11000" class="form-control input-md">
<span class="help-block">Zadejte PSČ míst možného osobního odběru oddělená čárkou.</span>
</div>
</div>
It should work when you click the checkbox in the middle, the div id="form-group-osobko" should appear.
I was trying not to use JS with my bootstrap.
Can't get my head around what I'm doing wrong :(
Thanks.
Your solution only works, if the div to be displayed is an adjacent sibling of the checkbox input, as that is what the + selector in CSS means.
If this div is neither a sibling nor a child you can't select it with CSS and will have to use JavaScript.
#form-group-osobko {
display: none;
}
#odber-1:checked+#form-group-osobko {
display: block;
}
<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="odber">Způsob platby</label>
<div class="col-md-4">
<div class="checkbox">
<label for="odber-0">
<input type="checkbox" name="odber" id="odber-0" value="1">Dobírka
</label>
</div>
<div class="checkbox">
<label for="odber-1">
<input type="checkbox" name="odber" id="odber-1" value="2">Hotově při osobním odběru
<!-- Text input-->
<div class="form-group" id="form-group-osobko">
<label class="col-md-4 control-label" for="osobniodber">Místo osobního odběru</label>
<div class="col-md-4">
<input id="osobniodber" name="osobniodber" type="text" placeholder="14900,11000" class="form-control input-md">
<span class="help-block">Zadejte PSČ míst možného osobního odběru oddělená čárkou.</span>
</div>
</div>
</label>
</div>
<div class="checkbox">
<label for="odber-2">
<input type="checkbox" name="odber" id="odber-2" value="3">Platba předem na účet
</label>
</div>
</div>
</div>
Here would be a simple jQuery solution, using just an additional class to display the div:
$('#odber-1').change(function(){
$('#form-group-osobko').toggleClass("active");
});
#form-group-osobko {
display: none;
}
#form-group-osobko.active {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-4 control-label" for="odber">Způsob platby</label>
<div class="col-md-4">
<div class="checkbox">
<label for="odber-0">
<input type="checkbox" name="odber" id="odber-0" value="1">Dobírka
</label>
</div>
<div class="checkbox">
<label for="odber-1">
<input type="checkbox" name="odber" id="odber-1" value="2">Hotově při osobním odběru
</label>
</div>
<div class="checkbox">
<label for="odber-2">
<input type="checkbox" name="odber" id="odber-2" value="3">Platba předem na účet
</label>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group" id="form-group-osobko">
<label class="col-md-4 control-label" for="osobniodber">Místo osobního odběru</label>
<div class="col-md-4">
<input id="osobniodber" name="osobniodber" type="text" placeholder="14900,11000" class="form-control input-md">
<span class="help-block">Zadejte PSČ míst možného osobního odběru oddělená čárkou.</span>
</div>
</div>
Get it https://jsfiddle.net/47ctm349/5/
I just added Javascript, using Jquery. It works for any div anywhere:
$('#odber-0').on('change', function(){
if($('#odber-0').is(':checked'))
$("#form-group-osobko").css("display","block");
else
$("#form-group-osobko").css("display","none");
});
$('#odber-1').on('change', function(){
if($('#odber-1').is(':checked'))
$("#form-group-osobko").css("display","block");
else
$("#form-group-osobko").css("display","none");
});
$('#odber-2').on('change', function(){
if($('#odber-2').is(':checked'))
$("#form-group-osobko").css("display","block");
else
$("#form-group-osobko").css("display","none");
});
In your case no ideas with CSS.
Good luck!