Cannot add margin between form elements - html

I tried to create a form and add some margin between form element in the class formGroup as margin 10px 0;
But it is not working and I am not sure why is that happening. I appreciate your help.
Here is the HTML
<div class="registrationForm">
<h2>Please fill in the form below to register</h2>
<form class="form">
<div class="formGroup">
<label class="formLabel">First Name</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Last Name</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Email Address</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Password</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Phone</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Gender</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Date of birth</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel"></label>
<div class="formField">
<input type="submit">
</div>
</div>
</form>
</div>
and the CSS here
.registrationForm
{
background-color: #FFF;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
padding: 3% 5%;
margin-bottom: 3%;
overflow: auto;
}
.registrationForm .form
{
margin: 10px auto;
width: 90%;
//border: 1px solid black;
overflow: auto;
}
.registrationForm .form .formGroup
{
width: 100%;
margin: 10px 0;
}
.registrationForm .form .formGroup .formLabel
{
width: 20%;
float: left;
//text-align: right;
}
.registrationForm .form .formGroup .formField
{
width: 80%;
float: left;
}
Thank you

You're just putting the margin-bottom in the wrong place. it should be in formField.
.registrationForm
{
background-color: #FFF;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
padding: 3% 5%;
overflow: auto;
}
.registrationForm .form
{
margin: 10px auto;
width: 90%;
//border: 1px solid black;
overflow: auto;
}
.registrationForm .form .formGroup
{
width: 100%;
}
.registrationForm .form .formGroup .formLabel
{
width: 20%;
float: left;
//text-align: right;
}
.registrationForm .form .formGroup .formField
{
width: 80%;
float: left;
margin-bottom: 3%;
}
<div class="registrationForm">
<h2>Please fill in the form below to register</h2>
<form class="form">
<div class="formGroup">
<label class="formLabel">First Name</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Last Name</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Email Address</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Password</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Phone</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Gender</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel">Date of birth</label>
<div class="formField">
<input type="text">
</div>
</div>
<div class="formGroup">
<label class="formLabel"></label>
<div class="formField">
<input type="submit">
</div>
</div>
</form>
</div>

You need to clear the floats contained within your .formGroup elements, currently .formGroup has no height so any margin applied is swallowed by the height of the children within it.
Put this on your .formGroup selector
overflow: hidden;
margin: 10px 0;
See this example: https://jsfiddle.net/yuqvu6w4/1/

you only need to add "overflow:hidden" to your class
".registrationForm .form .formGroup"
your final code will be :
.registrationForm .form .formGroup {
width: 100%;
margin: 10px 0;
**overflow: hidden;**
}
it will work without interrupting other code

Related

Is there's any way to get this file upload section to the right side like other text boxes

i want to get this file upload button to the right side like other text boxes.
tried editing the CSS file seems not working.
I'll put the CSS code and HTML code below.
if I can add something like add your image like drag and drop option that'll be very cool :)
little left algin the file upload area
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="PostYourAD.css" type="text/css">
</head>
<body>
<div class="navmenu">
<ul>
<li>Home</li>
<li>Post Your AD</li>
<li>Contact</li>
<li>About</li>
</ul>
</div>
<div class="logo">
<img src="images/logo.jpg" alt="logo" align = "left" width="150" height="150" />
</div>
<br><br><br><br><br><br><br><br>
<h1 align = "center">Post Your AD</h1>
<br><br>
<div class="container">
<form action="/action_page.php">
<div class="row">
<div class="col-25">
<label for="images">Upload Your Images</label>
<div class="col-75">
<input type="file" id="myFile" name="filename">
</div>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="name">Name</label>
</div>
<div class="col-75">
<input type="text" id="name" name="name" placeholder="Your name..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="location">Location</label>
</div>
<div class="col-75">
<input type="text" id="location" name="location" placeholder="Your Location..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="price">Price</label>
</div>
<div class="col-75">
<input type="text" id="price" name="price" placeholder="Enter the Price..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="pnumber">Phone Number</label>
</div>
<div class="col-75">
<input type="text" id="pnumber" name="pnumber" placeholder="Your Phone Number..">
</div>
</div>
<div class="row">
<div class="col-25">
<label for="Type">Type</label>
</div>
<div class="col-75">
<select id="type" name="type">
<option value="type">Select a Type</option>
<option value="land">Land</option>
<option value="vehicale">Vehicale</option>
<option value="house">House</option>
<option value="annex">Annex</option>
</select>
</div>
</div>
<div class="row">
<div class="col-25">
<label for="description">Description</label>
</div>
<div class="col-75">
<textarea id="description" name="description" placeholder="Write Your Description.." style="height:200px"></textarea>
</div>
</div>
<br>
<div class="row">
<input type="submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
CSS code
* {
box-sizing: border-box;
}
input[type=text], select, textarea {
text-align: justify;
vertical-align:super;
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
input[type=file] {
text-align: justify;
vertical-align:super;
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
resize: vertical;
}
label {
padding: 12px 12px 12px 0;
display: inline-block;
}
input[type=submit] {
background-color: #04AA6D;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
float: middle;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
.col-25 {
float: left;
width: 25%;
margin-top: 6px;
}
.col-75 {
float: left;
width: 75%;
margin-top: 6px;
}
.row:after {
content: "";
display: table;
clear: both;
}
#media screen and (max-width: 600px) {
.col-25, .col-75, input[type=submit] {
width: 100%;
margin-top: 0;
}
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
float: right;
}
a {
display: block;
padding: 8px;
background-color: #dddddd;
}
It seems like one of the closings tags in your file input code is misplaced:
You have this:
<div class="row">
<div class="col-25">
<label for="images">Upload Your Images</label>
<div class="col-75">
<input type="file" id="myFile" name="filename">
</div>
</div>
</div>
You should have this:
<div class="row">
<div class="col-25">
<label for="images">Upload Your Images</label>
</div>
<div class="col-75">
<input type="file" id="myFile" name="filename">
</div>
</div>
Reading you HTML code, you're closing the "html" tag, but the opening one, which should be below the doctype, is missing.
If I may, I don't know if it's the copy / paste who misaligned your tags, but I advise you to always align your tags correctly, or use a formatter. It will help you to edit your code and to spot small errors like this one more easily ;)
You placed the </div> for an element of the class col-75 wrongly. Here's the corrected version: https://jsfiddle.net/fw26y5pe/.

