Alignment of HTML contents - html

I have coded buttons and input boxes but I want them to be aligned and placed in the center of the browser, but my output looks messy. I tried using center but the input boxes are not aligned. How do I align them? Thanks in advance.
Here is my complete code:
<center>
Name:
<input type="text" id="NameInput">
<br>
Number:
<input type="text" id="NumberInput">
<br>
<input type="button" value="ADD" onClick="press(input.value)">
<input type="button" value="EDIT" onClick="press(input.value)">
<input type="button" value="DELETE" onClick="press(input.value)">
<br><br>
Name:
<input type="text" id="NameSearch">
<br>
Number:
<input type="text" id="NumberSearch">
<br>
<input type="button" value="SEARCH" onClick="press(input.value)">
</center>

Try below using margin on a div and specifying a width:
<!--ADDED THE BORDER JUST SO YOU CAN SEE WHAT THIS STYLE IS DOING-->
<div style="margin: auto; border: 1px solid red; width: 500px;">
<div>
Name: <input type="text" id="NameInput">
</div>
<div>
Number: <input type="text" id="NumberInput">
</div>
<div>
<input type="button" value="ADD" onClick="press(input.value)">
<input type="button" value="EDIT" onClick="press(input.value)">
<input type="button" value="DELETE" onClick="press(input.value)">
</div>
<div>
Name: <input type="text" id="NameSearch">
</div>
<div>
Number: <input type="text" id="NumberSearch">
</div>
<div>
<input type="button" value="SEARCH" onClick="press(input.value)">
</div>
Also take a look at this url: CSS replacement for <div align="center">
If you want to make all the input boxes align you can try something like below:
<Style>
.label
{
display: inline-block;
width: 90px;
}
</style>
<div style="margin: auto; border: 1px solid red; width: 500px;">
<div>
<span class="label">Name:</span>
<input type="text" id="NameInput">
</div>
<div>
<span class="label">Number:</span>
<input type="text" id="NumberInput">
</div>
<div>
<input type="button" value="ADD" onClick="press(input.value)">
<input type="button" value="EDIT" onClick="press(input.value)">
<input type="button" value="DELETE" onClick="press(input.value)">
</div>
<div>
<span class="label">Name:</span>
<input type="text" id="NameSearch">
</div>
<div>
<span class="label">Number: </span>
<input type="text" id="NumberSearch">
</div>
<div>
<input type="button" value="SEARCH" onClick="press(input.value)">
</div>
<div>

Depending on the requirements, you could try playing around with the placeholder attribute:
<input type="text" id="NameInput" placeholder="Name">

The <center> is working properly because it considers the field and the text to be all one line, and it finds the centre of that line. Because the label for each field is a different length, each line has a different centre point.
How to align input forms in HTML has a few different approaches. You should use styling to make the label for each field the same length.

Related

BootStrap 3.3 collapse block radio button

I have a issue with bootstrap.
When the div is extend the radio button will block and won't work.
Here's the code :
<form name="today_task" action="" method="post">
<div data-toggle="collapse" id="add_task" class="collapse">
<textarea name="task_content" style="width: 100%;" placeholder="Enter task"></textarea>
<input type="radio" name="priority" value="3"> High Priority <br />
<input type="radio" name="priority" value="2" checked> Medium Priority <br />
<input type="radio" name="priority" value="1"> Low Priority <br />
</div>
<a class="accordion-toggle" data-toggle="collapse" data-target="#add_task" href="#add_task"><input type="button" name="submit_new_task" id="add_task_button" value="Add Task" class="btn btn-success" style="width: 100%;" onClick="submit_button()"></a>
</form>
Here's the problem : https://jsfiddle.net/g14ajcgh/
remove the "data-toggle=collapse" from
<div data-toggle="collapse" id="add_task" class="collapse">
it works for me
how about making another div for your radio button?

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/

Button in full-width, Bootstrap3

this is my HTML
<div id="formSuscription">
<form class="form-inline">
<div class="form-group">
<input type="text" class="form-control" placeholder="First Name">
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Last Name">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email">
</div>
<div class="form-group ">
<input type="button" class="form-control" value="Submit">
</div>
<div class="clearfix"></div>
<center>
<div class="form-group">
<label>
<input type="checkbox" class="form-control" value="Submit"> DON'T SHOW AGAIN
</label>
</div>
</center>
</form>
</div>
image: https://www.dropbox.com/s/mpa7rybvpngf19z/ohnails.png
I can't post image, due to my reputation
How can I make for the button is full width?
I tried with:
style: display: block; width: 100%;
and
class btn-block
and
<div class="form-group btn-group-justified">
<input class="form-control btn-block" type="button" style="display: block; width: 100%;" value="Submit">
</div>
but not working
You can override current css by adding id="submit" to the <button> tag and use css to change it's width.
Your example: http://jsfiddle.net/urahara/b64yf2jm/2/
You can do it statically :
edit this:
<input id="submit" type="button" class="form-control" value="Submit">
use css:
#submit{
width:180px; // <-- Your width value
}
Or use css dynamically via jQuery:
Here what we do is assigning the #submit button width with witdh of the other fields on the form. ( I added +8 to compensate padding or margins, just tweak it a bit )
jQuery:
$('#submit').css('width', $('.form-control').width()+8);
If you're using bootstrap shouldnt this work?
<button type="button" class="btn btn-primary btn-lg btn-block" >Block level button</button>
Creates a button the full width of its container.
http://getbootstrap.com/css/#buttons-sizes
Phil

Form input is not clickable on an inline form

With the latest update of Chrome to revision 19.0.1084.52 we notice some strange behavior on forms on our website.
When the form has a style with display:inline and position:relative and the input is wrapped
in a div that floats then the input is not selectable anymore
Here is the most simple example of the bug (check it in Chrome)
<form action="" method="get" style="display:inline; position:relative">
<div>
<label>test1</label>
<input id="test1" name="test1" type="text" value="clickable" />
</div>
<div style="float: left;">
<label>test2</label>
<input id="test2" name="test2" type="text" value="not clickable" />
</div>
<div style="clear:both;"><input type="submit" value="submit"></div>
</form>
Is this a browser bug or is this style not possible?
Hey replace float:left into inline-block
As like this
<form action="" method="get" style="display:inline; position:relative">
<div>
<label>test1</label>
<input id="test1" name="test1" type="text" value="clickable" />
</div>
<div style="display:inline-block;">
<label>test2</label>
<input id="test2" name="test2" type="text" value="not clickable" />
</div>
<div style="clear:both;"><input type="submit" value="submit"></div>
</form>
Live demo http://jsfiddle.net/t4a3r/
​