CSS Radio section not stacking on top properly? - html

I'm trying to stack my radio button labels on top of each other with the radio button option on right of the label
Here is my HTML
<p>Instagram destorys the younger generation:</p>
<div class="instagram">
<input type="radio" name="instagram" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="instagram" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="instagram" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br>
<br>
</div>
Here is my CSS
/* the styles for the elements */
body {
font-family: Arial, Helvetica, sans-serif;
width: 900px;
margin: 0 auto;
padding: 0;
box-shadow: 0 10px 20px 10px;
}
h1, h2, h3, p {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
font-weight: bold;
}
a:hover, a:focus {
color: maroon;
}
/* the styles for the header */
header {
border-bottom: 3px solid #FFD300;
background-image: -moz-linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -webkit-linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -o-linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: linear-gradient(
30deg, #000000 0%, #FFD300 30%, white 50%, #00000080 80%, #2641B3 100%);
padding: 15px 30px;
}
header img {
float: left;
}
header h2 {
font-size: 250%;
font-style: italic;
color: steelblue;
text-indent: 45px;
text-shadow: 3px 3px 3px steelblue;
margin-bottom: .3em;
}
header h3 {
font-size: 150%;
text-indent: 45px;
padding-bottom: .75em;
}
/* the styles for the navigation menu */
#nav_menu {
clear: left;
}
#nav_menu ul {
list-style: none;
position: relative;
display: flex;
justify-content: space-evenly;
}
#nav_menu ul li {
float: left;
}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li {
float: none;
}
#nav_menu ul li:hover > ul {
display: block;
}
#nav_menu > ul::after {
content: "";
clear: both;
display: block;
}
#nav_menu ul {
margin: 0;
padding: 0;
}
#nav_menu ul li a {
text-align: center;
display: block;
width: 180px;
padding: .7em 0;
font-weight: bold;
color: white;
}
#nav_menu ul li a.current {
color: black;
}
#nav_menu ul li a:hover, #nav_menu ul li a:focus {
background-color: lightsteelblue;
}
/* the styles for the section */
section {
width: 565px;
float: right;
padding: 25px 30px;
}
section h1 {
font-size: 160%;
margin-bottom: .3em;
}
section p {
font-size: 100%;
margin-bottom: .7em;
}
/*thestyle for the form*/
fieldset {
margin-bottom: .5em;
padding: .5em 1em;
}
fieldset p {
font-size: 90%;
margin-bottom: .5em;
}
legend {
font-weight: bold;
font-size: 90%;
padding-bottom: .9em;
}
label, input, select {
font-size: 90%;
}
label {
display: block;
width: 9em;
text-align: right;
}
input, select {
width: 15em;
margin-left: .5em;
margin-bottom: .7em;
}
input:required, input[required] input:invalid
{
border: 2px solid maroon;
}
input:valid {
border: 1px solid black;
}
input:invalid {
box-shadow: none;
}
br {
clear: both;
}
#buttons input {
width: 10em;
}
textarea {
height: 10em;
width: 40em;
margin-left: 2.5em;
font-family: Arial, Helvetica, sans-serif;
}
#lifestyle label, #food label, #comments label {
float: none;
}
#lifestyle input, #food input {
width: auto;
margin-left: 3em;
}
#buttons input {
width: 10em;
}
#submit {
margin-left: 3em;
}
/* the styles for the sidebar */
aside {
float: left;
width: 245px;
padding: 25px 0 0 30px;
}
aside h2 {
font-size: 130%;
color: maroon;
margin-bottom: 8px;
}
aside ul {
line-height: 1.5;
margin: 0;
padding-left: 16px;
}
aside a:link, aside a:visited {
color: steelblue;
}
aside a:hover, aside a:focus {
color: maroon;
}
/* the styles for the footer */
footer {
clear: both;
padding: 15px 30px;
background-color: steelblue;
}
footer p {
text-align: center;
font-size: 85%;
color: white;
}
.instagram, #agree {
display: inline;
justify-content: flex-start;
text-align: left;
width: 1rem;
}
The full HTML is below
<main>
<section>
<h1>Opinion about Social Media</h1>
<p>Please answer the questions honestly!</p>
<form action="opinion_request.html" method="get" id="opinions_form">
<fieldset>
<legend>Please try to answer every question</legend><br><br>
<label for="name">Full name:</label>
<input type="text" id="name" autofocus required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" required><br><br>
<label for="gender">Gender:</label>
<select id="gender">
<option value="none">Select a Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select><br><br>
<label>How many hrs per day do you use Social Media?:</label>
<select id="age">
<option value="none">Select your choice</option>
<option value="1-2hrsr">1-2hrs</option>
<option value="2-4hrs">2-4hrs</option>
<option value="5hrs+">5hrs+</option>
</select><br><br>
<label for="social">List 2 social medias that you use the most:</label>
<input type="text" id="social" placeholder="Example: Instagram, Twitter, Facebook"><br><br>
<label for="rate">Rate Twitter from 1 to 5:</label>
<input type="range" id="rate"
min="1" max="5" step="1"><br><br>
</fieldset>
<fieldset>
<legend>Survey</legend><br>
Date you first started social media:
<input type="date" id="date"><br><br>
<p>Instagram destorys the younger generation:</p>
<div class="instagram">
<input type="radio" name="instagram" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="instagram" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="instagram" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br>
<br>
</div>
<p>Linkedin is the best networking social media:</p>
<input type="radio" name="link" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="link" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="link" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br><br>
<p>Tiktok is the next big social media:</p>
<input type="radio" name="tiktok" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="tiktok" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="tiktok" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br><br>
<p>Facebook is the most popular social media:</p>
<input type="radio" name="fb" value="agree" id="agree">
<label for="agree">Agree</label>
<input type="radio" name="" value="disagree" id="agree">
<label for="disagree">Disagree</label>
<input type="radio" name="social" value="strongly" id="agree">
<label for="strongly">Strongly Disagree</label><br><br>
</fieldset>
<fieldset><br>
<legend>Comments:</legend>
<p>In 10 years do you think you'll still use social media? Why or why not?</p>
<textarea id="text-area">
</textarea>
</fieldset>
<br>
<fieldset id="buttons">
<legend>Process your information</legend><br>
<input type="submit" id="submit" value="Submit now">
<input type="reset" id="submit" value="start over">
</fieldset>
</form>
</section>
</main>
Here are pics of what it currently looks like and how I want it to look like