Make form responsive

I am making a form inside of jumbotron and for some reason I get it to look good on desktop view but when viewing it mobile it goes out of the jumbotron. I am using netbeans to do my coding. I even use #media (max-width: 620px). I tried using google but failed :(
#wrapper{
width: 500px;
height: 700px;
position: relative;
margin: 0 auto;
background-color: rgba(255,255,255,.75);
text-align: center;
}
form{
color: black;
text-align: center;
}
div{
clear: both;
}
#off{
background-color: rgba(225,0,0,.85);
color: white;
width: 525px;
height: 140px;
font-size: 1rem;
text-align: center;
}
.formHeader{
color: #104c8b;
}
.formFooter{
background-color: rgba(0,0,255,.5);
color: white;
margin: 65px 0 0 0;
}
#media(max-width: 620px) {
#wrapper{
width: 100px;
height: 100px;
position: relative;
margin: 0 auto;
background-color: rgba(255,255,255,.75);
text-align: center;
}
<section id="top" class="jumbotron">
<div class="container-fluid">
<div class="row text-center">
<div id="wrapper"><p>Contact Form</p>
<div class="formHeader">
</div>
<form action="test.html" method="get" name="test" id="myForm">
<label>Name</label><input name="name" type="text" /><br>
<label>Email</label><input name="email" type="text" /><br>
<label>Phone</label><input name="number" type="text" /><br>
<input type="submit" value="Send"/>
</form>
<div class="formFooter">
</div>
</div>
</div>
</div>
</section>
Given that you're using Bootstrap as a framework it seems a shame not to make use of all of well... the framework. With some restructuring of your HTML (to make use of Bootstrap's responsive classes and form controls) you can easily achieve the responsiveness you desire.
Most of it is just adding the necessary .col-*-* for grid layouts, and of course applying Bootstrap classes to your input and label elements, etc. An example Bootply is below though the code is significantly altered to better-reflect Bootstrap's Framework and modern input classifications (like tel or email, etc).
http://www.bootply.com/mPNCZyXbbD
The HTML:
<section id="top" class="jumbotron">
<div class="container-fluid">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="form-wrapper text-center">
<p>Contact Form</p>
<form action="test.html" method="get" name="test" id="myForm" class="form form-horizontal">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input name="name" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input name="email" type="email" class="form-control">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Phone</label>
<div class="col-sm-10">
<input name="number" type="tel" class="form-control">
</div>
</div>
<button type="submit" class="btn btn-default">Send</button>
</form>
</div>
</div>
</div>
</div>
</section>
And the CSS:
.form-wrapper {
padding: 15px;
background: rgba(255,255,255,0.75);
}

Making forms that have double columns

