Align the radio buttons vertically

My goal is to align all my buttons vertically, similar to the first question. However, I'm struggling to get the second question to align correctly. Despite trying different methods like using the vertical-align: middle property, nothing seems to be working.

body {
  margin: 0px;
  background-image: linear-gradient(to top, #48c6ef 0%, #6f86d6 100%);
}

#wrapper {
  padding-top: 0px;
  text-align: center;
  margin-top: -1%;
  margin-left: 20%;
  margin-right: 20%;
  background-color: white;
  clear: both;
}

#quiz {
  padding-bottom: 10px;
}

#quiz li {
  list-style-type: none;
}

.question {
  padding-bottom: 10px;
  vertical-align: middle;
}
<div id="wrapper">

  <div id="quiz">


    <form name="quiz" method="post" name="buttons" id="quiz" onsubmit="return false">
      <li>
        <div class="question">1. How many continents are there?</div>
      </li>
      <input id="answer" type="radio" name="group1" value="wrong"> 6<br>
      <input id="answer" type="radio" name="group1" value="wrong"> 8<br>
      <input id="answer" type="radio" name="group1" value="correct"> 7<br>
      <input id="answer" type="radio" name="group1" value="wrong"> 5
      <hr>


      <li>
        <div class="question">2. Where is France located?</div>
      </li>
      <input id="answer" type="radio" name="group2" value="correct"> Europe<br>
      <input id="answer" type="radio" name="group2" value="wrong"> Asia<br>
      <input id="answer" type="radio" name="group2" value="wrong"> Antarctica<br>
      <input id="answer" type="radio" name="group2" value="wrong"> North America
      <hr>
    </form>

  </div>
</div>

Answer №1

By using the combination of text-align: left; and display: inline-block;, your issue was successfully resolved.

body {
  margin: 0px;
  background-image: linear-gradient(to top, #48c6ef 0%, #6f86d6 100%);
}

#wrapper {
  padding-top: 0px;
  text-align: center;
  margin-top: -1%;
  margin-left: 20%;
  margin-right: 20%;
  background-color: white;
  clear: both;
}

#quiz {
  padding-bottom: 10px;
}

#quiz li {
  list-style-type: none;
}

.question {
  padding-bottom: 10px;
  vertical-align: middle;
}

.wrap {
  text-align: left;
  display: inline-block;
}
<div id="wrapper">

  <div id="quiz">


    <form name="quiz" method="post" name="buttons" id="quiz" onsubmit="return false">
      <li>
        <div class="question">1. How many continents are there?</div>
      </li>
      <input id="answer" type="radio" name="group1" value="wrong"> 6<br>
      <input id="answer" type="radio" name="group1" value="wrong"> 8<br>
      <input id="answer" type="radio" name="group1" value="correct"> 7<br>
      <input id="answer" type="radio" name="group1" value="wrong"> 5
      <hr>


      <li>
        <div class="question">2. Where is France located?</div>
      </li>
      <div class="wrap">
        <input id="answer" type="radio" name="group2" value="correct">Europe<br>
        <input id="answer" type="radio" name="group2" value="wrong">Asia<br>
        <input id="answer" type="radio" name="group2" value="wrong">Antarctica<br>
        <input id="answer" type="radio" name="group2" value="wrong">North America
      </div>
      <hr>
    </form>

  </div>
</div>

Answer №2

Excellent work on your code, the elements are already centered in the middle. However, it seems that your CSS styling is not displaying correctly. I recommend using labels for the text and ensuring they are aligned properly as well.

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

Modifying the CSS design of specific columns within a table created using JavaScript

