How to make a button float next to the input form? - html

I have the following form, and my button is an image button. I want in to be on the same line with the email input but I cannot figure out how to accomplish it. I made my button float towards the right but it is not aligned on the same line with the input field.
Form:
.control-group{
float:left;
}
.control-group.button{
clear:both;
}
<form class="well email-form" id="emailForm" name="sendEmail" novalidate="" method="post">
<div class="col-sm-6">
<div class="control-group">
<div class="field-control">
<input class="form-control" name="email" id="email-address" type="email" placeholder="ENTER EMAIL ADDRESS" required="" data-validation-required-message=" "/>
</div>
</div>
<div class="control-group button">
<div class="field-control">
<input type="image" src="http://placehold.it/25x25" name="submitEmail" class="button"/>
</div>
</div>
</div>
</form>
CSS:
.control-group{
float:left;
}
.control-group.button{
clear:both;
}

You can use display: inline-block and vertical-align: bottom like:
.control-group {
display: inline-block;
}
input[type="image"].button {
vertical-align: bottom;
}
<form class="well email-form" id="emailForm" name="sendEmail" novalidate="" method="post">
<div class="col-sm-6">
<div class="control-group">
<div class="field-control">
<input class="form-control" name="email" id="email-address" type="email" placeholder="ENTER EMAIL ADDRESS" required="" data-validation-required-message=" " />
</div>
</div>
<div class="control-group button">
<div class="field-control">
<input type="image" src="http://placehold.it/25x25" name="submitEmail" class="button" />
</div>
</div>
</div>
</form>

There are classes built into bootstrap to do this. You can add the form-inline class to your form and replace your control-group class with form-group. This way you don't have to create any custom css to do the alignment. You also don't need the field-control class/div unless that's part of your custom css.
<form class="well email-form form-inline" id="emailForm" name="sendEmail" novalidate="" method="post">
<div class="col-sm-6">
<div class="form-group">
<div class="field-control">
<input class="form-control" name="email" id="email-address" type="email" placeholder="ENTER EMAIL ADDRESS" required="" data-validation-required-message=" " />
</div>
</div>
<div class="form-group">
<div class="field-control">
<input type="image" src="images/tree.png" name="submitEmail" class="button" />
</div>
</div>
</div>
</form>

you dont have to wrap under <span> tag
Fiddle
http://jsfiddle.net/m4rz38h7/2/
.control-group{
display:inline-block;
margin:0;
padding:0;
vertical-align:top;
}
.button{
width:20px;
height:20px;
}

Related

Placing DIV on the right side of form

I have a div in a form and i want to place the div on the right side of the form and the div must be fixed on the right side with the button. I don't know if this can be done but how can i get this done.
HTML
<form class="form-horizontal" method="post">
<div class="form-group">
<label for="name" class="col-lg-1 control-label"> Name</label>
<div class="col-lg-6">
<input type="text" class="typeahead form-control" id="name" placeholder="Name" name="name" required>
</div>
</div>
<!--i want to move this div to the right side of the form and fixed-->
<div style="background-color:white" class="move-right" id="move-right">
<legend style="text-align: center" >Heading <span></span></legend>
</div>
<div>
<button type="submit" class="btn ">Save</button>
</div>
</form>
</div>
If the content of the right should not overlap the other content you need:
.move-right { float:right; } in the css.
And reorder the html code to place the floating element above the others:
<form class="form-horizontal" method="post">
<div style="background-color:white" class="move-right" id="move-
right">
<legend style="text-align: center" >Heading <span></span></le zgend>
</div>
<div class="form-group">
<label for="name" class="col-lg-1 control-label"> Name</label>
<div class="col-lg-6">
<input type="text" class="typeahead form-control" id="name"
placeholder="Name" name="name" required>
</div>
</div>
<div>
<button type="submit" class="btn ">Save</button>
</div>
</form>
otherwise, if the contents can overlap:
use the .move-right { position: absolute; right: 0px; } and .form-horizontal { position: relative; } css code.

HTML Text input field different width to others in the same class