You can add some css rules to achieve the desired result. Add the following css rules.
#opinions_form input[type=radio]~label::after {
height: 1px;
width: 100%;
display: block;
content: '';
}
And remove display:block rule in label selector. Change it to following.
label {
width: 9em;
text-align: right;
}
Check this codepen link.
https://codepen.io/aryantw/pen/vYNOWOL

I made couple div around, reason it makes it clean and consistent across the options. important thing is used flex so that it makes the items inline, hope it works for you:
body {
font-family: Arial, Helvetica, sans-serif;
width: 900px;
margin: 0;
padding: 0;
border: 0;
box-shadow: 0 10px 20px 10px;
}
h1,
h2,
h3,
p {
margin: 0;
padding: 0;
}
a {
text-decoration: none;
font-weight: bold;
}
a:hover,
a:focus {
color: maroon;
}
/* the styles for the header */
header {
border-bottom: 3px solid #FFD300;
background-image: -moz-linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -webkit-linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: -o-linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #000000 80%, #2641B3 100%);
background-image: linear-gradient( 30deg, #000000 0%, #FFD300 30%, white 50%, #00000080 80%, #2641B3 100%);
padding: 15px 30px;
}
header img {
float: left;
}
header h2 {
font-size: 250%;
font-style: italic;
color: steelblue;
text-indent: 45px;
text-shadow: 3px 3px 3px steelblue;
margin-bottom: .3em;
}
header h3 {
font-size: 150%;
text-indent: 45px;
padding-bottom: .75em;
}
/* the styles for the navigation menu */
#nav_menu {
clear: left;
}
#nav_menu ul {
list-style: none;
position: relative;
display: flex;
justify-content: space-evenly;
}
#nav_menu ul li {
float: left;
}
#nav_menu ul ul {
display: none;
position: absolute;
top: 100%;
}
#nav_menu ul ul li {
float: none;
}
#nav_menu ul li:hover>ul {
display: block;
}
#nav_menu>ul::after {
content: "";
clear: both;
display: block;
}
#nav_menu ul {
margin: 0;
padding: 0;
}
#nav_menu ul li a {
text-align: center;
display: block;
width: 180px;
padding: .7em 0;
font-weight: bold;
color: white;
}
#nav_menu ul li a.current {
color: black;
}
#nav_menu ul li a:hover,
#nav_menu ul li a:focus {
background-color: lightsteelblue;
}
/* the styles for the section */
section {
width: 565px;
float: right;
padding: 25px 30px;
}
section h1 {
font-size: 160%;
margin-bottom: .3em;
}
section p {
font-size: 100%;
margin-bottom: .7em;
}
/*thestyle for the form*/
fieldset {
margin-bottom: .5em;
padding: .5em 1em;
}
fieldset p {
font-size: 90%;
margin-bottom: .5em;
}
legend {
font-weight: bold;
font-size: 90%;
padding-bottom: .9em;
}
label,
input,
select {
font-size: 90%;
}
label {
display: block;
width: 9em;
text-align: right;
}
select {
width: 15em;
margin-left: .5em;
margin-bottom: .7em;
}
input:required,
input[required] input:invalid {
border: 2px solid maroon;
}
input:valid {
border: 1px solid black;
}
input:invalid {
box-shadow: none;
}
br {
clear: both;
}
#buttons input {
width: 10em;
}
textarea {
height: 10em;
width: 40em;
margin-left: 2.5em;
font-family: Arial, Helvetica, sans-serif;
}
#lifestyle label,
#food label,
#comments label {
float: none;
}
#lifestyle input,
#food input {
width: auto;
margin-left: 3em;
}
#buttons input {
width: 10em;
}
#submit {
margin-left: 3em;
}
/* the styles for the sidebar */
aside {
float: left;
width: 245px;
padding: 25px 0 0 30px;
}
aside h2 {
font-size: 130%;
color: maroon;
margin-bottom: 8px;
}
aside ul {
line-height: 1.5;
margin: 0;
padding-left: 16px;
}
aside a:link,
aside a:visited {
color: steelblue;
}
aside a:hover,
aside a:focus {
color: maroon;
}
/* the styles for the footer */
footer {
clear: both;
padding: 15px 30px;
background-color: steelblue;
}
footer p {
text-align: center;
font-size: 85%;
color: white;
}
.instagram,
.facebook,
.tiktok,
.linkedin {
justify-content: space-between;
text-align: center;
width: auto;
margin-left: 15%;
}
.opinioncolumn {
display: flex;
flex-direction: column;
}
.opinionRow {
display: flex;
}
<main>
<section>
<h1>Opinion about Social Media</h1>
<p>Please answer the questions honestly!</p>
<form action="opinion_request.html" method="get" id="opinions_form">
<fieldset>
<legend>Please try to answer every question</legend><br><br>
<label for="name">Full name:</label>
<input type="text" id="name" autofocus required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" required><br><br>
<label for="gender">Gender:</label>
<select id="gender">
<option value="none">Select a Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select><br><br>
<label>How many hrs per day do you use Social Media?:</label>
<select id="age">
<option value="none">Select your choice</option>
<option value="1-2hrsr">1-2hrs</option>
<option value="2-4hrs">2-4hrs</option>
<option value="5hrs+">5hrs+</option>
</select><br><br>
<label for="social">List 2 social medias that you use the most:</label>
<input type="text" id="social" placeholder="Example: Instagram, Twitter, Facebook"><br><br>
<label for="rate">Rate Twitter from 1 to 5:</label>
<input type="range" id="rate" min="1" max="5" step="1"><br><br>
</fieldset>
<fieldset>
<legend>Survey</legend><br> Date you first started social media:
<input type="date" id="date"><br><br>
<p>Instagram destorys the younger generation:</p>
<div class="instagram">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="instagram" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="instagram" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label><br>
<input type="radio" name="instagram" value="strongly" id="agree">
</div>
</div>
<br>
</div>
<p>Linkedin is the best networking social media:</p>
<div class="linkedin">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="link" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="link" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label>
<input type="radio" name="link" value="strongly" id="agree">
<br><br>
</div>
</div>
<br>
</div>
<p>Tiktok is the next big social media:</p>
<div class="tiktok">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="tiktok" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="tiktok" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label>
<input type="radio" name="tiktok" value="strongly" id="agree">
<br><br>
</div>
</div>
</div>
<p>Facebook is the most popular social media:</p>
<div class="facebook">
<div class="opinioncolumn">
<div class="opinionRow">
<label for="agree">Agree</label>
<input type="radio" name="fb" value="agree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="disagree">Disagree</label>
<input type="radio" name="" value="disagree" id="agree">
</div>
</div>
<div class="opinioncolumn">
<div class="opinionRow">
<label for="strongly">Strongly Disagree</label><br><br>
<input type="radio" name="social" value="strongly" id="agree">
</div>
</div>
</div>
</fieldset>
<fieldset><br>
<legend>Comments:</legend>
<p>In 10 years do you think you'll still use social media? Why or why not?</p>
<textarea id="text-area">
</textarea>
</fieldset>
<br>
<fieldset id="buttons">
<legend>Process your information</legend><br>
<input type="submit" id="submit" value="Submit now">
<input type="reset" id="submit" value="start over">
</fieldset>
</form>
</section>
</main>

