I have a group of radio buttons that are organized vertically, stacked. They are on separate lines by use of <br> tag. I want to align them vertically using CSS, left-aligned, 100 pixels from the left. It doesn't seem like it would be that hard, but I haven't got it figured out yet. Here's an illustration I made to clarify the desired result:
+----------------------------------------------------------------+
| |
| |
| |
| |
| * choice 1 |
| * choice 2 is a different length |
| * choice 3 is also long |
| |
| |
| |
| |
| |
+----------------------------------------------------------------+
+----------------------------------------------------------------+
| |
| |
| |
| |
| * choice 1 |
| * choice 2 is a different length |
| * choice 3 is also long |
| |
| |
| |
| |
| |
+----------------------------------------------------------------+
Made with Asciiflow.com
Here is my code:
form {
background-color: #ffffb3;
font-family: Arial, sans-serif;
padding: 10px;
border: 2px solid #000000;
min-width: 600px;
max-width: 690px;
width: 80%;
margin: 0 auto;
min-height: 200px;
}
label {
margin-left: 100px;
postion: absolute;
}
/*input[type="checkbox"]:checked + */
<form method="POST" action="mailto:[email protected]">
<h2>Visitor Survey</h2>
<fieldset>
<label for="myName">Your Name:</label>
<input type="text" name="myName" id="myName">
<br>
<label for="email">Email Address:</label>
<input type="text" name="email" id="email">
<br>
</fieldset>
<p>What is your favorite movie?</p>
<input type="radio" name="movie" id="transformers" value="Transformers!">
<label for="transformers">Transformers!</label>
<br>
<input type="radio" name="movie" id="dark-knight" value="Dark Knight">
<label for="dark-knight">Dark Knight</label>
<br>
<input type="radio" name="movie" id="goodwillhunting" value="Good Will Hunting">
<label for="goodwillhunting">Good Will Hunting</label>
<br>
<br>
<input type="submit" value="Submit Query">
<input type="reset" value="Reset">
</form>
input[type="radio"] + label
(but I need the label to come first), to no avail.So, I have several questions:
Something like this?
radio
button and label
combo using pseudo elements (:after
in this case). No need of <br>
.margin-left
to input[type="radio"]
instead of label
.Using :after
I have created a empty block (display: block;
). This empty block is placed at the end of label
so it pushes the next element to a new line.
Note:
For explanation, I have highlighted the empty block(created by :after
) with a red border. Remove if necessary.
form {
background-color: #ffffb3;
font-family: Arial, sans-serif;
padding: 10px;
border: 2px solid #000000;
min-width: 600px;
max-width: 690px;
width: 80%;
margin: 0 auto;
min-height: 200px;
}
label {
margin-left: 100px;
}
input[type="radio"] {
margin-left: 100px;
}
input[type="radio"] + label {
margin-left: 10px;
}
input[type="radio"] + label:after {
content: '';
display: block;
/* Below code(border: 1px solid red;) is just for illustration, remove if necessary */
border: 1px solid red;
}
/*input[type="checkbox"]:checked + */
<form method="POST" action="mailto:[email protected]">
<h2>Visitor Survey</h2>
<fieldset>
<label for="myName">Your Name:</label>
<input type="text" name="myName" id="myName">
<br>
<label for="email">Email Address:</label>
<input type="text" name="email" id="email">
<br>
</fieldset>
<p>What is your favorite movie?</p>
<input type="radio" name="movie" id="transformers" value="Transformers!">
<label for="transformers">Transformers!</label>
<input type="radio" name="movie" id="dark-knight" value="Dark Knight">
<label for="dark-knight">Dark Knight</label>
<input type="radio" name="movie" id="goodwillhunting" value="Good Will Hunting">
<label for="goodwillhunting">Good Will Hunting</label>
<br>
<br>
<input type="submit" value="Submit Query">
<input type="reset" value="Reset">
</form>