Align 2 items side-by-side in a flex column - html

I am very new to flex. But I'm loving it so far. The question I have is, how do I align two items side-by-side when the parent has flex-direction: column;?
I have pasted my HTML and Sass code here along with screenshots.
I have a form like so:
// manage.html
<div class="form2" hidden>
<div class="message" hidden></div>
<form id="updateUserForm" action="https://someaction.com" method="POST">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
Cancel
<button type="submit " class="updateButton"></button>
</form>
</div>
That is styled like so:
// style.scss
.form2 {
#updateUserForm {
display: flex;
flex-direction: column;
}
label {
text-align: center;
}
input {
border-style: solid;
border-color: $black;
color: $black;
font-size: 16px;
padding: 10px 14px;
text-align: left;
margin: 4px 2px;
}
input:focus::-webkit-input-placeholder {
color: transparent;
}
input:focus:-moz-placeholder {
color: transparent;
}
input:focus::-moz-placeholder {
color: transparent;
}
input:focus:-ms-input-placeholder {
color: transparent;
}
a,
button {
border: none;
color: $white;
background-color: $blue;
padding: 12px 16px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
display: inline-block;
align-self: flex-start;
cursor: pointer;
}
}
Here is the output:
I would like to align 'Cancel' link and 'Reactivate' button side by side. I tried the following:
// style.scss
a {
align-self: flex-start;
}
button {
align-self: flex-end;
}
This only slides the elements to left and right respectively without being on the same line. Here is the output I wish to get:
Any suggestions on how to reach my expected output?

You can just use flex-wrap: wrap with row direction and set flex: 0 0 100% on inputs.
form {
display: flex;
flex-wrap: wrap;
}
input {
flex: 0 0 100%;
}
<div class="form2">
<div class="message"></div>
<form id="updateUserForm">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
Cancel
<button type="submit " class="updateButton">Lorem</button>
</form>
</div>

Just place them in a container and change direction.
#updateUserForm {
display: flex;
flex-direction: column;
}
label {
text-align: center;
}
input {
border-style: solid;
border-color: black;
color: black;
font-size: 16px;
padding: 10px 14px;
text-align: left;
margin: 4px 2px;
}
input:focus::-webkit-input-placeholder {
color: transparent;
}
input:focus:-moz-placeholder {
color: transparent;
}
input:focus::-moz-placeholder {
color: transparent;
}
input:focus:-ms-input-placeholder {
color: transparent;
}
/*Just place them in a container and change direction*/
#button_container{
display:flex;
}
a,
button {
border: none;
color: white;
background-color: blue;
padding: 12px 16px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
display: inline-block;
align-self: flex-start;
cursor: pointer;
text-transform: uppercase;
}
<div class="form2">
<div class="message" hidden></div>
<form id="updateUserForm" action="https://someaction.com" method="POST">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
<!--Just place them in a container and change direction -->
<div id="button_container">
Cancel
<button type="submit " class="updateButton">Reactivate</button>
<div>
</form>
</div>

