Struggling to align radio buttons correctly within the form. The goal is to have them match the alignment of the other text boxes in the form

I have been struggling with aligning radio buttons to match the alignment of the form's text boxes.

I've experimented with various solutions recommended on this site, as well as others and YouTube. However, the most helpful resource I found was:

How to Align Form Elements

html {background-color: off #f3f3f3;}
        fieldset {background-color: rgb(181, 221, 230); width: 700px;}

        #submit {width: 100px; margin-left: 300px; margin-bottom: 20px;}

        #comments {margin-top: 0.8rem; height: 100px;}

        label {display: inline-block; text-align: right; width: 150px; margin: 0.8rem;}

        input[type="radio"] {margin-left: 190px;}

        .required-field::after {content: "*"; color: red;}

        .select {text-align: justify; margin-left: 0px;}
<!DOCTYPE html>
        <html lang="en">
        <head>
            <meta charset="UTF-8">

            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <link rel="stylesheet" href="style.css"/>
            <title>Car Race Signup Sheet</title>
        </head>
        <body>
            <h1>Car Race Signup Sheet</h1>
            <p>Note: MANDATORY FIELD = *</p>
            <form>
                <fieldset>
                    <div class="required-field">
                        <label for="selectevent">* Select Event</label>
                        <input type="radio" id="Stock" name="* Select Event" value="Stock">
                            <label for="Stock">Stock</label><br>
                        <input type="radio" id="Modified" name="* Select Event" value="Modified">
                            <label for="Modified">Modified</label><br>
                        <label for="lastname">*Last Name</label>
                            <input type="text" name="lastname"><br>
                    <!-- more form elements here -->
                </fieldset>
            </form>
        </body>
        </html>
    

Answer №1

If I were you, I would consider restructuring it.

Here is a starting point:

html {
  background-color: off #f3f3f3;
}

fieldset {
  background-color: rgb(181, 221, 230);
  width: 700px;
}

#submit {
  width: 100px;
  margin-left: 300px;
  margin-bottom: 20px;
}

#comments {
  margin-top: 0.8rem;
  height: 100px;
}

label {
  display: inline-block;
  width: auto;
  margin: 0.8rem;
}

input[type="radio"] {
  margin-left: 100px;
}

.required-field {
  display: flex;
  flex-direction: column;
}

.required-field::after {
  content: "*";
  color: red;
}