Related

ordered list numbers are not aligned to the list

I have two doubts to be cleared.
my ordered list has numbering of 1 2 3 4 5 6 etc but am not able to bring that aligned with the questions this is going outside the box.
I have a solution button for each questions but I don't know how to place it on the side of the questions.
here i have attached the code and the expected output. if possible kindly complete the code and post.
* {
margin: 0;
padding: 0;
}
body {
font-family: sans-serif;
font-size: 15px;
height: 100%;
width: 100%;
background-color: antiquewhite;
}
input[type="radio"] {
margin-right: 10px;
}
p {
line-height: 30px;
padding: 30px;
}
.play{
position: absolute;
top: 150px;
left: 300px;
padding: 10px;
border-radius: 10px;
font-family: sans-serif;
background-color: darkgreen;
color: #fff;
}
form[name=quiz] {
margin-left: 10%;
margin-right: 10%;
}
ol{
padding: 10px;
list-style-position: inside;
}
ol li{
background-color: #fff;
border-radius: 15px;
margin: 10px;
box-shadow: 0px 1.5px 2px 0px rgb(91, 91, 91);
}
<form name="quiz" id="quiz">
<ol>
<li>
<div class="q1">
<p><strong>The value of \(\frac{1}{{{{\log }_4}120}} + \frac{1}{{{{\log }_5}120}} + \frac{1}{{{{\log }_6}120}}\) is</strong><br><br>
<input type="radio" name="question1" value="0">A.0<br>
<input type="radio" name="question1" value="1">B.1<br>
<input type="radio" name="question1" value="24">C.24<br>
<input type="radio" name="question1" value="120">D.120<br>
</p>
</div>
<div>
<button class="play">Play Solution</button>
</div>
</li>
<li>
<div>
<p><strong>For a 3x3 matrix A, |A| = 4 and adj A = \(\left( {\begin{array}{*{20}{c}}1&p&3\\1&3&3\\2&4&4\end{array}} \right)\), then the value of p is</strong><br><br>
<input type="radio" name="question2" value="4">A.4<br>
<input type="radio" name="question2" value="11">B.11<br>
<input type="radio" name="question2" value="5">C.5<br>
<input type="radio" name="question2" value="0">D.0<br>
</p>
</div>
</li>
Your question isn't aligning with the number of your ordered list because you're using a <p> element for it which is set to display: block; by default. Removing the <p> element will fix the problem.
You can use a <table> to structure your answers and the solution buttons.
* {
margin: 0;
padding: 0;
}
body {
font-family: sans-serif;
font-size: 15px;
height: 100%;
width: 100%;
background-color: antiquewhite;
}
form[name=quiz] {
margin-left: 10%;
margin-right: 10%;
}
ol {
padding: 10px;
list-style-position: inside;
}
ol li {
background-color: #fff;
border-radius: 15px;
margin: 10px;
padding: 30px;
box-shadow: 0px 1.5px 2px 0px rgb(91, 91, 91);
}
li table {
width: 100%;
}
li table td {
vertical-align: top;
padding-top: 20px;
}
li table td:first-child {
width: 70%;
}
td p {
padding-bottom: 10px;
}
td button {
width: 100%;
padding: 10px;
margin-bottom: 5px;
border-radius: 10px;
background-color: darkgreen;
color: #fff;
}
<form name="quiz" id="quiz">
<ol>
<li class="q1">
<strong>The value of \(\frac{1}{{{{\log }_4}120}} + \frac{1}{{{{\log }_5}120}} + \frac{1}{{{{\log }_6}120}}\) is</strong>
<table>
<tr>
<td>
<p>
<input type="radio" name="question1" id="question1" value="0">
<label for="question1">A. 0</label>
</p>
<p>
<input type="radio" name="question1" id="question2" value="1">
<label for="question2">B. 1</label>
</p>
<p>
<input type="radio" name="question1" id="question3" value="24">
<label for="question3">C. 24</label>
</p>
<p>
<input type="radio" name="question1" id="question4" value="120">
<label for="question4">D. 120</label>
</p>
</td>
<td>
<button class="play">Play Solution</button>
<button class="play">Text Solution</button>
</td>
</tr>
</table>
</li>
</ol>
</form>