With the existing markup, using flex-direction: column, you can't make those two "buttons" align side-by-side.
One way is to change to row wrap and make all the input + label 100% width, which can be done with either width: 100% (used below) or flex-basis: 100%.
With that the items being 100% wide will stack vertical and the rest horizontal (unless their total width doesn't exceed 100%)
Stack snippet
form {
display: flex;
flex-wrap: wrap;
}
label {
text-align: center;
width: 100%;
}
input {
border-style: solid;
border-color: black;
color: black;
font-size: 16px;
padding: 10px 14px;
text-align: left;
margin: 4px 2px;
width: 100%;
}
a,
button {
border: none;
color: white;
background-color: blue;
padding: 12px 16px;
text-align: center;
text-decoration: none;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
<div class="form2">
<div class="message"></div>
<form id="updateUserForm" action="https://api.ghjobssubscribe.com/manage/update" method="POST">
<label class="userInfo"></label>
<input type="text" name="userFirstName" class="userFirstName" placeholder="First Name">
<input type="text" name="userLastName" class="userLastName" placeholder="Last Name">
<input type="text" name="subTag" class="subTag" placeholder="Title, benefits, companies, expertise">
<input type="text" name="subLocation" class="subLocation" placeholder="City, state, zipe code or country">
Cancel
<button type="submit " class="updateButton">Submit</button>
</form>
</div>

Related

Form field alignment issues using flexbox [duplicate]

This question already has an answer here:
Input field wrapping using flexbox
(1 answer)
Closed 1 year ago.
PROBLEM:
I'm having some alignment issues with this form.
CODE SNIPPET:
.form-container {
display: flex;
margin: 0 auto;
align-items: center;
justify-content: center;
}
.verification-form {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.verification-form .form-group {
display: flex;
flex-direction: row;
margin-bottom: 35px;
width: 100%;
}
.verification-form .form-group:nth-child(3) {
margin-bottom: 5px;
}
.form-group label {
text-align: right;
font-size: 11px;
font-weight: bold;
color: #484343;
margin-left: 10px;
max-width: 150px;
}
.form-group input {
padding: 0px 0px;
margin-left: 20px;
flex: 3;
border: 2px solid #d2d2d2;
border-width: 0 0 2px 0;
transition: border-color 0.3s;
font-size: 18px;
}
#required::after {
content: "*";
color: #f06d41;
font-size: 28px;
}
.form-group input:hover {
border-color: #aa2c2f;
outline: 0;
}
.form-group input:focus {
border-color: #aa2c2f;
outline: 0;
}
input[type="checkbox"] {
width: 28px !important;
height: 28px !important;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
box-shadow: none;
text-align: center;
background: #ffffff;
flex: none;
padding: 0px 0px;
margin-left: 20px;
border: 2px solid #d2d2d2;
border-width: 2px;
transition: border-color 0.3s;
font-size: 18px;
cursor: pointer;
}
input[type="checkbox"]:checked:after {
content: "✔";
color: #aa2c2f;
<div class="form-container">
<div class="verification-form">
<div class="form-group">
<label>FIRST</label>
<input id="firstName" type="" name="firstName" value="" required />
<label>LAST</label>
<input id="lastName" type="" name="lastName" value="" required />
</div>
<div class="form-group" id="required">
<label>EMAIL</label>
<input id="email" type="email" name="email" value="" required />
</div>
<div class="form-group">
<label>PHONE</label>
<input id="phone" type="" name="phone" value="" required />
<label class="sms-label">SMS<br />OPT IN</label>
<input id="sms" type="checkbox" name="sms" value="" required />
</div>
<div class="form-group" id="required">
<label>STREET<br />ADDRESS</label>
<input id="address" type="text" name="address" value="" required />
</div>
<div class="legend">
<p>
<sub>*</sub>Required field
</p>
</div>
</div>
</div>
As you can see, the form looks wonky.
I feel like this is the culprit:
.form-group input {
padding: 0px 0px;
margin-left: 20px;
flex: 3;
border: 2px solid #d2d2d2;
border-width: 0 0 2px 0;
transition: border-color 0.3s;
font-size: 18px;
}
I would like the form to align properly where all fields in a single column are the same size and aligned. I also want the rows with two form fields to be even with rows that have only one field.
I've tried excluding flex:3 with a static width, however, this is not the solution. Would appreciate any help in making this look better.
EDIT: Also open to a solution using CSS grid.
I did some changes in your code. You should use flex for the paten div for the form and if you give witdh:100% to the input fileds it will fit the container of its own. So here the html and css for your form.
Html:
<div class="form-container">
<div class="verification-form">
<div class="form-group" >
<label class="required">FIRST</label>
<input id="firstName" type="" name="firstName" value="" required />
<label class="required">LAST</label>
<input id="lastName" type="" name="lastName" value="" required />
</div>
<div class="form-group" id="required">
<label class="required">EMAIL</label>
<input id="email" type="email" name="email" value="" required />
</div>
<div class="form-group">
<label class="required">PHONE</label>
<input id="phone" type="" name="phone" value="" required />
</div>
<div class="form-group row">
<label class="sms-label required">SMS OPTION</label>
<input id="sms" type="checkbox" name="sms" value="" required />
</div>
<div class="form-group" id="required">
<label class="required" >STREET ADDRESS</label>
<input id="address" type="text" name="address" value="" required />
</div>
<div class="legend">
<p>
<sub class="required"></sub>Required field
</p>
</div>
</div>
</div>
CSS:
.verification-form .form-group:nth-child(3) {
margin-bottom: 5px;
}
.form-group {
display:flex;
flex-direction:column;
text-align:start;
justify-content:flex-start;
max-width:320px;
padding:10px;
}
.form-group.row {
flex-direction:row;
align-items:center;
margin-bottom:10px;
}
.form-group label {
text-align: start;
font-size: 11px;
font-weight: bold;
color: #484343;
margin-left: 20px;
margin-bottom:10px;
max-width: 200px;
}
.form-group input {
width:100%;
padding: 0px 0px;
margin-left: 20px;
flex: 3;
border: 2px solid #d2d2d2;
border-width: 0 0 2px 0;
transition: border-color 0.3s;
font-size: 18px;
margin-bottom:10px;
}
.required::after {
content: "*";
color: #f06d41;
font-size: 16px;
}
.form-group input:hover {
border-color: #aa2c2f;
outline: 0;
}
.form-group input:focus {
border-color: #aa2c2f;
outline: 0;
}
.legend {
margin-left:20px;
}
input[type="checkbox"] {
width: 28px !important;
height: 28px !important;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
outline: none;
box-shadow: none;
text-align: center;
background: #ffffff;
flex: none;
padding: 0px 0px;
margin-left: 20px;
border: 2px solid #d2d2d2;
border-width: 2px;
transition: border-color 0.3s;
font-size: 18px;
cursor: pointer;
}
input[type="checkbox"]:checked:after {
content: "✔";
color: #aa2c2f;}

Centering the checkbox in a line [duplicate]

This question already has answers here:
How can I vertically align elements in a div?
(28 answers)
Closed 3 years ago.
I would like to center the checkbox in a line with text next to it.
I've tried already style="text-align: center;" in <div> but it doesn't work.
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2)
}
input:checked[type="checkbox"] {
background-color: transparent;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail" />
<input type="password" name="password" id="password" placeholder="password" />
<button>Create account</button>
<div style="text-align: center;">
<input type="checkbox" name="consent" id="consent" />
<label for="consent">I agree to whatever you want me to agree</label>
</div>
</form>
At the moment it looks like this in the attached picture. So can someone please guide me on how to center the checkbox in a line?
here
Please add below line only your css class, not need to change in html you written:
vertical-align: middle;
position: relative;
bottom: 1px;
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2);
vertical-align: middle;
position: relative;
bottom: 1px;
}
input:checked[type="checkbox"] {
background-color: transparent;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail"/>
<input type="password" name="password" id="password" placeholder="password"/>
<button>Create account</button>
<div style="text-align: center;">
<input type="checkbox" name="consent" id="consent"/>
<label for="consent">I agree to whatever you want me to agree</label>
</div>
</form>
Just put the checkbox in the tag and use
display: flex;
align-items: center;
on the label
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width: 15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2)
}
input:checked[type="checkbox"] {
background-color: transparent;
}
label {
display: flex;
align-items: center;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail" />
<input type="password" name="password" id="password" placeholder="password" />
<button>Create account</button>
<div>
<label for="consent"><input type="checkbox" name="consent" id="consent" />I agree to whatever you want me to agree</label>
</div>
</form>
Use align-items property.
div { display: flex; align-items: center; } //immediate parent of checkbox and label
For parent div of input add the below style property
.div{
Display:inline-flex;
}
Or you can add the below code
<label for="input" ><input type="checkbox" name="input" /></label>
Try position:relative and bottom:**px as per your need
input {
font-size: 16px;
}
label {
font-size: 11px;
vertical-align: middle;
}
form {
margin-top: 30px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
input[type="checkbox"] {
width:15px;
height: 15px;
-webkit-appearance: none;
background: white;
outline: none;
border: none;
border-radius: 50%;
transition: .5s;
box-shadow: inset 0 0 5px rgba(0, 0, 0, .2);
margin:0;
bottom:-3.5px;
position:relative
}
input:checked[type="checkbox"] {
background-color: transparent;
}
<form class="form-box__form form">
<input type="e-mail" name="e-mail" id="e-mail" placeholder="e-mail"/>
<input type="password" name="password" id="password" placeholder="password"/>
<button>Create account</button>
<div style="text-align: center;display:inline;">
<input type="checkbox" name="consent" id="consent" >
<label for="consent" > I agree to whatever you want me to agree</label>
</div>
</form>

CSS divs not horizontally aligned properly [duplicate]

This question already has answers here:
Align inline-block DIVs to top of container element
(5 answers)
Closed 4 years ago.
This is probably a stupid question, but it has been driving me crazy the whole day. I need both divs with the class of contacthor to be aligned on the top, but not forcing them by using margin-top: -x or etc. Here is an image of the issue.
Also, Im new to web design so if I have useless code please explain.
Thanks.
#redcontact {
margin-bottom: 0;
padding-left: 5vh;
font-size: 15px;
line-height: 30px;
background: black;
}
.contacthor {
display: inline-block;
}
form > .contacthor > .input {
color: #C5B358;
font-size: 15px;
background-color: black;
margin-top: 0;
margin-left: 1vh;
margin-bottom: 1vh;
height: 30px;
width: 190px;
display: block;
}
.contacthor > textarea {
color: #C5B358;
font-size: 15px;
font-family: 'Montserrat', sans-serif;
width: 60vh;
height: 25vh;
background: black;
border: 1px;
border-style: solid;
border-radius: 3px;
border-color: grey;
padding-left: 4px;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
<div id="redcontact">
<form action="action_page.php">
<div class="contacthor">
<label for="name">Nombre</label>
<input class="input" type="text" name="name_user" placeholder="test">
<label for="org">Empresa</label>
<input class="input" type="text" name="org" placeholder="test">
<label for="mail">Mail</label>
<input class="input" type="text" name="mail" placeholder="contacto#test.com">
</div>
<div class="contacthor">
<p>Mensaje</p>
<textarea name="mensaje" tabindex="5" placeholder="text..."></textarea>
<input type="submit" value="enviar">
</div>
</form>
</div>
I would agree with Chere's answer in that you should be using something like CSS Grid or Flexbox. However, if you want to stay simple for this example, or just want to know why your code isn't working, here is a solution:
#redcontact {
margin-bottom: 0;
padding-left: 5vh;
font-size: 15px;
line-height: 30px;
background: black;
}
.contacthor {
display: inline-block;
}
form>.contacthor>.input {
color: #C5B358;
font-size: 15px;
background-color: black;
margin-top: 0;
margin-left: 1vh;
margin-bottom: 1vh;
height: 30px;
width: 190px;
display: block;
}
.contacthor>textarea {
color: #C5B358;
font-size: 15px;
font-family: 'Montserrat', sans-serif;
width: 60vh;
height: 25vh;
background: black;
border: 1px;
border-style: solid;
border-radius: 3px;
border-color: grey;
padding-left: 4px;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
.contacthor>p {
margin-bottom: 5px;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
.contacthor>input[value=enviar] {
display: block;
margin-top: 0;
margin-bottom: 1vh;
margin-left: 1vh;
}
/* ===== Styles to fix example ===== */
label, p {
color: white;
}
/* ===== Styles to answer your question ===== */
.contacthor {
vertical-align: top;
}
<div id="redcontact">
<form action="action_page.php">
<div class="contacthor">
<label for="name">Nombre</label>
<input class="input" type="text" name="name_user" placeholder="test">
<label for="org">Empresa</label>
<input class="input" type="text" name="org" placeholder="test">
<label for="mail">Mail</label>
<input class="input" type="text" name="mail" placeholder="contacto#test.com">
</div>
<div class="contacthor">
<p>Mensaje</p>
<textarea name="mensaje" tabindex="5" placeholder="text..."></textarea>
<input type="submit" value="enviar">
</div>
</form>
</div>
The main thing to take away from this is the addition of vertical-align: top. Here is a similar question and here is the documentation for the vertical-align property.
Note: I think there may have been some CSS missing, so the snippet looks a bit odd and I had to make a couple of unrelated changes.
Why is there a . before the input?
Also, I highly recommend not using vh or pixels. You should go with em. Without doing everything, you should probably try to do something like that, with flexbox.
#redcontact {
width: 100%;
height: 100%;
font-size: 15px;
line-height: 1.5;
background-color: #000;
color: #fff;
}
form {
display: flex;
padding: 2em;
.contacthor {
display: flex;
flex-direction: column;
width: 50%;
padding: 0 2em;
input,
textarea {
color: #C5B358;
background-color: transparent;
margin-left: 1em;
margin-bottom: 1em;
padding: 0.5em 1em;
width: auto;
display:block;
}
input {
border: 0;
}
textarea {
border: 1px solid grey;
border-radius: 3px;
}
}
}
I have made a grid. See if you are looking for somewhat similar thing.
https://codepen.io/kalpeshshende/pen/qJjomO
form{
display:grid;grid-gap:10px;
grid-template-columns:1fr 2fr;
}
.holder{
max-width:600px;
margin:auto;
background:black;
color:#C5B358;padding:10px;
}
.contacthor{
display:grid;grid-gap:10px;
}
textarea{
height:100px;
}
input[type=submit]{
width:120px;
}
p{
padding:0px;
}
input[type=text]{
background:black;
color:;border:none;
}
Markup :
<body>
<div class="holder">
<form action="">
<div class="contacthor">
<label for="name" >Nombre</label>
<input class="input" type="text" name="name_user" placeholder="test">
<label for="org">Empresa</label>
<input class="input" type="text" name="org" placeholder="test">
<label for="mail">Mail</label>
<input class="input" type="text" name="mail" placeholder="contacto#test.com">
</div>
<div class="contacthor">
<label for="Mensaje">Mensaje</label>
<textarea name="mensaje" tabindex="5" placeholder="text..."></textarea>
<input type="submit" value="enviar">
</div>
</form>
</div>
</body>
Try adding vertical-align: top; to contracthor.

How can I get the label text to the left of the input field?

I am not able to understand how I can get the label from top of the input field to the left. The label text is on top of the input field. How can I get it to the left of the input field for the contact information part? Any help would be appreciated. Thanks a lot.
This is my code:
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can reset width and display on inputs and/or use float.
It can be a reset at any time or within the mediaquerie.
You can also filter within which fieldset you need this reset to be effective.(example below)
.formcenter fieldset:first-of-type label,
.formcenter fieldset:first-of-type input{
float: left;
line-height: 1.2em;
padding: 6px;
margin: 8px 0;
width: 50%;
}
.formcenter fieldset:first-of-type label {
clear: left;
width: 35%;
}
input[type="checkbox"],
input[type="radio"]{
margin-right:1em;
}
fieldset ~ fieldset br + label {
margin:1em;
color:gray
}
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
.formcenter fieldset:first-of-type label,
.formcenter fieldset:first-of-type input{
float: left;
line-height: 1.2em;
padding: 6px;
margin: 8px 0;
width: 50%;
}
.formcenter fieldset:first-of-type label {
clear: left;
width: 35%;
}
input[type="checkbox"],
input[type="radio"]{
margin-right:1em;
}
fieldset ~ fieldset br + label {
margin:1em;
color:gray
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can use display:flex with a container for each lines
.line
{
display:flex;
align-items:center;
}
.line label
{
min-width:200px;
}
input
{
flex:1;
margin:10px;
}
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<div class="line">
<label for="inputfield">Full Name :</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
</div>
<div class="line">
<label for="inputfield1">Email Address :</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
</div>
<div class="line">
<label for="inputfield2">Phone Number :</label>
<input type="text" name="phonenumber" id="inputfield2">
</div>
<div class="line">
<label for="inputfield3">Street Address :</label>
<input type="text" name="streetaddress" id="inputfield3">
</div>
<div class="line">
<label for="inputfield4">City :</label>
<input type="text" name="city" id="inputfield4">
</div>
<div class="line">
<label for="stateselect">State :</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
</div>
<div class="line">
<label for="zipcode">Zip Code :</label>
<input type="text" name="zipcode" id="zipcode">
</div>
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<input type="checkbox" name="htmlnews"><label>HTML News</label><br><br>
<input type="checkbox" name="css"><label>CSS News</label><br><br>
<input type="checkbox" name="javascript"><label>Javascript News</label><br><br>
<label>Newsletter format</label><br><br>
<input type="radio" name="newsletter" value="html"><label>HTML</label><br><br>
<input type="radio" name="newsletter" value="plaintext"><label>Plain Text</label><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
Swap your labels and inputs to get desired result:
#p1 {
text-align: center;
background-color: black;
color: white;
padding: 20px;
}
#h31 {
text-align: center;
}
#p2 {
text-align: center;
}
input[type="text"] {
border: 2px solid grey;
border-radius: 4px;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
input[type="text"]:focus {
border: 2px solid blue;
}
input[type="email"]:focus {
border: 2px solid blue;
}
::placeholder {
text-align: right;
}
input[type="submit"] {
background-color: #3cbc8d;
color: white;
border-radius: 4px;
padding: 16px 32px;
width: 100%;
}
input[type="email"] {
border: 2px solid grey;
padding: 6px;
width: 90%;
background-color: #d3d3d3;
display: block;
margin: 8px 0;
}
#p3 {
text-align: center;
}
#submitdiv {
text-align: center;
}
#textareadiv {
text-align: center;
}
textarea {
width: 100%;
}
hr {
width: 100%;
}
select {
background-color: #d3d3d3;
padding: 6px;
width: 90%;
display: block;
margin: 8px 0;
}
input[id="zipcode"] {
width: 40%;
}
body {
font-family: 'Merriweather', serif;
}
fieldset {
border: none;
}
#media screen and (min-width: 768px) {
.formcenter {
text-align: center;
display: block;
}
form {
text-align: left;
margin-left: auto;
margin-right: auto;
display: inline-block;
}
select {
width: 90%;
padding: 6px;
border-radius: 4px;
}
#p1 {
width: 100%;
}
hr {
width: 100%;
}
}
<link href="https://fonts.googleapis.com/css?family=Merriweather" rel="stylesheet">
<p id="p1">THE CODE REVIEW</p><br><br>
<div class="formcenter">
<form method="post" action="project3.html">
<h3 id="h31">Sign up for our newsletter</h3>
<p id="p2">Get the latest news on how your code is doing right in your inbox</p>
<hr>
<hr>
<fieldset>
<legend>
<h3 id="h32">Contact Information</h3>
</legend>
<label for="inputfield">Full Name</label>
<input type="text" name="fullname" placeholder="Required" id="inputfield">
<label for="inputfield1">Email Address</label>
<input type="email" name="emailaddress" placeholder="Required" id="inputfield1">
<label for="inputfield2">Phone Number</label>
<input type="text" name="phonenumber" id="inputfield2">
<label for="inputfield3">Street Address</label>
<input type="text" name="streetaddress" id="inputfield3">
<label for="inputfield4">City</label>
<input type="text" name="city" id="inputfield4">
<label for="stateselect">State</label>
<select name="state" id="stateselect">
<option>Choose State</option>
<option value="mah">Maharashtra</option>
<option value="guj">Gujarat</option>
<option value="pun">Punjab</option>
</select>
<label for="zipcode">Zip Code</label>
<input type="text" name="zipcode" id="zipcode">
</fieldset>
<hr>
<fieldset>
<legend>
<h3>Newsletter</h3>
</legend><br>
<label>Select the newsletters you would like to receive</label><br><br>
<label>HTML News</label><input type="checkbox" name="htmlnews"><br><br>
<label>CSS News</label><input type="checkbox" name="css"><br><br>
<label>Javascript News</label><input type="checkbox" name="javascript"><br><br>
<label>Newsletter format</label><br><br>
<label>HTML</label><input type="radio" name="newsletter" value="html"><br><br>
<label>Plain Text</label><input type="radio" name="newsletter" value="plaintext"><br><br>
<label>Other topics you'd like to hear about</label><br><br>
<div id="textareadiv">
<textarea rows="5" cols="30"></textarea><br><br>
</div>
<div id="submitdiv">
<input type="submit" value="Sign Up"><br><br>
</div>
</fieldset>
<p id="p3"><i>Copyright The Code Review</i></p>
</form>
</div>
You can do this fairly easily:
Full Name: <input type="text" name="fullname" placeholder="Required" id="inputfield">
This will just make the text appear to the left side of the input itself.
I used this method for a newsletter input I was doing:
Name: <input id="nameInput" type="text" name="name" required><br>