Sorry if the title isn't clear, I couldn't think of a shorter way of stating it without taking away to much.
Now, I have made a simple contact form (currently doesn't submit etc) with 4 labels and 4 text inputs. Each pair is contained inside it's own div and then styled by class.
Everything lines up and is where I want it, except the 4th div is off. The text field is one pixel wider than the rest, which also bumps the label out of alignment.
Here's what I've got...
HTML:
<div id="contact-form">
<div id="form-title">
<h3>Contact Form</h3>
<h5>Enter your details below to contact me</h5>
</div>
<form id="contact">
<div class="input">
<label>First name:
<input class="txt-box" type="text" />
</label>
</div>
<div class="input">
As above, "Surname"
</div>
<div class="input">
As above, "Phone"
</div>
<div class="input">
As above, "Email"
</div>
</form>
</div>
CSS:
.input {
width:100%;
display:inline-block;
}
.input label {
display:inline-block;
vertical-align:left;
text-align:right;
padding:0;
}
.input input {
width:60%;
margin:0 5px 0 3px;
display:inline-block;
vertical-align:right;
}
Here's how it displays
Title...
First name: [text]
Surname: [text]
Phone: [text]
Email: [text ]
I've been through all the other code and nothing should be interacting with this section at all.
Any ideas would be greatly appreciated, also please note that I've searched and tried and tested so the way that it's styled may not be the best or most efficient.
EDIT:
Here's the full code of the section.
HTML:
<div id="contact-form">
<div id="form-title">
<h3>Contact Form</h3>
<h5>Enter your details below to contact me.</h5>
</div>
<form id="contact">
<div class="input">
<label>First name
<input class="txt-box" type="text" placeholder="John" />
</label>
</div>
<div class="input">
<label>Surname:
<input class="txt-box" type="text" placeholder="Smith />
</label>
</div>
<div class="input">
<label>Phone
<input class="txt-box" type="text" placeholder="0412345678" />
</label>
</div>
<div class="input">
<label>Email
<input class="txt-box" type="text" placeholder="j.smith#example.com" />
</label>
</div>
</form>
</div>
try this css
.input {
width:100%;
display:inline-block;
}
.input label {
display:inline-block;
vertical-align:left;
text-align:right;
padding:0;
width:45%;
}
.input input {
width:55%;
margin:0 5px 0 3px;
display:inline-block;
vertical-align:left;
}
<div id="contact-form">
<div id="form-title">
<h3>Contact Form</h3>
<h5>Enter your details below to contact me.</h5>
</div>
<form id="contact">
<div class="input">
<label>First name:
<input class="txt-box" type="text" placeholder="John" />
</label>
</div>
<div class="input">
<label>Surname:
<input class="txt-box" type="text" placeholder="Smith" />
</label>
</div>
<div class="input">
<label>Phone:
<input class="txt-box" type="text" placeholder="0412345678" />
</label>
</div>
<div class="input">
<label>Email:
<input class="txt-box" type="text" placeholder="j.smith#example.com" />
</label>
</div>
</form>
</div>
jsfiddle output
Through trial and error I have found a way to make it work properly.
Here's the updated html:
<div id="contact-form">
<div id="form-title">
<h3>Contact Form</h3>
<h5>Enter your details below to contact me.</h5>
</div>
<form id="contact">
<div class="input">
<label>First name:</label>
<input class="txt-box" type="text" placeholder="John" />
</div>
<div class="input">
<label>Surname:</label>
<input class="txt-box" type="text" placeholder="Smith" />
</div>
<div class="input">
<label>Phone:</label>
<input class="txt-box" type="text" placeholder="0412345678" />
</div>
<div class="input">
<label>Email:</label>
<input class="txt-box" type="text" placeholder="j.smith#example.com" />
</div>
</form>
</div>
And the update css:
.input {
width:100%;
}
.input label {
width:35%;
display:inline-block;
vertical-align:left;
text-align:right;
padding:0;
padding-top:5px;
}
.txt-box {
width:50%;
margin:0;
margin-left:3px;
display:inline-block;
vertical-align:right;
}

Bootstrap, Two columns won't go side by side (Form + Message)

I'm trying to make a contact section with two columns, an lg-8 and lg-3 (EDIT) + 1 buffer column:
First Column: Contact Form
Second Column: A simple text message from me.
I've looked around several places and cannot understand what is wrong with my code. I've done everything [bootstrap][1] resource says to and I'm getting one column underneath the other.
This is in a 'div class="container"'
<div class="formattedContact" id="contact">
<h3>Contact Me</h3>
<div class="wrapper">
<div class="content-main">
<form id="contactForm">
<form class="form-item">
<label for="inputName" ></label>
<input type="text" name="name" placeholder="Name" width="100%"></input>
</form>
<form class="form-item">
<label for="inputEmail" ></label>
<input type="text" name="email" placeholder="Email" width="100%"></input>
</form>
<form class="form-item">
<label for="inputPhone" ></label>
<input type="text" name="phone" placeholder="Phone" width="100%"></input>
</form>
<form class="form-item">
<label for="inputMsg" >Message</label><br>
<textarea rows='5' placeholder='Message' > </textarea>
</form>
<button type="submit">Send</button>
</form>
</div>
<div class="content-secondary">
<p>Hullo, Shoot me a text</p>
</div>
</div>
</div>
and the CSS
.wrapper {
.make-row();
}
.content-main {
.make-lg-column(8);
}
.content-secondary {
.make-lg-column(3);
.make-lg-column-offset(1);
}
I made several changes, both to get it to work as you describe and to get the labels linked to the inputs. It is a little redundant to have the placeholders match the labels, but you can do what you want to with that. You can change the 'xs' back to 'lg' in the grid class names, so they will be more appropriate outside of a small snippet. You may find that you want something in between, such as 'sm', (ex 'col-sm-8') since the classes take effect for the size specified between the dashes and larger.
Also, you know that the width numbers at the end of these bootstrap grid system class names are typically supposed to add up to 12, not 11 for a given screen width specifier, right?
#contactForm label {
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="formattedContact" id="contact">
<h3>Contact Me</h3>
<div class="wrapper">
<div class="content-main">
<form id="contactForm" class="col-xs-8">
<label for="inputName" >Name</label>
<input type="text" name="inputName" placeholder="Name" width="100%">
<label for="inputEmail" >Email</label>
<input type="text" name="inputEmail" placeholder="Email" width="100%">
<label for="inputPhone" >Phone</label>
<input type="text" name="inputPhone" placeholder="Phone" width="100%">
<label for="inputMsg" >Message</label>
<textarea rows='5' placeholder='Message' name="inputMsg" > </textarea>
<button type="submit">Send</button>
</form>
</div>
<div class="content-secondary col-xs-3">
<p>Hullo, Shoot me a text</p>
</div>
</div>
</div>
</div>
Add the following (Although I would recommend adding an id to these divs and styling )
.content-secondary,.content-main{
display:inline-block;
vertical-align:bottom
}
Snippet below
.wrapper {
.make-row();
}
.content-main {
.make-lg-column(8);
}
.content-secondary {
.make-lg-column(3);
.make-lg-column-offset(1);
}
.content-secondary,
.content-main {
display: inline-block;
vertical-align: bottom
}
<div class="formattedContact" id="contact">
<h3>Contact Me</h3>
<div class="wrapper">
<div class="content-main">
<form id="contactForm">
<form class="form-item">
<label for="inputName"></label>
<input type="text" name="name" placeholder="Name" width="100%"></input>
</form>
<form class="form-item">
<label for="inputEmail"></label>
<input type="text" name="email" placeholder="Email" width="100%"></input>
</form>
<form class="form-item">
<label for="inputPhone"></label>
<input type="text" name="phone" placeholder="Phone" width="100%"></input>
</form>
<form class="form-item">
<label for="inputMsg">Message</label>
<br>
<textarea rows='5' placeholder='Message'></textarea>
</form>
<button type="submit">Send</button>
</form>
</div>
<div class="content-secondary">
<p>Hullo, Shoot me a text</p>
</div>
</div>
</div>
Use the built in row and column classes:
<div class="container">
<div class="row">
<div class="col-sm-8">
<div class="formattedContact" id="contact">
<h3>Contact Me</h3>
<div class="wrapper">
<div class="content-main">
<form id="contactForm">
<form class="form-item">
<label for="inputName" ></label>
<input type="text" name="name" placeholder="Name" width="100%"></input>
</form>
<form class="form-item">
<label for="inputEmail" ></label>
<input type="text" name="email" placeholder="Email" width="100%"></input>
</form>
<form class="form-item">
<label for="inputPhone" ></label>
<input type="text" name="phone" placeholder="Phone" width="100%"></input>
</form>
<form class="form-item">
<label for="inputMsg" >Message</label><br>
<textarea rows='5' placeholder='Message' > </textarea>
</form>
<button type="submit">Send</button>
</form>
</div>
</div>
<div class="col-sm-3">
<div class="content-secondary">
<p>Hullo, Shoot me a text</p>
</div>
</div>
</div>
</div>
Add float:left to your content-main
.content-main {
.make-lg-column(8);
float:left;
}
https://jsfiddle.net/9Lf16p1c/

center <a> tags below a form

how can i center the a tags below the form
login.asp
<%
$Response->write(qq[
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-4">
<div class="image_logo">
<img class="img_logo" src="images/wearefamily-logo.png" alt="wearefamily-logo"/>
</div>
<h2 class="title_header">].gettext("title_header").qq[</h2>
<div id="error_message_div">]. ( $Session->{login_error} ? gettext("wrong_credentials") : "" ).qq[</div>
<form class="loginForm" name="loginForm" action="index.asp" method="post" autocomplete="off">
<input id="send" type="hidden" name="send" value="0" />
<input id="uri" type="hidden" name="uri" value="">
<input type="text" name="username" class="input" id="username" placeholder=].gettext("email").qq[ value="" /><br>
<input type="password" name="password" class="input" id="password" placeholder=].gettext("password").qq[ value="" /><br>
<input type="button" value=].gettext("signin").qq[ class="btn submit_btn"/><br>
</form>
<a class="form_link" href="index.asp?action=reset">].gettext("resetpassword").qq[</a><br>
<a class="form_link" href="index.asp?action=register">].gettext("register").qq[</a>
</div>
<div class="col-md-4"></div>
</div>
]);
%>
i would like to center the a tags below the form...the "reset your password" and "register to wearefamily kids" should be below sign button centered in the middle
Use this code given below
<div class="btn-block">
<a class="form_link" href="index.asp?action=reset">].gettext("resetpassword").qq[</a>
<a class="form_link" href="index.asp?action=register">].gettext("register").qq[</a>
</div>
.btn-block {
text-align:center;
}
.btn-block a {
display:inline-block;
}
I assume you didn't override the behavior of a elements because you haven't posted your css.
a element is rendered as an inline element. This is default.
It means the a elements behaves like text so you can give text-align:center; to the parent of element for centering the a element.
.col-md-4
{
text-align: center;
}

How to render no-table HTML form into two columns with CSS using classes?

I am trying to format a two-column form so that:
the labels are above each input field or text area
everything in class col1 is in the column on the left
everything in class col2 is in the column on the right
everything in class col12 spans both columns
Here is the HTML code I need this to work with:
<div id="contactForm">
<form method="post" action="">
<h3>Contact us</h3>
<p>To send us a work order, fill in the form below.<br /><strong>All the (*) fields are mandatory.</strong></p>
<fieldset>
<div class="col1">
<label for="form_firstname">Firstname <span class="required">*</span></label>
<input type="text" id="form_firstname" name="form_firstname" value="" />
</div>
<div class="col2">
<label for="form_lastname">Lastname <span class="required">*</span></label>
<input type="text" id="form_lastname" name="form_lastname" value="" />
</div>
<div class="col1">
<label for="form_address">Address</label>
<input type="text" id="form_address" name="form_address" value="" />
</div>
<div class="col2">
<label for="form_city">City</label>
<input type="text" id="form_city" name="form_city" value="" />
</div>
<div class="col1">
<label for="form_email">Email <span class="required">*</span></label>
<input type="text" id="form_email" name="form_email" value="" />
</div>
<div class="col2">
<label for="form_phone">Phone <span class="required">*</span></label>
<input type="text" id="form_phone" name="form_phone" value="" />
</div>
<div class="col12">
<label for="form_attachment">Add Attachment <span class="form_attachment">*</span></label>
<textarea id="form_attachment" name="form_attachment" rows="5"></textarea>
</div>
<div class="col12">
<label for="form_message">Message <span class="required">*</span></label>
<textarea id="form_message" name="form_message" rows="5"></textarea>
</div>
<div class="col12">
<label for="form_message">Message <span class="required">*</span></label>
<input type="submit" value="Send" formnovalidate="formnovalidate" />
</div>
</fieldset>
</form>
</div>
How do I code the CSS to style this HTML as required?
Here is the code on JSFiddle.
Try this CSS:
#contactForm{
width: 80%;
}
label,.col1,.col2,.col12{display: block;}
.col1{ float:right;}
.col2{float:left;}
.col12{clear:both;}
textarea{
display: block;
width: 100%;
}
http://jsfiddle.net/rx2gjpdw/3/