Aligning label with input type text

Good day all. I am currently doing a form in html and css. I tried researching on the internet but somehow the code there is would either cause my textbox to lose its design and look plain or it would be very ugly.
I am trying to align the textbox with the labels so that it would look neat.
I also want to make the submit and reset button align in the center next to each other.
And the radio buttons to make them in a straight line instead of being seperated on 2 lines.
When I removed the code for the class .firstform select, type, I lose my design properties for the textboxes but the buttons managed to be align.
body {
background: url(ewp.jpg);
background-size: cover;
}
.firstform {
order-radius: 5px;
background: green;
padding: 20px;
width: 550px;
margin: auto;
color: #fff;
font-size: 16px;
font-family: verdana;
margin-top: 100px;
opacity: 0.8;
}
.firstform h1 {
text-align: center;
margin: 0;
padding: 0;
}
.firstform input,
select {
width: 50%;
padding: 12px 20px;
margin-left: 16em;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 18px;
background: black;
color: white;
opacity: 0.9;
}
.container {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
margin-left: 24em;
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide browser default radio button */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create custom radio button */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 15px;
width: 15px;
background-color: #eee;
border-radius: 50%;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the radio button is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196f3;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the indicator (dot/circle) when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the indicator (dot/circle) */
.container .checkmark:after {
top: 6px;
left: 6px;
width: 4px;
height: 4px;
border-radius: 50%;
background: white;
}
.buttonHolder {
display: block;
margin: 0 auto;
}
.firstform input[type="submit"]:hover {
background: #45a049;
transparent: 0.6s;
}
.firstform input[type="reset"]:hover {
background: #45a059;
transparent: 0.6s;
}
<div class="firstform">
<h1>Student Registration Form</h1>
<form action="Form1.php" method="post">
<p><label>First Name: <input type="text" name ="fname" placeholder="First Name" maxlength="25"></label></p>
<p><label>Last Name: <input type="text" name="lname" placeholder="Last Name" maxlength="25"></label></p>
<p><label>Age: <input type="number" name= "age" min="0" max="150"></label></p>
<p><label> Date of Birth:<input type="date" name="date"></label></p>
<p>Gender:
<label class="container">
<input type="radio" name="gender" value="Male">Male
<span class="checkmark"></span>
</label>
<label class="container">
<input type="radio" name="gender" value="Female">Female
<span class="checkmark"></span>
</label>
</p>
<p> Nationality:
<label>
<select name="nationality">
<option selected>Malaysia</option>
<option>Bangladesh</option>
<option>India</option>
<option>African Nations</option>
<option>South East Asia nations</option>
<option>others</option>
</select>
</label>
</p>
<p><label>Address:<input type="text" name="address" size="30" /></label></p>
<p><label>Postcode: <input type="number" name="postcode" min="0" maxlength="5" oninput="this.value=this.value.slice(0,this.maxLength)"></label></p>
<p><label>State:
<input name="state" list="state">
<datalist id="state">
<option value="Selangor">
<option value="Kuala Lumpur">
<option value="Kelantan">
<option value="Johor">
<option value="Malacca">
<option value="Perak">
<option value="Pahang">
<option value="Negeri Sembilan">
<option value="Sabah">
<option value="Sarawak">
<option value="Perlis">
<option value="Kedah">
<option value="Terengganu">
<option value="Penang">
</datalist>
</label></p>
<p>
<label>Email:
<input type="email" name="email">
</label>
</p>
<p>
<label> Tel:
<input type="tel" name="tel" placeholder="(###) ###-####" oninput="this.value=this.value.slice(0,this.maxLength)" maxlength="10">
</label>
</p>
<div class="buttonHolder">
<input type="submit" name="Insert">
<input type="reset" name="Clear">
</div>
</form>
</div>
Working fiddle: https://jsfiddle.net/jennifergoncalves/nut5mzgj/10/
body {
background: url(ewp.jpg);
background-size: cover;
}
.firstform {
order-radius: 5px;
background: green;
padding: 20px;
width: 550px;
margin: auto;
color: #fff;
font-size: 16px;
font-family: verdana;
margin-top: 100px;
opacity: 0.8;
}
.firstform h1 {
text-align: center;
margin: 0;
padding: 0;
}
.firstform input,
select {
width: 50%;
padding: 12px 20px;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
font-size: 18px;
background: black;
color: white;
opacity: 0.9;
/* removed margin-left */
}
.container {
display: block;
position: relative;
padding-left: 25px;
margin-bottom: 12px;
margin-left: 24em;
cursor: pointer;
font-size: 12px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide browser default radio button */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create custom radio button */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 15px;
width: 15px;
background-color: #eee;
border-radius: 50%;
}
/* On mouse-over, add a grey background color */
.container:hover input~.checkmark {
background-color: #ccc;
}
/* When the radio button is checked, add a blue background */
.container input:checked~.checkmark {
background-color: #2196f3;
}
/* Create the indicator (the dot/circle - hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the indicator (dot/circle) when checked */
.container input:checked~.checkmark:after {
display: block;
}
/* Style the indicator (dot/circle) */
.container .checkmark:after {
top: 6px;
left: 6px;
width: 4px;
height: 4px;
border-radius: 50%;
background: white;
}
.buttonHolder {
display: block;
margin: 0 auto;
}
.firstform input[type="submit"]:hover {
background: #45a049;
transparent: 0.6s;
}
.firstform input[type="reset"]:hover {
background: #45a059;
transparent: 0.6s;
}
label > span, p > span {
width: 50%;
display: inline-block;
}
<div class="firstform">
<h1>Student Registration Form</h1>
<form action="Form1.php" method="post">
<p><label><span>First Name: </span><input type="text" name ="fname" placeholder="First Name" maxlength="25"></label></p>
<p><label><span>Last Name: </span><input type="text" name="lname" placeholder="Last Name" maxlength="25"></label></p>
<p><label><span>Age: </span><input type="number" name= "age" min="0" max="150"></label></p>
<p><label><span>Date of Birth:</span><input type="date" name="date"></label></p>
<p><span>Gender:</span>
<label class="container">
<input type="radio" name="gender" value="Male">Male
<span class="checkmark"></span>
</label>
<label class="container">
<input type="radio" name="gender" value="Female">Female
<span class="checkmark"></span>
</label>
</p>
<p><label><span>Nationality:</span><select name="nationality">
<option selected>Malaysia</option>
<option>Bangladesh</option>
<option>India</option>
<option>African Nations</option>
<option>South East Asia nations</option>
<option>others</option>
</select>
</label>
</p>
<p><label><span>Address:</span><input type="text" name="address" size="30" /></label></p>
<p><label><span>Postcode: </span><input type="number" name="postcode" min="0" maxlength="5" oninput="this.value=this.value.slice(0,this.maxLength)"></label></p>
<p><label><span>State:</span><input name="state" list="state">
<datalist id="state">
<option value="Selangor">
<option value="Kuala Lumpur">
<option value="Kelantan">
<option value="Johor">
<option value="Malacca">
<option value="Perak">
<option value="Pahang">
<option value="Negeri Sembilan">
<option value="Sabah">
<option value="Sarawak">
<option value="Perlis">
<option value="Kedah">
<option value="Terengganu">
<option value="Penang">
</datalist>
</label></p>
<p>
<label><span>Email:</span><input type="email" name="email">
</label>
</p>
<p>
<label><span>Tel:</span><input type="tel" name="tel" placeholder="(###) ###-####" oninput="this.value=this.value.slice(0,this.maxLength)" maxlength="10">
</label>
</p>
<div class="buttonHolder">
<input type="submit" name="Insert"><input type="reset" name="Clear">
</div>
</form>
</div>
The issues were that you had a margin to the left of the inputs. This was preventing the elements from being inline because it added to the horizontal space needed.
Secondly, your inputs are inside your labels. This is fine practice since you can avoid using for attributes for accessibility. However, you can't target just the label, so I surrounded the actual label text with a span. Now you can just target the actual label text. Setting this to 50% and having the inputs at 50% with display:inline-block on both will solve this issue.
I suggest looking into flexbox for these kind of issues. It gives you the ability to be completely flexible about how you align your elements. Here you can find a good explanation:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
3 issues here, to fix the problem
You have enclosed the <input> inside the <label>. Move it out, close the </label> and then start the <input>
remove the margin-left of the input
give display: inline-block; width: 50%; to the label
So your code looks like this now:
jsfiddle: https://jsfiddle.net/vg3ts1m0/3/
jsfiddle (full screen): https://jsfiddle.net/vg3ts1m0/3/show
I have edited first few items in it. It will give you an idea on how to proceed.
I hope it helps.
I am trying to align the textbox with the labels so that it would look neat.
// Layout will resolve 90% of vertical alignment issues.
// To unify form controls (ex. `<input>`, `<select>`, etc) apply the following
input, select, label {display: inline-block; font: inherit}
I also want to make the submit and reset button align in the center next to each other.
/*
Wrap the buttons in a block element (ex. `<fieldset>`, `<div>`, etc)
and center the block
*/
fieldset {width: fit-content; margin: 0 auto}
<fieldset><input type='reset'><input type='submit'></fieldset>
And the radio buttons to make them in a straight line instead of being seperated on 2 lines.
/*
Dimensions should be adjusted as a square (ex. width:4vw; height:4vh;)
The following styles align everything vertically. Keep the height and
line-height the same.
*/
[type=radio] {height: 5vh; line-height: 5vh; vertical-align: middle}
Intrinsic lengths (vw and vh) are used to make the whole form so that it's responsive (see demo in full page mode.
Demo
* {
margin: 0;
padding: 0;
}
html,
body {
width: 100%;
height: 100%;
font: 700 5vh/1.1 Verdana;
}
body {
overflow-x: hidden;
overflow-y: scroll;
}
form {
width: 100%;
height: 100%;
padding: 0;
margin: 0 auto;
}
fieldset {
padding: 5px;
margin: 1vh auto;
border-radius: 6px;
}
.set1>legend {
margin-bottom: -7px
}
legend {
margin-top: 10px;
}
legend+hr {
width: 30vw;
}
[type=radio] {
width: 4vw;
height: 4vh;
}
input,
select,
label {
display: inline-block;
font: inherit;
margin: 2vh 0 0 0;
height: 6vh;
line-height: 6vh;
vertical-align: middle;
padding: 1px 2px;
border-radius: 4px;
}
#first,
#last {
width: 77vw;
}
#dob {
width: 33vw
}
.set2 label {
min-width: 9vw;
}
.set3 label {
min-width: 10vw;
}
#male {
margin-left: 3vw;
}
label[for=nationality] {
width: 19vw
}
#nationality {
height: 8vh;
line-height 8vh;
}
#address {
width: 71vw;
}
#state {
width: 25vw;
}
#email {
width: 75vw;
}
[type=number],
[type=tel],
[type=date] {
font-family: Consolas;
font-size: 6vh
}
[type='reset'],
[type='submit'] {
width: 15vw;
height: 8vh;
cursor: pointer;
}
[type=submit] {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
margin: 0 0 0 -3px;
padding: 0 0 2px 0;
}
[type=reset] {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
margin: 0 0 0 -3px;
padding: 0 0 2px 0;
}
.set4 {
padding: 4px;
width: fit-content;
margin: 0px auto;
}
hr {
margin-top: 8px;
}
<form id='main'>
<fieldset name='set1' class='set1 set'>
<legend>Student Registration</legend>
<hr>
<fieldset name='set2' class='set2 set'>
<legend>Personal Information</legend>
<label for='first'>First: </label>
<input id='first' name='first' type='text'><br>
<label for='last'>Last: </label>
<input id='last' name='last' type='text'><br>
<label for='dob'>DOB: </label>
<input id='dob' name='dob' type='date'>
<input id='male' name='gender' type='radio' value='male'><label for='male'> Male </label>
<input id='female' name='gender' type='radio' value='female'><label for='female'> Female</label> <br>
<label for='nationality'>Nationality: </label>
<select id='nationality' name='nationality'>
<option value=''>---------------------------</option>
<optgroup label='North America'>
<option value='US'>American</option>
<option value='CA'>Canadian</option>
<option value='MX'>Mexican</option>
</optgroup>
<optgroup label='South America'>
<option value='BR'>Brazilian</option>
<option value='CR'>Costa Rican</option>
<option value='PR'>Peruvian</option>
</optgroup>
<optgroup label='Asia'>
<option value='CN'>Chinese</option>
<option value='JP'>Japanese</option>
<option value='IN'>Indian</option>
</optgroup>
<optgroup label='Europe'>
<option value='GB'>British</option>
<option value='DE'>German</option>
<option value='FI'>Finnish</option>
</optgroup>
<optgroup label='Africa'>
<option value='NG'>Nigerian</option>
<option value='EG'>Egyptian</option>
<option value='ML'>Malian</option>
</optgroup>
<option value='AU'>Australian</option>
</select>
</fieldset>
<hr>
<fieldset name='set3' class='set3 set'>
<legend>Contact Information</legend>
<label for='address'>Address: </label>
<input id='address' name='address' type='text'><br>
<label for='state'>State: </label>
<input id='state' name='state' list='states'>
<datalist id="states">
<option value="California">
<option value="Oregon">
<option value="Washington">
<option value="Nevada">
<option value="Arizona">
</datalist>
<label for='zipcode'>Zip Code: </label>
<input id='zipcode' name='zipcode' type='number' min='85000' max='98999'><br>
<label for='email'>Email: </label>
<input id='email' name='email' type='email'><br>
<label for='tel'>Telephone: </label>
<input id='tel' name='tel' type='tel'>
</fieldset>
<fieldset name='set4' class='set4 set'>
<input type='submit'>
<input type='reset'>
</fieldset>
</fieldset>
</form>

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>