So i have this form that i quickly made and i got it so that i can make double columns now.
link: http://codepen.io/zomdar/pen/WbXBaq
<head>
</head>
<body>
<fieldset>
<form>
<div class="half">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div>
<div class="half">
<label for="email">Email</label>
<input type="text" id="email" name="email">
</div>
<div class="half">
<label for="zip">Zip / Postal code</label>
<input type="text" id="zip" name="zip">
</div>
<div class="half">
<label for="country">Country</label>
<select id="country" name="country"><option></option></select>
</div>
<div class="full">
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
</div>
<div class="half">
<input type="checkbox" id="copy" name="copy">
<label for="copy">Send me a copy</label>
</div>
<div class="half right">
<input type="submit" value="send">
</div>
</form>
</fieldset>
</body>
</html>
CSS:
fieldset { width: 900px; }
input[type=text], select, textarea { width: 98%; }
.half { float: left; width: 48%; padding: 1%; }
.full { clear: both; width: 98%; padding: 1%; }
.right { text-align: right; }
but the problem is that when i put the div tag half and put it in the html....i have to put 2 "half" fields for it to go to the next line. I cant just put 1 half class and another half class right below the half class. Any ideas on how i can do that? add another class maybe?
add a class .clear { clear: both; } like this:
fieldset { width: 500px; padding: 1%; }
input[type=text], select, textarea { width: 98%; }
.half { float: left; width: 48%; padding: 1%; }
.clear { clear: both; }
.full { clear: both; width: 98%; padding: 1%; }
.right { text-align: right; }
<head>
</head>
<body>
<fieldset>
<legend>Contact form</legend>
<form>
<div class="half">
<label for="name">Name</label>
<input type="text" id="name" name="name">
</div>
<div class="clear"></div><!-- added div class clear -->
<div class="half">
<label for="email">Email</label>
<input type="text" id="email" name="email">
</div>
<div class="half">
<label for="zip">Zip / Postal code</label>
<input type="text" id="zip" name="zip">
</div>
<div class="half">
<label for="country">Country</label>
<select id="country" name="country"><option></option></select>
</div>
<div class="full">
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
</div>
<div class="half">
<input type="checkbox" id="copy" name="copy">
<label for="copy">Send me a copy</label>
</div>
<div class="half right">
<input type="submit" value="send">
</div>
</form>
</fieldset>
</body>
</html>

Bootstrap placing forms next to eachother

Trying to put three of my first forms in the center of the container and put the last two forms next to the first three. Trying to use float, but that didn't work.
Any help is much appricieted:
bootply: http://www.bootply.com/125841
How I want it to look:
Ok.
you put everything inside a div with class="everything".
.everything {
overflow: auto;
width: 600px;
margin-left:auto;
margin-right:auto;
}
then you put the first three group of textfields in a class called .blocks and the other three groups of textfields and button in another div called .blocks too.
.blocks {
width: 50%;
float:left;
}
here you are fella:
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-lg-12">
<form class="form-horizontal" role="form">
<div class="block">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-2">
<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-2">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password1</label>
<div class="col-sm-2">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
</div>
<div class="block">
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password2</label>
<div class="col-sm-2">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label">Password3</label>
<div class="col-sm-2">
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button id="onlyButton" type="submit" class="btn btn-default">Sign in</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
css:
.jumbotron {
/* display: inline-block; */
margin-bottom: auto;
margin: 0 auto;
min-height: 623px;
}
.block {
width: 50%;
float: left;
}
.container {
min-height: 530px;
/* set border styling */
border-color: black;
border-style: solid;
border-width: 1px;
width: 600px;
margin-right:auto;
margin-left:auto;
overflow:auto;
/* set border roundness */
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
margin: 0 auto;
width: 800px;
/* display: inline-block; */
background-color: white;
}
.form-horizontal {
padding-right: 150px;
}
.form-control {
width: 100px;
margin-left: 30px;
}
#onlyButton {
float:right;
}

Bootstrap: Centering 2 forms next to eachother in Carousel Template?

I am trying to center two forms sitting next to each other in twitter's bootstrap.
This is the template I am using given by Bootstrap
and this is the code I have so far. What it does is placing them on the top of each other.
<!-- Carousel
================================================== -->
<div id="myCarousel" class="carousel">
<div class="carousel-inner">
<div class="item active">
<img class="header" src="img/header_bg.jpg" alt="">
<div class="container">
<div class="row-fluid">
<div class="span12">
<div class="logo"><img src="img/logo.png" height="105px" width="96px"></div>
</div>
</div>
</div> <!-- container logo -->
<div class="container">
<div class="carousel-caption">
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
<form class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
</div>
</div>
</div> <!-- item active -->
</div> <!-- carousel-inner -->
</div><!-- /.carousel -->
Here is the CSS:
/* Carousel base class */
.carousel {
margin-bottom: 60px;
}
.carousel .container {
position: relative;
z-index: 9;
}
.carousel-control {
height: 80px;
margin-top: 0;
font-size: 120px;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
background-color: transparent;
border: 0;
z-index: 10;
}
.carousel .item {
height: 700px;
}
.carousel img.header {
position: absolute;
top: 0;
left: 0;
min-width: 100%;
height: 700px;
}
.carousel-caption {
background-color: transparent;
position: static;
max-width: 400px;
margin-top: 100px;
}
.carousel-caption h1,
.carousel-caption .lead {
margin: 0;
line-height: 1.25;
color: #fff;
text-shadow: 0 1px 1px rgba(0,0,0,.4);
}
.carousel-caption .btn {
margin-top: 10px;
}
.logo {
margin-left:-150px;
float:left;
}
Can someone please help me out with this ? : ) Thanks !
To get the forms side-by-side, we have to give them a 'float: left' CSS rule, like so:
.form-horizontal{
float: left;
}
Anyway, here's a JSFiddle with the new CSS: http://jsfiddle.net/4WwLX/1/