How to move form to center of page

I am creating a registration form and am wondering how can I move the whole form to the center of the page? right now its all on the left side of the container, I want it to look a bit something like this: https://id2.s.nfl.com/fans/register?returnTo=http%3A%2F%2Fweeklypickem.fantasy.nfl.com%2F
#Regcontainer {
width: 1200px;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> </h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label>FIRST NAME</label>
<input type="text" name="FName" />
<label>LAST NAME</label>
<input type="text" name="SNAME" />
<br/>
<label>EMAIL ADDRESS</label> <input id="email" name="email" type="text" />
<BR/>
<label>CREATE YOUR USERNAME</label> <input name="uname" type="text" /> <br/>
<label>CREATE PASSWORD</label> <input name="pass" type="password" />
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Here is the solution I came up with... but what does it do?
#Registercontainer needs to be on the center of the page. Meaning, your fixed with of 1200px is not going to work too well. I took the approach of reducing the size of your from container to give a better look and feel like this:
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
/* ... your other properties here ... */
}
Another note, your <label> needs the for attribute as specified in this article.
Let me know if you have any questions, FYI there are many ways to make this work for you.
#Registercontainer {
max-width: 600px;
min-width: 320px;
width: 100%;
margin: 70px auto;
border: 1px solid;
background-color: aliceblue;
top: 0;
padding: 15px;
}
.Regcontainer h1 {
font-size: 40px;
font-family: 'Helvetica Neue', sans-serif;
color: black;
line-height: 1;
padding-left: 35px;
padding-top: 35px;
color: black;
}
input {
display: inline-block;
margin: 10px;
}
input[type=text] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
box-shadow: #212121;
}
input[type=password] {
padding: 10px;
border: 2px solid #212;
border-radius: 2px;
padding: 5px 10px 5px 10px;
}
input[type=submit] {
background-color: #ff0000;
border: 1px solid #212121;
border-radius: 5px;
color: aliceblue;
font-weight: bold;
}
#back_form {
justify-content: center;
}
<div id="Registercontainer">
<div class="RegForm">
<h1> Register With NackStack</h1>
<div id="back_glob">
<div id="back_form">
<form method="POST">
<label for="fname">FIRST NAME</label>
<input type="text" name="FName" id="fname" />
<br/>
<label for="sname">LAST NAME</label>
<input type="text" name="SNAME" id="sname" />
<br/>
<label for="email">EMAIL ADDRESS</label>
<input id="email" name="email" type="text" />
<br/>
<label for="uname">CREATE YOUR USERNAME</label>
<input name="uname" type="text" id="uname" />
<br/>
<label for="password">CREATE PASSWORD</label>
<input name="pass" type="password" id="password"/>
<br/>
<input type="submit" name="valid" value="REGISTER" />
</form>
</div>
</div>
</div>
Add margin:auto and a fixed width to the parent <div>. Example:
<div id="Registercontainer" style="margin-left:auto;margin-right:auto;width:250px">
Fiddle:
https://jsfiddle.net/mwatz122/g9ay26x3/
#Registercontainer {
text-align: center;
}
Please try this. It might help.
Put your form within a <div> like this:
<div align="center">
<!-- insert code here -->
</div>
Then in the CSS, add
form {
text-align: left;
}