Floating list issue

I am creating a list with 5 star rating. I want to put stars in from of list title but my stars are not showing in front of list title.
.cont {
color: #eee;
margin: 0 auto;
max-width: 350px;
overflow: hidden;
padding: 0;
text-align: center;
width: 100%;
}
hr {
margin: 20px;
border: none;
border-bottom: thin solid rgba(255, 255, 255, .1);
}
div.stars {
width: 270px;
display: inline-block;
float: left;
}
input.star {
display: none;
}
label.star {
color: #444;
float: right;
font-size: 25px;
padding: 5px;
transition: all .2s;
}
input.star:checked ~ label.star:before {
content: '\f005';
color: #FD4;
transition: all .25s;
}
input.star-5:checked ~ label.star:before {
color: #FE7;
text-shadow: 0 0 20px #952;
}
input.star-1:checked ~ label.star:before {
color: #F62;
}
label.star:hover {
transform: rotate(-15deg) scale(1.3);
}
label.star:before {
content: '\f006';
font-family: FontAwesome;
}
/* LIST #3 */
#list3 {
float: left;
}
#list3 ul {
list-style-image: url("../images/arrow.png");
color: #4B4B4B;
font-size: 18px;
margin-left: 25px;
}
#list3 ul li {
line-height: 30px;
}
<div id="list3">
<ul>
<li>Estimated time: 43min</li>
<li>Distance in miles: 14 miles</li>
<li>Review Rating:
<div class="cont">
<div class="stars">
<form action="">
<input class="star star-5" id="star-5-2" type="radio" name="star" />
<label class="star star-5" for="star-5-2"></label>
<input class="star star-4" id="star-4-2" type="radio" name="star" />
<label class="star star-4" for="star-4-2"></label>
<input class="star star-3" id="star-3-2" type="radio" name="star" />
<label class="star star-3" for="star-3-2"></label>
<input class="star star-2" id="star-2-2" type="radio" name="star" />
<label class="star star-2" for="star-2-2"></label>
<input class="star star-1" id="star-1-2" type="radio" name="star" />
<label class="star star-1" for="star-1-2"></label>
</form>
</div>
</div>
</li>
</ul>
</div>
Try this: http://codepen.io/g1un/pen/KgvrwZ
.cont {
color: #eee;
margin: 0 auto;
max-width: 350px;
overflow: hidden;
padding: 0;
text-align: center;
/* width: 100%; */
display: inline-block;
vertical-align: top;
}
div.stars {
/* width: 270px; */
display: inline-block;
/* float: left; */
}
Your main mistake causing appearing of your rating icons below the title is that rating block has display: block; property by default as a div and you didn't change it.
It is also no need in width: 100% that causes element jumping to another row to fit this property.

