I am trying to center the text and form field inputs in the #registration-code-entry .registration-code-entry-content div
Not sure what I am doing wrong.
http://jsfiddle.net/yLX4F/
<div id="registration-code-entry">
<div class="registration-code-entry-header"></div>
<div class="registration-code-entry-middle">
<div class="registration-code-entry-content">
<form class="registration-form">
<div class="field">
<input type="text" name="first_name" placeholder="*First Name" class="required" />
</div>
<div class="field">
<input type="text" name="last_name" placeholder="*Last Name" class="required" />
</div>
<div class="field">
<input type="email" name="email" placeholder="*Email Address" class="required" />
</div>
<div class="field">
<input type="text" name="phone" placeholder="Phone Number" />
</div>
<div class="field">
<input type="checkbox" name="optin">
<label for="optin" />Yes, I would like to receive more information</label>
</div>
<div class="field">
<input type="checkbox" name="accept" class="required" />
<label for="accept">*I accept the Official Rules.</label>
</div>
<input type="submit" class="submit-btn" value="">
</form>
</div>
</div>
<div class="registration-code-entry-footer"></div>
</div>
css
#registration-code-entry {
height: 100px;
width: 359px;
position: absolute;
top: 100px;
right: 20px;
background: transparent;
.registration-code-entry-header {
top: 0;
background: transparent url('../images/form-header.png') no-repeat;
width: 359px;
height: 17px;
}
.registration-code-entry-middle {
background: #713487;
.registration-code-entry-content {
border: 1px solid red;
width: 350px;
margin: 0 auto;
color: #fff;
form {
display: inline-block;
margin: 0 auto;
.field {
margin: 10px 0;
input[type="email"], input[type="text"] {
padding: 5px;
}
}
input.submit-btn {
background: transparent url('../images/submit-btn.png') no-repeat;
width: 168px;
height: 59px;
display: block;
border: 0;
}
}
}
}
.registration-code-entry-footer {
display: block;
bottom: 0;
background: transparent url('../images/form-footer.png') no-repeat;
width: 359px;
height: 11px;
}
}
You can add text-align: centerto .field. You can also change to display: block for form to make the form expand to the full width of the parent.
jsfiddle
Centering the input ?
This will centering it :
.field input[type="text"], .field input[type="email"] {
display:block;
margin: auto;
}
Check This
Just change youre less :
...
.field {
margin: 10px 0;
input[type="email"], input[type="text"] {
padding: 5px;
display:block;
margin:0 auto;
}
}
...
Related
This question already has answers here:
Center image using text-align center?
(28 answers)
Flexbox: center horizontally and vertically
(14 answers)
Closed 1 year ago.
For a long time, I am trying to resolve this issue but I was not able to find a good solution for this. I need to align this image on the center of the form but I am totally unsuccessful in it. You may feel like I am elaborating too much, but this is because StackOverflow is not letting me post this question because it thinks that this question needs deep elaboration. I don't know why.
This is my HTML:
<body>
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg"
alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
</body>
This is my CSS:
* {
padding: 0;
margin: 0;
box-sizing: 0;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background-color: orange;
}
.form-container {
display: block;
width: 70vw;
height: 70vh;
padding-bottom: 150px;
}
form {
border: 3px solid #f1f1f1;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 14px 20px;
margin: 8px 0;
width: 100%;
}
button:hover {
opacity: 0.8;
}
img.avatar {
width: 20%;
}
.container {
padding: 16px;
}
How can I align the image in the center? I have tried many ways. But I am not able to do it. I have tried aligning using display flex property and tried aligning it in the center and tried to justify the content in the center!
.imagecontainer {
text-align: center;
}
Will do the job.
Adding text-align:center should solve your problem -
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer" style="text-align:center">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg"
alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
* {
padding: 0;
margin: 0;
box-sizing: 0;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background-color: orange;
}
.form-container {
display: block;
width: 70vw;
height: 70vh;
padding-bottom: 150px;
}
form {
border: 3px solid #f1f1f1;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 14px 20px;
margin: 8px 0;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.imagecontainer {
display: flex;
justify-content: center;
}
img.avatar {
width: 20%;
}
.container {
padding: 16px;
}
<body>
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg" alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
</body>
You need to use the flex property on the parent.
Add this to your css
.imagecontainer {
display: flex;
justify-content: center;
}
Just use margin
html, body {
margin: 0;
}
.wrapper {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
background-color: orange;
}
.form-container {
display: block;
width: 70vw;
height: 70vh;
padding-bottom: 150px;
}
form {
border: 3px solid #f1f1f1;
}
input[type="text"],
input[type="password"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
padding: 14px 20px;
margin: 8px 0;
width: 100%;
}
button:hover {
opacity: 0.8;
}
.imagecontainer {
text-align: center;
}
img.avatar {
width: 20%;
}
.container {
padding: 16px;
}
<body>
<div class="wrapper">
<div class="form-container">
<h2>Login Form</h2>
<br>
<form action="" class="login-form">
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg"
alt="Avatar" class="avatar">
</div>
<div class="container">
<label for="uname"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="uname" required>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<button type="submit">Login</button>
</div>
</form>
</div>
</div>
</body>
Try to use margin:auto on imagecontainer div.
You can make use of <center> tag.
<center>
<div class="imagecontainer">
<img src="https://raw.githubusercontent.com/EdiTechStudio/Beta-ETS/master/favicon.svg" alt="Avatar" class="avatar">
</div>
</center>
Just place the above code in place of imagecontainer div. You need to wrap the div in center tag.
I want to create this form in css
HTML
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
CSS
.contact {
&__form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 105px 95px;
color: $white;
}
&__form-input,
&__form-textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
margin-bottom: 25px;
}
&__form-textarea {
height: 150px;
}
&__form-label {
padding-right: 70px;
}
}
What I'm struggling with is alignment of inputs with labels and of textarea at the same line vertically.
textarea always sticks out at the side, because of its label which has longer text than the rest.
All the help will be appreciated.
I would not use a flexbox for the form, but for each <div> inside the form. The labels are vertically centered for each input field, except for the textarea. There the label is vertically aligned at the top. You can play with top padding there when desired.
* {
box-sizing: border-box;
}
.contact__right {
background-color: gray;
}
.contact__form {
padding: 105px 95px;
width: 100%;
color: white;
}
.contact__form>div {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 25px;
}
.contact__form-input,
.contact__form-textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
}
.contact__form-textarea {
height: 150px;
}
label[for="message"].contact__form-label {
align-self: flex-start;
}
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
Add following css code and your problem will be solved.
.contact__form-label {
vertical-align: top;}
Add this CSS rule for label:
label {
width: 100px;
display: inline-block;
vertical-align: top;
}
(otherwise label will be treated as an inline-element. This way you give it a fixed width and align it to the top)
If you don't like the alignment at the very top, you can add a padding-top ike in the following snippet:
form {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 105px 95px;
color: $white;
}
input,
textarea {
width: 300px;
height: 40px;
background: transparent;
border: 1px solid white;
border-radius: 2px;
margin-bottom: 25px;
}
textarea {
height: 150px;
}
label {
width: 100px;
display: inline-block;
vertical-align: top;
padding-top: 14px;
}
.contact__right {
background: #ccc;
}
<div class="contact__right">
<form action="" class="contact__form">
<div>
<label for="name" class="contact__form-label">Name</label>
<input type="text" id="name" class="contact__form-input">
</div>
<div>
<label for="email" class="contact__form-label">Email</label>
<input type="text" id="email" class="contact__form-input">
</div>
<div>
<label for="phone" class="contact__form-label">Phone</label>
<input type="text" id="phone" class="contact__form-input">
</div>
<div>
<label for="message" class="contact__form-label">Message</label>
<textarea name="message" id="message" cols="30" rows="10" class="contact__form-textarea"></textarea>
</div>
</form>
</div>
ยด
You are gonna have to do that manually I guess. Normally websites tend to break line after the labels and bring the input fields to the next line.
I want to design the responsive contact form where the layout is name, email, subject fields be in one column and message field be in the another column. I could not make that message field appear in another column though I have used the width as 50%. Here is the demo
http://jsbin.com/vuxojuqeve/edit?html,css,output
The code
#responsive-form {
max-width: 600px;
margin: 0 auto;
width: 100%;
}
.form-row {
width: 100%;
}
.form-row input {
margin: 10px 0;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.button {
float: left;
background: #CA0002;
color: #fff;
text-transform: uppercase;
border: none;
padding: 8px 20px;
cursor: pointer;
}
input[type="text"],
textarea {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box
}
.half-size {
width: 50%;
}
<div id="responsive-form" class="clearfix">
<div class="half-size">
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
</div>
<div class="half-size">
<div class="form-row">
<div class="column">
<textarea class="form-control" cols="40" rows="10"></textarea>
</div>
</div>
</div>
<div class="form-row">
<div class="column">
<input type="submit" name="name" class="button">
</div>
</div>
</div>
</div>
This is what I wanted with submit button on the left column
You need to set your containers to display:inline-block, as they are block level elements by default and won't allow others to be positioned beside them.
I'm using 45% because 50% + 50% is not usually 100% when using inline-blocks because of an issue with whitespace, there are some ways around it, I'll let you decide for yourself which hack to use...
#responsive-form {
max-width: 600px;
margin: 0 auto;
width: 100%;
}
.form-row {
width: 100%;
}
.form-row input {
margin: 10px 0;
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
.button {
float: left;
background: #CA0002;
color: #fff;
text-transform: uppercase;
border: none;
padding: 8px 20px;
cursor: pointer;
}
input[type="text"],
textarea {
width: 100%;
padding: 8px;
border: 1px solid #ccc;
border-radius: 3px;
box-sizing: border-box
}
.half-size {
width: 45%;
display:inline-block;
}
<div id="responsive-form" class="clearfix">
<div class="half-size">
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
<div class="form-row">
<div class="column">
<input type="text" name="name" class="form-control">
</div>
</div>
</div>
<div class="half-size">
<div class="form-row">
<div class="column">
<textarea class="form-control" cols="40" rows="10"></textarea>
</div>
</div>
</div>
<div class="form-row">
<div class="column">
<input type="submit" name="name" class="button">
</div>
</div>
</div>
</div>
If there are columns, use flexbox.
Inputs and textarea width unit is vw and e.g. min-width: 180px.
Example
body {
margin: 0;
}
::placeholder,
input[type="submit"] {
color: #BACEE7;
font-weight: bold;
}
.form {
display: flex;
justify-content: center;
padding: 15px;
}
.form input,
.form textarea {
min-width: 180px;
background: #F2F2F2;
border: 1px solid #ccc;
text-transform: uppercase;
border-radius: 3px;
text-align: center;
box-sizing: border-box;
}
.form>.inputs {
margin-right: 5px;
}
.form>.inputs>input {
width: 30vw;
display: block;
margin-bottom: 5px;
padding: 1.5vw;
}
.form>.inputs>input:last-child {
margin-bottom: 0 !important;
}
.form textarea {
width: 35vw;
padding-top: 80px;
display: block;
height: 100%;
}
.form input[type="submit"] {
background: #CA0002;
color: white;
border: none;
cursor: pointer;
}
<div class="form">
<div class="inputs">
<input type="text" name="first_name" placeholder="first name">
<input type="text" name="last_name" placeholder="last name">
<input type="email" name="email" placeholder="email">
<input type="text" name="organization" placeholder="organization">
<input type="tel" name="phone" placeholder="phone">
<input type="submit" name="submit">
</div>
<div class="textarea">
<textarea name="" id="" cols="30" placeholder="message"></textarea>
</div>
</div>
I got my general CSS code for the tool tips from here, but tried tailoring it to my needs:
/* The tooltip stuff */
.tooltip
{
top: -5px;
z-index: 1;
display: inline-block;
width: 200px;
background-color: #e55;
padding: 5px 0;
position: absolute;
color: #fff;
border-radius: 6px;
margin-left: 6px;
}
.tooltip::after
{
content: "";
position: absolute;
top: 50%;
right: 100%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent #e55 transparent transparent;
}
For some reason, however, when I test this with a dummy tool tip, it not only is missing its arrow, but it isn't even on the row that needs it! Even worse, the tool tips, for some reason, sit on top each other!
The HTML code to the main div is as follows:
<div class="main pageCenter">
<form id="newUserRegistration">
<span class="row">
<label for="firstName" class="half">First name</label>
<input type="text" id="firstName" class="half">
<span class="tooltip">text</span>
</input>
</span>
<span class="rowTight">
<label for="lastName" class="half">Last name</label>
<input type="text" id="lastName" class="half">
<span class="hidden tooltip"></span>
</input>
</span>
<span class="rowTight">
<label for="empIDNumber" class="half">Employee ID number</label>
<input type="text" class="number" class="half">
<span class="tooltip">other text</span>
</input>
</span>
<span class="rowTight">
<label for="dept" class="half">Department</label>
<select id="dept" class="half">
<!-- To be populated with data from a Mustache template-->
{{#departments}}
<option id="{{departmentHTMLID}}">{{departmentName}}</option>
{{/departments}}
</select>
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="manager" class="half">Manager name</label>
<input type="text" id="manager" class="half">
<span class="hidden tooltip"></span>
</input>
</span>
<span class="rowTight">
<label for="username" class="half">Username</label>
<input type="text" id="username" class="half">
<span class="hidden tooltip"></span>
</input>
</span>
<span class="rowTight">
<label for="password" class="half">Password</label>
<input type="text" id="password" class="half">
<span class="hidden tooltip"></span>
</input>
</span>
<span class="rowTight">
<label for="confirmPassword" class="half">Confirm password</label>
<input type="text" id="confirmPassword" class="half">
<span class="hidden tooltip"></span>
</input>
</span>
<span class="rowTight">
<label for="email" class="half" title="A confirmation email will be sent to this e-mail address.">E-mail address</label>
<input type="email" class="half" title="A confirmation email will be sent to this e-mail address.">
<span class="hidden tooltip"></span>
</input>
</span>
<span class="right row buttonRow">
<input type="reset" class="right" value="Clear"/>
<input type="submit" class="right" value="Submit" />
</span>
</form>
</div>
and the rest of my CSS code is as follows:
/* Fractional-width classes */
.fiveSixths { width: 83.3333333333333333%; }
.fourFifths { width: 80%; }
.threeFourths { width: 75%; }
.twoThirds { width: 66.6666666666666667%; }
.threeFifths { width: 60%; }
.half { width: 50%; }
.twoFifths { width: 40%; }
.third { width: 33.3333333333333333%; }
.fourth { width: 25%;}
.fifth { width: 20%; }
.sixth { width: 16.6666666666666667%; }
.main
{
border: 2px solid orange;
border-radius: 5px;
box-shadow: 0px 0px 100px orange;
}
.main > *
{
padding: 10px;
}
.pageCenter
{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
input[type="text"],input[type="password"], input[type="email"]
{
border-left-style: none !important;
border-right-style: none !important;
border-top-style: none !important;
border-bottom-color: #888 !important;
}
input[type="submit"],input[type="reset"],button
{
height: 25px;
width: 100px;
border-width: 1px;
border-radius: 3px;
}
input[type="submit"]
{
background-color: orange;
border-color: orange;
}
input[type="submit"]:hover
{
background-color: #fb0;
}
.hidden
{
display: none;
visibility: hidden;
}
.row:not(.buttonRow),.rowTight:not(.buttonRow)
{
display: block;
width: 100%;
}
.row
{
margin-top: 10px;
margin-bottom: 10px;
}
.rowTight
{
margin-top: 5px;
margin-bottom: 5px;
}
.right
{
float: right;
}
.number
{
text-align: right;
}
.main
{
min-width: 450px;
width: 50%;
}
#formContainer
{
padding: 20px;
}
#newUserRegistration > *:not(input[type="submit"])
{
width: 100%;
overflow: hidden;
}
#newUserRegistration > * > *
{
float: left;
}
#newUserRegistration > * > *:not(:first-child):not([type="submit"]):not([type="reset"]):not(button)
{
margin-left: -4px;
}
#newUserRegistration span
{
overflow: auto;
}
I've been trying to play with this for a while, but couldn't get the tool tips to position properly, nor for them to not be on top each other.
Although position: relative was declared on your containing elements, the overflow: auto property declared in addition prevented any overflow of the element's contents being visible, and so the tooltip could not be properly observed because of this.
To address this:
Remove the float: left rules declared on nested elements by the
following rule: #newUserRegistration > * > * - the global
selectors (*) for this rule causes havoc in this case, and should
be avoided, for better practice use more specific selectors and
only style what you are required to.
Only float your form fields right, with more specific selectors,
e.g:
#newUserRegistration select, #newUserRegistration input {
float: right;
}
You are no longer required to clear floats using overflow: auto on
the containing parent element, allowing your absolutely positioned
tooltips to remain visible. In addition, a left positioning property has been added to your tooltips.
Updated JSFiddle
Code Snippet Demonstration:
/* The tooltip stuff */
.tooltip
{
top: -5px;
left: 100%; /* Added - position absolute tooltip relative to parent row */
z-index: 1;
display: inline-block;
width: 200px;
background-color: #e55;
padding: 5px 0;
position: absolute;
color: #fff;
border-radius: 6px;
margin-left: 6px;
}
.tooltip::after
{
content: "";
position: absolute;
top: 50%;
right: 100%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent #e55 transparent transparent;
}
/* Fractional-width classes */
.fiveSixths { width: 83.3333333333333333%; }
.fourFifths { width: 80%; }
.threeFourths { width: 75%; }
.twoThirds { width: 66.6666666666666667%; }
.threeFifths { width: 60%; }
.half { width: 50%; }
.twoFifths { width: 40%; }
.third { width: 33.3333333333333333%; }
.fourth { width: 25%;}
.fifth { width: 20%; }
.sixth { width: 16.6666666666666667%; }
.main
{
border: 2px solid orange;
border-radius: 5px;
box-shadow: 0px 0px 100px orange;
}
.main > *
{
padding: 10px;
}
.pageCenter
{
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
input[type="text"],input[type="password"], input[type="email"]
{
border-left-style: none !important;
border-right-style: none !important;
border-top-style: none !important;
border-bottom-color: #888 !important;
}
input[type="submit"],input[type="reset"],button
{
height: 25px;
width: 100px;
border-width: 1px;
border-radius: 3px;
}
input[type="submit"]
{
background-color: orange;
border-color: orange;
}
input[type="submit"]:hover
{
background-color: #fb0;
}
.hidden
{
display: none;
visibility: hidden;
}
.row:not(.buttonRow),.rowTight:not(.buttonRow)
{
display: block;
position: relative;
width: 100%;
}
.row
{
margin-top: 10px;
margin-bottom: 10px;
}
.rowTight
{
margin-top: 5px;
margin-bottom: 5px;
}
.right
{
float: right;
}
.number
{
text-align: right;
}
.main
{
min-width: 450px;
width: 50%;
}
#formContainer
{
padding: 20px;
}
#newUserRegistration > *:not(input[type="submit"])
{
width: 100%;
overflow: hidden;
}
#newUserRegistration > * > * /* this is causing mayhem, selectors should be more specific */
{
float: left;
}
/* ...like this */
#newUserRegistration select, #newUserRegistration input {
float: right;
}
#newUserRegistration label {
float: none;
}
#newUserRegistration > * > *:not(:first-child):not([type="submit"]):not([type="reset"]):not(button)
{
margin-left: -4px;
}
/* not necessary, since you no longer need to clear nested elements that are floated
#newUserRegistration span
{
overflow: auto;
} */
<div class="main pageCenter">
<form id="newUserRegistration">
<span class="row">
<label for="firstName" class="half">First name</label>
<input type="text" id="firstName" class="half" />
<span class="tooltip">text</span>
</span>
<span class="rowTight">
<label for="lastName" class="half">Last name</label>
<input type="text" id="lastName" class="half" />
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="empIDNumber" class="half">Employee ID number</label>
<input type="text" class="number half" />
<span class="tooltip">other text</span>
</span>
<span class="rowTight">
<label for="dept" class="half">Department</label>
<select id="dept" class="half">
<!-- To be populated with data from a Mustache template-->
{{#departments}}
<option id="{{departmentHTMLID}}">{{departmentName}}</option>
{{/departments}}
</select>
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="manager" class="half">Manager name</label>
<input type="text" id="manager" class="half" />
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="username" class="half">Username</label>
<input type="text" id="username" class="half" />
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="password" class="half">Password</label>
<input type="text" id="password" class="half" />
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="confirmPassword" class="half">Confirm password</label>
<input type="text" id="confirmPassword" class="half" />
<span class="hidden tooltip"></span>
</span>
<span class="rowTight">
<label for="email" class="half" title="A confirmation email will be sent to this e-mail address.">E-mail address</label>
<input type="email" class="half" title="A confirmation email will be sent to this e-mail address." />
<span class="hidden tooltip"></span>
</span>
<span class="right row buttonRow">
<input type="submit" class="right" value="Submit" />
<input type="reset" class="right" value="Clear"/>
</span>
</form>
</div>
I created an overlay with div over top of it, right now I am trying to center the div over top of the overlay, I tried messing around the left and right but nothing worked.
.request-estimate {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
background-color: rgba(0,0,0,0.8);
display: none;
}
.request-estimate-box {
display: none;
height: 400px;
width: 40%;
margin: 0 auto;
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
padding: 20px;
border-radius: 5px;
}
And here is the CSS
<div class="request-estimate"></div>
<div class="request-estimate-box">
<h1>Request Free Estimate</h1>
<form action="" method="post">
<p>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" />
</p>
<p>
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control" />
</p>
<p>
<label for="phone">Phone</label>
<input type="phone" name="phone" id="phone" class="form-control" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-default" />
</p>
</form>
</div>
.request-estimate {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
background-color: rgba(0,0,0,0.8);
/*display: none;*/
}
.request-estimate-box {
/*display: none;*/
height: 400px;
width: 40%;
margin-left:-20%; /*add this = width/2*/
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
left:50%; /*add this*/
padding: 20px;
border-radius: 5px;
}
<div class="request-estimate"></div>
<div class="request-estimate-box">
<h1>Request Free Estimate</h1>
<form action="" method="post">
<p>
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control" />
</p>
<p>
<label for="email">Email</label>
<input type="email" name="email" id="email" class="form-control" />
</p>
<p>
<label for="phone">Phone</label>
<input type="phone" name="phone" id="phone" class="form-control" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" class="btn btn-default" />
</p>
</form>
</div>
Solution: https://jsfiddle.net/gqqqeLfL/
request-estimate-box was not being contained by request-estimate.
Originally:
<div class="request-estimate"></div>
<div class="request-estimate-box"></div>
Changed to:
<div class="request-estimate">
<div class="request-estimate-box"></div>
</div>
Furthermore, removed position:fixed since that glues the element to an exact position thus nullifing your margin-auto. Now the position default is position:relative and the margin:auto is properly executed.
I see two alternatives :
.request-estimate-box {
height: 400px;
width: 40%;
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
left: 0;
right: 0;
margin: auto;
padding: 20px;
border-radius: 5px;
}
http://codepen.io/anon/pen/dPLxPJ?editors=110
And :
.request-estimate-box {
height: 400px;
width: 40%;
background-color: #FFF;
z-index: 99999;
position: fixed;
top: 15%;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
padding: 20px;
border-radius: 5px;
}
http://codepen.io/anon/pen/ByEXyM?editors=110
And a margin half it's width from the center of course, like Tambo is suggesting.