HTML Bootstrap form and well not aligning to the center - html

I'm working on a simple landing page for a site and my form wont align to the center. If you take a look here you can see that it is slightly offset to the right. I've tried adding a container div around the form and well, setting it as a block with margin:0 auto as well, but nothing changes. I've also tried setting class="span6 offset 3" to align it in the center but that little offset still remains. I have a feeling that all the divs inside other divs are building up some sort of margin on, but I can't seem to figure out how to fix it.
Here's my HTML code:
<div class="row">
<div class="span3"></div><!--/.span3-->
<div class="span6">
<div class="well span6" align="center">
<form id="contact-form" name="contact-form" method="post" action="form-processing.php">
<input class="span6" name="Name" id="Fname" type="text" placeholder="Your name" required>
<input class="span6" name="Email" id="Email" type="email" placeholder="Your email" required>
<input class="span6" name="Message" id="Message" type="text" rows="3" placeholder="What's on your mind?" required><br>
<button type="submit" class="btn btn-primary" id="button">Submit</button>
<button type="reset" class="btn">Clear</button>
</form>
</div><!--/.well span6-->
</div><!--/.span6-->
<div class="span3"></div><!--/.span3-->
</div><!--/.row-->
And here's my non-Bootstrap CSS code:
h1 {font-family: marvel, serif; color:#060; font-size:90px; -webkit-text-stroke: 1px white;}
h2 {font-family: marvel, serif; color:#CCC; font-size:50px; -webkit-text-stroke: 1px black;}
p {color:white; font-size:20px;}
body{
padding: 40px;
margin:0 auto;
background-image: url(../img/background.jpg);
background-repeat: repeat;
background-position: center center;
}
.welcome {padding:30px 0 0 0;}
#Message {overflow:hidden;}
.well {margin:0 auto;}
.navbar-fixed-top,.navbar-fixed-bottom{position:fixed}
If you can figure out what the problem is I'll bake you a pie or something. Thanks.

Here is my new code that I typed out, which is almost identical to the previous, with the omission of a span6 class. Everything is lined up perfectly now.
<div class="row">
<div class="span3"></div><!--/.span3-->
<div class="well span6" align="center">
<form id="contact-form" name="contact-form" method="post" action="form-processing.php">
<input class="span6" name="Name" id="Fname" type="text" placeholder="Your name" required>
<input class="span6" name="Email" id="Email" type="email" placeholder="Your email" required>
<textarea class="span6" name="Message" id="Message" type="text" rows="3" placeholder="What's on your mind?" required></textarea><br>
<button type="submit" class="btn btn-primary" id="button">Submit</button>
<button type="reset" class="btn">Clear</button>
</form>
</div><!--/.well span6-->
<div class="span3"></div><!--/.span3-->
</div><!--/.row-->

I recommend not editing the bootstrap css but including your own css as you've done above. Create an id for the specific you want centered and then pad it until it works. Looks like the bootstrap css interfered with your own css causing the problems. It works now so if you think it's important remember to you only your own css when you want to make changes in the future. One final thing, have the bootstrap page open it gives you an idea of what the spans and rows look like before including them in your page.

It looks like the padding on your "well" class is adding width to bootstrap's span6 class.
You could take the box-sizing route by adding "box-sizing: border-box;" to your well class or by targeting that specific div and reducing the width from 570px (bootstrap's span6 width) to 532px (19px padding on left and right).
Hope that helps.

Remember that for bootstrap theres the '-offset-' class which is very helpful when it comes to aligning items. For example you could use "col-md-12 col-md-offset-2" or for a span6 "col-lg-6 col-lg-offset-3".

Related

Button is not aligning in center in bootstrap form

I have made bootstrap contact from in which I want to align all its element in center.
Below is my code:
.third-section > form > input{
width: 35%;
margin: auto;
margin-top: 25px;
}
.third-section > form > textarea{
width: 35%;
margin:auto;
margin-top: 20px;
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<section class="third-section">
<form>
<input type="text" class="form-control" placeholder="Name" required/>
<input type="email" class="form-control" placeholder="Email" required/>
<textarea id="message" rows="4" class="form-control" placeholder="Message" required></textarea>
<input type="submit" class="btn btn-primary" value="SUBMIT"/>
</form>
</section>
SCREENSHOT
As seen in screenshot button is not aligned in center.Someone please let me know how can I get desired layout. Any help would be appreciated.
THANKS
Add the following CSS
.third-section > form {
text-align: center;
}
if you could provide a working jsfiddle with all of your code in it, that would help. However, from what I can see, your issue can be solved by putting all of your form inside of a container with the text-center class.
<div class="container text-center">
...
</div>
Add bootstrap class 'text-center'. please refer the below code.
<section class="third-section text-center">
<form>
<input type="text" class="form-control" placeholder="Name" required/>
<input type="email" class="form-control" placeholder="Email" required/>
<textarea id="message" rows="4" class="form-control" placeholder="Message" required></textarea>
<input type="submit" class="btn btn-primary" value="SUBMIT"/>
</form></section>
Your button is not aligned because the your button is actually an input. All the elements are centered because they have margin: auto (so the remaining space is split evenly between the two margins). But the input elements (and the elements with class btn from bootstrap) are inline-block, and margin left and right properties are not working on inline and inline-block elements.
One option is the one that metaDesign sugested. Another option is to explicitly set the display property of the button to display: block.
so something like:
input.btn {
display:block;
}

Desktop and mobile display different for DIVS

I've got a very simple table that I have managed to get looking how I want it in desktop versions of chrome and firefox:
Browser output:
However when I view it on a mobile device it loks like this:
Mobile output:
(I put borders round the two elements to so I could see where the div went to etc.
This is my relevant HTML:
<div id="title">My Secret Diary.</div>
<div id="container">
<?php if ($errorMsg){echo "<div id='errorMsg'>".($errorMsg)."</div>";} ?>
<form id="newUserForm" method="POST">
<input type="text" name="email" placeholder="Enter email."><br>
<input type="text" name="password" placeholder="Enter password."><br>
<div class="formDiv">
<input type='hidden' name='signUp' value=1>
<button type="submit" value="submit">Sign Up!</button>
<input type="checkbox" name="rememberUser" value =1>Remember me.<br>
<div id="newToggle">(Already registered? Click here)</div>
</div>
</form>
<form id="logUserForm" method="POST">
<input type="text" name="email" placeholder="Enter email."><br>
<input type="text" name="password" placeholder="Enter password."><br>
<div class="formDiv">
<input type='hidden' name='signUp' value=0>
<button type="submit" value="submit">Log in!</button>
<input type="checkbox" name="rememberUser" value=1>Remember me.<br>
<div id="logToggle">(New user? Click here)</div>
</div>
</form>
</div>
This is my relevant CSS:
#title{
font-family: 'Gaegu', cursive;
font-size: 500%;
width: 1000px;
height: 200px;
color:mediumpurple;
margin:auto;
text-align: center;
padding-top: 50px;
border: black solid 1px;
}
#container{
margin:auto;
width:500px;
padding-top: 50px;
border: solid 1px blue;
}
.formDiv{
text-align: center;
}
Any help muchly appreciated!
basically you want to make your div responsive (to center it in the mobile device), try to use #media rule
The #media rule is used in media queries to apply different styles for different media types/devices.
Media queries can be used to check many things, such as:
1- width and height of the viewport
2- width and height of the device
3-orientation (is the tablet/phone in landscape or portrait mode?) resolution
try to change the size of your text and your videos with the media queries technique, do some research about the media rule css to make your layout responsive.
for me i usually use to solve this kind of problems by wrapping the division which is not centered in mobile but is centered on laptop inside center tags
like this:
<div id="title">
My Secret Diary.
</div>
<center>
<div id="container">
<?php if ($errorMsg){echo "<div id='errorMsg'>".($errorMsg)."</div>";} ?>
<form id="newUserForm" method="POST">
<input type="text" name="email" placeholder="Enter email."><br>
<input type="text" name="password" placeholder="Enter password."><br>
<div class="formDiv">
<input type='hidden' name='signUp' value=1>
<button type="submit" value="submit">Sign Up!</button>
<input type="checkbox" name="rememberUser" value =1>Remember me.<br>
<div id="newToggle">(Already registered? Click here)</div>
</div>
</form>
<form id="logUserForm" method="POST">
<input type="text" name="email" placeholder="Enter email."><br>
<input type="text" name="password" placeholder="Enter password."><br>
<div class="formDiv">
<input type='hidden' name='signUp' value=0>
<button type="submit" value="submit">Log in!</button>
<input type="checkbox" name="rememberUser" value=1>Remember me.<br>
<div id="logToggle">(New user? Click here)</div>
</div>
</form>
</div>
</center>
hope so it may solve your problem

How to set form-group background color

I want to set the background color on form-group. To clarify what I exactly mean, look at the following picture
As you can see above that I marked the div with color, I want to set the background color from form-group.
I tried with the following css.
.signup-ctrl {
//margin-top: 60px;
.form-buffer {
margin: 30px 0px;
background-color: #006dcc;
}
}
and the html
<div class="col-md-5 portfolio-item">
<form>
<div class="form-group form-buffer">
<input type="text" class="form-control" name="name" placeholder="Enter your name">
</div>
<div class="form-group form-buffer">
<input type="email" class="form-control" name="email" placeholder="Enter your email">
</div>
<div class="form-group form-buffer">
<input type="email" class="form-control" name="emailconfirm" placeholder="Enter email confirmation">
</div>
<div class="form-group form-buffer">
<input type="password" class="form-control" name="password" placeholder="Enter your Password">
</div>
<div class="form-group form-buffer">
<input type="text" class="form-control" name="captcha" placeholder="Enter numbers from image">
</div>
<button type="submit" class="btn btn-primary">Sign Up</button>
</form>
</div>
But it does not work, what do I wrong?
Your .form-group takes up exactly the same height as the input inside of it so every background color you add to it is actually hidden behind the input.
You could replace the top/bottom margins with padding to make the .form-group area actually bigger than the input:
.form-group {
padding: 30px 0;
background-color: #006dcc;
}
Your CSS is incorrect, it should be:
.portfolio-item form .form-buffer.form-group {
margin: 30px 0px;
background-color: #006dcc;
}
this will select the whole .form-group. Your mistake was nesting a CSS rule inside another.
Here is a fiddle of it
Sounds strange..!! but it doesnt work like that you have apply padding-bottom: XXpx inside the form-group of your choice instead of applying just background-color, and then it works for the length that you applied in the padding-bottom.

How to output inline text with bootstrap

I have added a !important to make sure that my css rules comes first but my inputs still behave like it was display in block; fiddle
input{
display: inline!important;
}
<p>My name is
<input type="text" placeholder="Name" class="form-control" style='display:inline;'/>
from USA. And I'm <input type="text" placeholder="21" class="form-control" style='display:inline;'/> years old.
</p>
All you need to do is reset the width to auto - it was 100%. It's worth noting that the Bootstrap styling is coming from the .form-control selector; use that to overwrite it.
Updated Example
.form-control {
width:auto;
display:inline-block;
}
No need for inline styling or !important.
<p>My name is
<input type="text" placeholder="Name" name="name" class="form-control" style='display:inline; width:100px'/>
from USA. And I'm <input type="text" name="age" placeholder="21" class="form-control" style='display:inline; width:100px'/> years old.
</p>
you can resize your input button with CSS including width in input style
I added the form tag for inline forms, it works when you have enough room on the page for one line.
<form class="form-inline" role="form">
<div class="form-group">
<p>My name is
<input type="text" placeholder="Name" name="name" class="form-control" style='display:inline;'/>
from USA. And I'm <input type="text" name="age" placeholder="21" class="form-control" style='display:inline;'/> years old.
</p>
</div>
</form>
Here's some more information explaining it from getbootstrap.com.
"Add .form-inline to your for left-aligned and inline-block controls. This only applies to forms within viewports that are at least 768px wide.
Requires custom widths
Inputs, selects, and textareas are 100% wide by default in Bootstrap. To use the inline form, you'll have to set a width on the form controls used within."
http://getbootstrap.com/css/
Works in jsfiddle when it's wide enough.

Aligning text next to a checkbox

Simple question, and undoubtedly an easy solution--I'm just having a lot of trouble finding it despite searching SO and Google for a while.
All I'm looking to do is take the snippet of text "I'm interested in an enhanced listing or premium profile, (a member of our team will respond promptly with further information)" and having it aligned to the right of the check box (with the text left aligned), but not wrapping around it like it is now.
Here's my JSFiddle
Code (using PureCSS for styling):
<form class="pure-form pure-form-aligned">
<fieldset>
<div class="pure-control-group">
<label for="name">Product Name</label>
<input id="name" type="text" placeholder="Username">
</div>
<div class="pure-control-group">
<label for="password">Contact Name</label>
<input id="password" type="text" placeholder="Password">
</div>
<div class="pure-control-group">
<label for="email">Contact Email</label>
<input id="email" type="email" placeholder="Email Address">
</div>
<div class="pure-control-group">
<label for="foo">Website</label>
<input id="foo" type="text" placeholder="Enter something here...">
</div>
<div class="pure-control-group">
<label for="foo">Description:</label>
<textarea id="description" type="text" placeholder="Enter description here..."></textarea>
</div>
<div class="pure-controls">
<label for="cb" class="pure-checkbox">
<input id="cb" type="checkbox">
I'm interested in an enhanced listing or premium profile, (a member of our team will respond promptly with further information)
</label>
<button type="submit" class="pure-button pure-button-primary">Submit</button>
</div>
</fieldset>
</form>
Any help would be much appreciated. Thanks.
Here's a simple way. There are probably others.
<input id="cb" type="checkbox" style="float: left; margin-top: 5px;>">
<div style="margin-left: 25px;">
I'm interested in an enhanced listing or premium profile,
(a member of our team will respond promptly with further information)
</div>
I used a div to "block" structure the text and moved it to the right. The float: left on the input keeps the checkbox to the left of the text (not above). The margin-top on the input tweaks the top alignment with the text.
The fiddle.
This is the method, that I used. It worked better for me than the many other methods I found on SO.
LABEL.indented-checkbox-text
{
margin-left: 2em;
display: block;
position: relative;
margin-top: -1.4em; /* make this margin match whatever your line-height is */
line-height: 1.4em; /* can be set here, or elsewehere */
}
<input id="myinput" type="checkbox" />
<label for="myinput" class="indented-checkbox-text">I have reviewed the business information and documentation above, and assert that the information and documentation shown is current and accurate.</label>
Try floating the check box left, and then wrap the text in a div with "overflow: hidden;". Maybe additionally, add some padding as I did below to give the text some breathing room from the check box (the padding is optional though).
<div class="pure-controls">
<label for="cb" class="pure-checkbox">
<input id="cb" type="checkbox" style="float: left;">
<div style="overflow: hidden; padding: 0px 0px 0px 5px;">
I'm interested in an enhanced listing or premium profile, (a member of our team will respond promptly with further information)
</div>
</label>
<button type="submit" class="pure-button pure-button-primary">Submit</button>
</div>