White space between two inputs in a form

I`m making a form with this code
HTML
<form id="advanced_search" action="" class="clearfix">
<input type="text" id="check_in_date" placeholder="Check In Date">
<input type="text" id="check_out_date" placeholder="Check Out Date">
<input type="text" id="min_price" placeholder="Min. Price">
<input type="text" id="max_price" placeholder="Max. Price">
<input type="text" id="keywords" placeholder="Keywords">
</form>
CSS
#advanced_search {display: none;}
#advanced_search input
{
width: 30%;
height: 100px;
background: #cbe0f4;
padding-left: 10%;
padding-right: 10%;
border: none;
text-transform: uppercase;
font: 20px 'Lato', sans-serif;
}
input:focus {outline: 0}
input::-webkit-input-placeholder{
color: #95badf;
}
#advanced_search input:last-of-type {
width: 100%
}
#max_price,
#check_out_date {
float: right;
}
#advanced_search
#check_out_date {
background: #cbe0f4 url(img/calendar_icon.png) no-repeat;
background-position: 80% 50%;
}
#advanced_search #check_in_date {
background: #cbe0f4 url(img/calendar_icon.png) no-repeat;
background-position: 80% 50%;
}
But in Google Chrome it have a white line like this between two inputs
What should I do to fix this problem? Thanks
http://2.firepic.org/2/images/2015-11/09/a7knga1law0v.png
The line is caused by the white space between the elements:
<input type="text" id="check_in_date" placeholder="Check In Date"> //white space is here
<input type="text" id="check_out_date" placeholder="Check Out Date">
You can remove it with this style:
#advanced_search input {
float: left;
}
Fiddle
Or if you hate floats you can set a font size 0 on the container div, and display them inline block:
#advanced_search {
font-size: 0;
}
#advanced_search input {
width: 30%;
height: 100px;
background: #cbe0f4;
padding-left: 10%;
padding-right: 10%;
border: none;
text-transform: uppercase;
font: 20px'Lato', sans-serif;
display: inline-block;
}
input:focus {
outline: 0
}
input::-webkit-input-placeholder {
color: #95badf;
}
#advanced_search input:last-of-type {
width: 100%
}
#advanced_search #check_out_date {
background: #cbe0f4 url(img/calendar_icon.png) no-repeat;
background-position: 80% 50%;
}
#advanced_search #check_in_date {
background: #cbe0f4 url(img/calendar_icon.png) no-repeat;
background-position: 80% 50%;
}
<form id="advanced_search" action="" class="clearfix">
<input type="text" id="check_in_date" placeholder="Check In Date">
<input type="text" id="check_out_date" placeholder="Check Out Date">
<input type="text" id="min_price" placeholder="Min. Price">
<input type="text" id="max_price" placeholder="Max. Price">
<input type="text" id="keywords" placeholder="Keywords">
</form>