.select {
  text-align: justify;
  margin-left: 0px;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css" />
  <title>Car Race Signup Sheet</title>
</head>

<body>
  <h1>Car Race Signup Sheet</h1>
  <p>Note: MANDATORY FIELD = *</p>
  <form>
    <fieldset>
      <div class="required-field">
        <label for="selectevent">* Select Event</label>
        <!-- <div class="select"> -->
        <div>
          <input type="radio" id="Stock" name="* Select Event" value="Stock">
          <label for="Stock">Stock</label>
        </div>
        <div>
          <input type="radio" id="Modified" name="* Select Event" value="Modified">
          <label for="Modified">Modified</label>
        </div>
        <div>
          <label for="lastname">*Last Name</label>
          <input type="text" name="lastname"><br>
        </div>
        <div>
          <label for="firstname">*First Name</label>
          <input type="text" name="firstname"><br>
        </div>
        ... and more
    </fieldset>
  </form>
</body>

</html>

The current structure seems somewhat outdated. It may be worth exploring modern techniques like flexbox for this layout. You can find more information about flexbox here.

Answer №2

<form>
    <fieldset>  
        <div class="required-field">
        <label for="selectevent">* Select Event</label>
        <input type="radio" id="Stock" name="* Select Event"
        value="Stock">
        <label for="Stock">Stock</label><br>
        <label></label>
        <input type="radio" id="Modified" name="* Select Event" value="Modified">
        <label for="Modified">Modified</label><br>
        <label for="lastname">*Last Name</label>
        <input type="text" name="lastname"><br>
        <label for="firstname">*First Name</label>
        <input type="text" name="firstname"><br>
        <label for="address">*Address</label>
        <input type="text" name="address"><br>
        <label for="city">*City</label>
        <input type="text" name="city"><br>
        <label for="Province">*Province</label>
        <select name="Province">
            <option value="---">---</option>
            <option value="AB">AB</option>
            <option value="BC">BC</option>
        </select><br>    
        <label for="postalcode">*Postal Code/Zip Code</label>
        <input type="text" name="postalcode"><br>
        <label for="country">*Country</label>
        <input type="text" name="country"><br>
        <label for="email">*Email</label>
        <input type="email" name="email"><br> 
        <label for="dateofbirth">*Date of Birth</label>    
        <input type="date" name="dateofbirth"><br>

        <label for="gender">* Gender</label>
        <input type="radio" id="Male" name="* Gender"
        value="Male">
        <label for="Male">Male</label><br>
        <label></label>
        <input type="radio" id="Female" name="* Gender"
        value="Female">
        <label for="Female">Female</label><br>
        <label></label>
        <input type="radio" id="Other" name="* Gender"
        value="Other">
        <label for="Other">Other</label><br>

        <label for="carmake">*Car Make</label>
        <input type="text" name="carmake"><br>
        <label for="comments">Comments</label>
        <input type="comments" name="comments" id="comments"><br>
        <label for="agree">*I agree to the waiver</label>
        <input type="checkbox" name="checkbox">
        <label for="yes">Yes</label><br>
        <input type="submit" name="Submit" id="submit">   
    </fieldset>
</form>

and remove

<pre>input[type="radio"] {margin-left: 190px;} 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is causing the lack of response in the select box on Mac Chrome when I try to click on it?

Similar Question: JQuery function doesn't work on Chrome on Mac, but works on Chrome on Win 7 and all other browsers I am encountering an issue with a select-option list <div class="social-option"> <select name="hex_theme_options[soc ...

Tips for ensuring a flexbox stays within the bounds of its container and doesn't exceed the available space

I am in the process of developing a modal that needs to be centered on my page and expand organically, but only up to a specific width and height limit. Using flexbox, I have successfully centered this modal (.modal) on the page. Within the modal, there ...

What is the best way to remove the background from a button that uses -moz

After adding the select component to my page, I noticed a problem with the select button in Firefox. In Chrome, the arrow down button looks normal, like this, but in Firefox it appears differently, as shown in this image. How can I remove the background ...

Navigating through pages can result in Ruby Locales becoming misplaced

I am encountering an issue with my website where different pages are meant to be shown for different URLs (locales). The problem arises when I navigate from one page to the next, as it defaults back to the default URL instead of staying on the specific sit ...

Using Jquery to determine if a div is empty, excluding any content before or after it

I'm looking to use JQuery to determine if a Div is empty without taking into account any content added before or after it. When checking for emptiness, I want to ignore anything placed before or after the div. $(function(){ if($('#content&ap ...

What is the process for transferring data (BLOB datatype) to a different table?

I need assistance with transferring data from one blob to another table in the same data type blob. However, I encountered an error message regarding SQL syntax: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv ...

Is it possible to consolidate three footer widget areas into just one for WordPress?

I'm currently using the Retailer theme for my WooCommerce shop, which has 3 footer widget placeholders set up in a grid layout. However, I want to consolidate these into just one widget that spans the width of the entire main container. I managed to ...

Switching between different CSS files based on the URL using jQuery or another method

Is it feasible to apply specific styles based on the ID or load various CSS files depending on the URL you are visiting? For example: <script> if(location.href == 'http://jpftest2.tumblr.com/about'){ document.write('<style type= ...

Utilizing ionic-scroll for seamless movement and scrolling of a canvas element

I have set up a canvas element with a large image and I want to enable dragging using ionic-scroll. Following the provided example: <ion-scroll zooming="true" direction="xy" style="width: 500px; height: 500px"> <div style="width: 5000px; h ...

template not being loaded with form

My Django form is not showing up when I try to implement it. Even after checking the browser's inspector, there is no sign of it being loaded at all. If more information is required, please let me know. Here is the project structure: /beerad url ...

Converting from CAPS lock to using the capitalize property in CSS

Is there a way to transform a sentence that is all in CAPs lock without changing it? This sentence is part of a paragraph, and I am looking for a CSS solution (maybe with a little Jquery) that works reliably across most devices! I have come across similar ...

navigating through a specific section of a data chart

I need the first column of a table to stay fixed while the rest of the columns scroll horizontally. Here's the code I have: <div id="outerDiv"> <div id="innerDIv"> <table> <tr><td>1</td><t ...

Errors persist with PHP form submission despite all fields being filled out

Snippet of PHP code for form validation: <html> <head> </head> <body bgcolor="000033" text="navy"> <?php $nume=""; $email=""; $subiect=""; if (!$nume || !$email || !$subiect) { ?> <h4 style="color:gray" align="center"> ...

Switch the displayed image(s) based on the radio button selection made by the user

I need help implementing a feature on my website where users can change an image by selecting radio buttons. For example, there are three options: 1) Fox 2) Cat 3) Dog When the user chooses "Fox," I want an image of a fox to be displayed. If they then sw ...

Tips for properly formatting a fixed table header

I'm currently facing an issue with the sticky header style in my data table. I have created a simple Angular component along with a specific directive: sticky.directive.ts @Directive({ selector: '[sticky]' }) export class StickyDirecti ...

Disallowing selection on input text field

I am seeking to disable selection on an input field while still allowing for focusing, with the following criteria: Preventing selection via mouse Preventing selection via keyboard (including Ctrl+A, shift+arrows) Permitting focus on the field using both ...

Most effective method for displaying 100 images on a single page?

I have a webpage on my site that displays 100 images, but loading them one at a time makes it look unattractive. Is there a way to make it more elegant and visually appealing? ...

The stunning fade effect of Magnific Popup enhances the visual appeal of the inline gallery

I'm currently using magnific popup for an inline gallery, but I'm not seeing any effects. I would like to have a fade effect when opening/closing the popup. Can someone assist me with achieving this? https://jsfiddle.net/gbp31r8n/3/ [Check o ...

Create automatic transcripts for videos, including subtitles and captions

Are there any tools or plugins available that can automatically create a transcript of a video for website playback? For example, generating captions and subtitles in the English language. ...

Is there a way to customize the background color of Material-UI MenuItem when hovering over it through AutoComplete props?

AutoComplete utilizes the Menu component to display MenuItems as demonstrated in the documentation on those respective pages. I am looking to modify the backgroundColor of a MenuItem when it is hovered over. While I have been successful in changing the co ...