I am trying to horizontal and vertical align these radios/checkboxes also I want the text to be in the left side of them. I tried some things like inline and block but I am fairly beginner and trying to learn.
HERE is the HTML and CSS code for my small project.
.container {
width: 100%;
margin: 3.125rem auto 0 auto;
}
body {
width: 100%;
height: 100%;
margin: 0;
background: #1b1b32;
color: white;
font-family: Consolas, serif;
font-size: 17px;
}
h1,
p {
margin: 20px auto;
text-align: center;
}
form {
margin: 0 auto;
width: 600px;
max-width: 1000px;
min-width: 300px;
padding-bottom: 2em;
padding-top: 1em;
background-blend-mode: color;
}
fieldset {
margin: auto;
padding: 20px;
border-radius: 30px;
border-color: #6b6b8d;
}
label {
display: block;
margin: auto;
text-align: left;
font-size: 16px;
padding-bottom: 10px;
width: 100%;
}
input,
textarea,
select {
box-sizing: border-box;
width: 100%;
min-height: 30px;
margin: 10px 0 0 0;
border-radius: 20px;
border: 1px solid #0a0a23;
background-color: #0a0a23;
color: #ffffff;
text-indent: 5px;
}
.input-radio,
.input-checkbox {
display: block;
margin: auto;
min-height: 1.25rem;
min-width: 1.25rem;
}
.inline-field {
display: inline;
margin-bottom: 10px;
/* I added this after I posted my reply */
vertical-align: middle;
/* Fixes any weird issues in Firefox and IE */
}
.input-textarea {
display: block;
margin-left: auto;
margin-right: auto;
height: 120px;
text-indent: 5px;
}
.submit-button {
display: block;
width: 50%;
margin: 1em auto;
height: 30px;
font-size: 1.1rem;
background-color: #3b3b4f;
border-radius: 20px;
border-color: #6b6b8d;
min-width: 300px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Survey Registration Form</title>
<link rel="stylesheet" href="survey.css">
</head>
<body>
<div class="container">
<h1 id="title">Pepe's Survey Form</h1>
<p id="description">Thank you for taking time to help us improve the platform</p>
<form method="post" action="https://register-demo.freecodecamp.org" id="survey-form">
<fieldset>
<label id="name-label">Enter your first name:<input class="form-control" id="name" type="text"
placeholder="Enter your name" required></label>
<label id="email-label">Email:<input class="form-control" id="email" type="email"
placeholder="Enter your email" required></label>
<label id="number-label">Age(optional)<input class="form-control" id="number" type="number"
placeholder="Enter your age" required min="18"
max="100"></label>
<label for="referrer">How did you hear about us?
<select class="dropdown" id="referrer" name="referrer">
<option disabled selected value>Select current trading style</option>
<option value="1">Intraday Trader</option>
<option value="2">Swing Trader</option>
<option value="3">Investor</option>
</select>
</label>
<div class="inline-field">
<label class="input-radio"><input class="input-radio" id="Yes" name="Yes-No" checked
type="radio" value="Yes">Yes</label>
<label class="input-radio"><input class="input-radio" id="No" name="Yes-No" type="radio"
value="No">No</label>
</div>
<label class="input-checkbox">What would you like to see improved?
<small>(Check all that apply)</small>
<input class="input-checkbox" type="checkbox" value="more-charts">More Charts
<input class="input-checkbox" type="checkbox" value="new-screener">New Screener
<input class="input-checkbox" type="checkbox" value="better-execution">Better execution speed
<input class="input-checkbox" type="checkbox" value="blog-page">Blog Page
</label>
<label>Any comments or suggestions?
<textarea class="input-textarea" id="Textarea" rows="3" cols="30"
placeholder="I want this feature.."></textarea>
</label>
<label>
<input class="submit-button" id="submit" type="submit">
</label>
</fieldset>
</form>
</div>
</body>
</html>
3
Answers
You can create rows using flexbox. Below is an example:
HTML:
CSS:
Click below for more information on how to use flexbox:
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Small improvement proposal to your inital code.
I would advise you to go through the ‘flex’ layout concept (https://css-tricks.com/snippets/css/a-guide-to-flexbox/) to handle your placement more easily 🙂
To ensure alignment in both the horizontal and vertical axes, use a grid to lay out your checkboxes.