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

Having trouble making `overflow: hidden` work correctly when using padding on an element with `height:

Looking for some coding help here. My aim is to create a customized select menu with a sleek animation effect. I initially decided to set the default height to 0 and use overflow: hidden, then switch it to auto when .active class is applied. But, I'm ...

Issue of delayed loading of CSS in Vue.js application

My vue PWA is experiencing slow loading of CSS when using Vue Bootstrap and Buefy. I attempted to use V cloak, but it only hides components milliseconds after the raw HTML is briefly displayed without any CSS applied. I am looking for a method to display ...

Is there a way to instruct the code to select between two variables and align their values?

I have encountered a challenge while working on a unit test. The website I am testing is dynamic, causing the CSS Selector and xpath to frequently change. As a solution, I came up with the idea of using both CSS and xpath to retrieve the same text. Curren ...

clicking on links to different sections of the page does not automatically bring you to the top of

I am working on a design similar to this: http://jsfiddle.net/MTWu5/ The layout consists of a centered page with a sticky header. The header contains menu links that lead to anchors within the page. My issue arises when clicking on these links - I would l ...

The CSS styles are not recognized by the Windows 2003 server

After deploying my webapp, which was created using asp.net, to a testing server (Windows 2003 SP2, IIS6), I encountered an issue. When I accessed the default page, none of the CSS styles were applied. Only plain text or formatting from the .aspx file was v ...

Can CSS be used to create curved dashed lines?

Is it possible to achieve dashed lines similar to the ones highlighted in the images below using only CSS? I have a responsive web page built with Bootstrap, and I need the dashed lines to adjust accordingly when the window width changes. ...

Develop a custom dropdown menu using JavaScript

I've been working on creating a dropdown menu that appears after selecting an option from another dropdown menu. Here's the HTML code I'm using: <br> <select id ="select-container" onchange="addSelect('select-container') ...

Does anyone know if it's feasible to return a value from PHP to an HTML form without relying on JavaScript?

Currently, I am in the process of learning how to create a basic web form. My goal is to develop an HTML web form that sends a number to PHP and then displays the number in another text field without refreshing the page. After doing some research online, ...

What is the best way to adjust the height of a row in a Material UI table using CSS

I've been attempting to establish a row height of 30px for a table (https://material-ui.com/components/tables/), but it seems that the minimum I can set is 53. Why is this restriction in place? How can I adjust the row height to 30px using CSS based ...

Creating a div that becomes fixed at the top of the page after scrolling down a certain distance is a great way to improve user experience on a

I am struggling to create a fixed navigation bar that sticks to the top of the page after scrolling 500px, but without using position: fixed. Despite trying various solutions, none seem to work due to the unique layout of my navigation bar. Strangely enoug ...

Tips on avoiding scrolling when toggling the mobile navigation bar:

While working on a website using HTML, CSS, and BS3, I have created a basic mobile navigation. However, I am facing an issue where I want to disable scrolling of the body when toggling the hamburger button. The problem arises when the menu is toggled on, ...

Display or conceal content based on checkbox status

i am trying to create a system where content is hidden by default and only displayed when a checkbox is checked. The goal is to show the content when the checkbox is checked and hide it when unchecked, so that other content can be shown as well upon checki ...

Identifying sluggish hardware or unresponsive browsers using JavaScript

My site features numerous CSS animations and transitions that run very slowly on specific browsers and older hardware. I want to avoid user-agent sniffing; is there a way to identify browsers or hardware configurations using JavaScript or a JS library, and ...

Modification of a CSS element

The CSS I am working with looks like this: .cls .imageX { float:left; } .cls .imageY { float:right; } It is currently being used on a page in this way: <div class="cls"> <a href="" class="imageX"><img src="left.png"/></a> &l ...

Can someone please explain to me why the Transition effect is not functioning properly for input:checked::before?

Can someone please help me troubleshoot why the transition effect on the input's before element is not working when checked? If I can't solve this issue, I might have to consider alternative solutions. input[type="checkbox"]{ width: 160px ...

Styling targeted div class elements with specific input elements

I have a group of input text elements on my webpage. I am looking to style the div element with the "forms_in_ap" class that contains the #email, #reEmail, #nogInFirstName, and #nogInAccNumber elements specifically for Safari browsers on MAC and IOS device ...

Does the 'span' element negatively impact the vertical alignment of text?

While working on my code, I noticed an issue with vertical alignment when using span tags to change the background of the text based on its content. The problem occurs specifically when viewing the code in the Android Chrome browser. You can view the initi ...

Adjust the size of the font in your Bootstrap Table

I've been utilizing the Bootstrap table feature and it's been fantastic, but I've encountered an issue with changing the font size. I've referred to the example on , however no matter what adjustments I make to the size, it doesn' ...

Techniques for retrieving elements from HTML using jQuery

I'm developing a feature that allows users to add videos to playlists by clicking on a link in a popover. The challenge I'm facing is extracting the video_id and the selected playlist when the user interacts with the popover. Any tips on how to a ...

The upper margin is ineffective

Apologies, I am new to CSS. Here is the HTML code I have: <div class="box-A" >Box A content goes here</div> <div class="box-B" >Box B content goes here</div> I attempted to apply the following CSS to it: .box-A{ background-c ...