A unique way to showcase JSON data in a table is by utilizing a for loop within a function. This method, however, does not assign an ID or Class to the table. To hide the final three columns of this table using CSS, the following code can be employed (whe ...

CSS uses color parameters in the same way

Apologies, I spent a few years immersed in the world of IT. Now, onto my query: I have a lengthy ".css" file with numerous structures like color: #567567; within it. Is there a way to utilize a construction similar to color: $mycolor or is this not po ...

The visual content I have does not fill up the entire screen, which results in some empty spaces in the layout

Whenever I insert an image, I strive to have it fill the entire space but end up with white gaps. This is my code: <div style="background-image: url('../assets/img/food-with-ingredients.jpg'); -webkit-background-size: cover; -moz-back ...

.css files standing their ground against modifications

Currently, I'm utilizing the WebStorm IDE to work on my React project. My goal is to make modifications to the app.css files in order to update the design. However, each time I attempt to build or run the project, it dismisses all of the changes I&apo ...

What is the best way to restrict the length and number of lines in a textarea based on pixel dimensions?

I am looking to create a textarea where people can select different fonts, such as "sans-serif" and "serif", to type in text. I plan to have buttons labeled "sans-serif" and "serif" that will change the font of the textarea when clicked. However, there ar ...

Several mat-radio-button options chosen within mat-radio-group

`<mat-radio-group [ngClass]="cssForGroup" name="test"> <mat-radio-button *ngFor="let option of options | filter:searchText" class="cssForRow" [value]="option" ...

Increasing the div's size to exceed the dimensions of the screen

My issue pertains to the background image on my website. I have set a background image for the body and centered it horizontally. Each page includes a paragraph below the header, each with a different size, causing scrolling. The problem is that the backgr ...

Random variable without repetition in SASS

I have a unique project where I am tasked with incorporating a list of 5 specific colors into 10 different div elements. The challenge is that each color must be used twice and in a completely random order without any repetition of colors. Although utilizi ...

Ways to align elements horizontally while preventing them from shifting positions

I'm faced with a layout challenge where I need to place 2 components side by side, but I want one component to stay on the right without affecting the orientation of the other component. Example: https://i.stack.imgur.com/T5Ram.png Currently, when I ...

Text enhancement with text-shadow in jQuery and CSS

Before I reached out, I had been searching for a solution. In the process of building my website, I decided to incorporate text-shadow. It seemed straightforward, but turned out to be more complicated than expected. I discovered that IE does not support ...

Ways to update div content following a successful AJAX call

I have a form that utilizes AJAX requests, and when the input fields are not filled correctly and the submit button is clicked, error messages are displayed without refreshing the page. While this functionality works, a problem arises when the form is subm ...

Struggling to incorporate a logo into the navigation bar for an HTML project

I'm a beginner in the world of HTML and CSS, trying my hand at creating a homepage. While I managed to add a logo to the Navigation bar, it seems to have messed up the link for the HOME page. Could this be due to not wrapping the logo in a div or imp ...

Unable to switch the text option

[Fiddle] I'm currently working on a project where I want pairs of buttons to toggle text by matching data attributes. While I can successfully change the text from "Add" to "Remove" on click, I am facing an issue with toggling it back to "Add" on the ...

What is the method for automatically starting another .mp4 video once the first one finishes playing?

I am currently trying to replicate the functionality of a television for a project. The idea is to play a .mp4 file, and once it ends, automatically select and play another .mp4 file. It's like mimicking the TV experience where one episode finishes a ...

Learn how to access an array within an object using JavaScript and an API URL

Trying to fetch data from the swapi API to display film titles using jQuery. Below is the JavaScript code: $(function(){ function promiseTest(){ return $.ajax({ type: 'GET', url: 'https://swapi.co/api/people/', } ...

What could be causing the misalignment of divs with margins?

I'm facing an issue where I can't seem to get two h2 elements with top margin set and placed inside divs floating left to line up properly. Any help would be appreciated. <html> <head></head> <style> h2{ ...

Bootstrap navigation bar collapsing horizontally instead of vertically

My Navbar is collapsing correctly, but when I click the toggle icon after it's collapsed, the items appear in a horizontal row instead of the intended vertical block. I have checked the code on the Bootstrap 5 example page and tried to replicate it, b ...

Easy steps to eliminate background color from text

https://i.sstatic.net/mKmIW.png I have encountered an issue where a white background is covering the background image in my coding project. Despite trying to add background-color: transparent;, I wasn't able to remove the white background. How can I r ...

Incorporating the use of font color in CSS styles and

I am creating a newsletter template using foundation. Within the table, there are 2 <th> elements containing the content "Reservationnumber" and "23425-FF3234". I have multiple instances of these <th>. I want to apply a colored font to them. Wh ...

How can I dynamically adjust the font size of content in a React Material-UI Button when it's unexpectedly

In my web application project, I have created multiple choice questions where each answer is displayed within a single button: <Button fullWidth={true} variant="contained" onClick={(answer) => this.handleAnswer(this.state.answers[0].tex ...