Is there a way to arrange the components of my form so that the questions are positioned on the left side and the choices are displayed on the right

As I am creating a form, my goal is to align the information within it in a way that places the questions on the left side and the options on the right.

I have experimented with utilizing IDs, centering them, and adjusting their positioning from left to right.

#wholeform {
  background-color: white;
  display: inline-block;
  text-align: center;
  vertical-align: top;
  line-height: 2.0;
  border-radius: 7px;

}
#title {
   max-width: 400px;
  margin: 20px;
    text-align: center;
}
#survey-form {
  text-align: center
}
<div id="wholeform">
<p id="description">Let us know how we can improve freeCodeCamp<p>

  <form id="survey-form">
    * Name: <input type="text" name="fullname"><br>
  * Email: <input type="text" name="email"><br>
    * Age: <input type="text" name="age"><br>
    Which option best describes your current role?<select name="status">
  <option value="student">Student</option>
  <option value="full time job">Full Time Job</option>
  <option value="full time learner">Full Time Learner</option>
  <option value="Prefer not to say">Prefer not to say</option>
   <option value="Other">Other</option>
</select><br>
    * How likely is that you would recommend freeCodeCamp to a friend?<br>
    <input type="radio"> Definitely<br>
    <input type="radio"> Maybe</br>
    <input type="radio">Not sure</br>
    What do you like most in FCC:<select name="options">
   <option value="challenges">Challenges</option>
    <option value="projects">Projects</option>
    <option value="community">Community</option>
    <option value="open source">Open Source</option></select></br>
    Things that should be improved in the future(Check all that apply)<input type="checkbox" name="front-end" value="Front-end Projects"> Front-end Projects</br>
  <input type="checkbox" name="Back-end Projects" value="Back-end Projects" checked> Back-end Projects</br>
     <input type="checkbox" name="Data Visualization" value="Data Visualization" checked> Data Visualization</br>
     <input type="checkbox" name="Challenges" value="Challenges" checked> Challenges</br>
     <input type="checkbox" name="Open Source Community" value="Open Source Community" checked> Open Source Community</br>
     <input type="checkbox" name="Gitter help rooms" value="Gitter help rooms" checked> Gitter help rooms</br>
     <input type="checkbox" name="Videos" value="Videos" checked> Videos</br>
     <input type="checkbox" name="City Meetups" value="City Meetups" checked> City Meetups</br>
     <input type="checkbox" name="Wiki" value="Wiki" checked> Wiki</br>
     <input type="checkbox" name="Forum" value="Forum" checked> Forum</br>
     <input type="checkbox" name="Additional Courses" value="Additional Courses" checked> Additional Courses</br>
   Any Comments or Suggestions?<name="comments" id="comments">
Enter your comment here...
</textarea><br>
    <input type="submit">
    </form>
    </div>

Result expected - Questions aligned left, Options aligned right

Answer №1

Here is a snippet to help you create a layout with questions on one side and answers on the other. Take a look and let me know if this meets your needs.

#wholeform {
  background-color: white;
  display: inline-block;
  border-radius: 7px;
  margin: 50px;
}

.form-group {
  margin-bottom: 1rem;
}

.row {
  display: -ms-flexbox;
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

.col {
  position: relative;
  width: 100%;
  padding-right: 15px;
  padding-left: 15px;
}

.col-sm-5 {
  flex: 0 0 41.666667%;
  max-width: 41.666667%;
}

.col-sm-7 {
  flex: 0 0 58.333333%;
  max-width: 58.333333%;
}

#title {
  max-width: 400px;
  margin: 20px;
  text-align: center;
}

#survey-form {}

<div id="wholeform">
  <p id="description">Let us know how we can improve freeCodeCamp
    <p>

      <form id="survey-form">
        <div class="form-group row">
          <label for="staticEmail" class="col-sm-5 col-form-label">* Name</label>
          <div class="col-sm-7">
            <input type="text" class="form-control-plaintext" id="staticName" value="">
          </div>
        </div>
        <div class="form-group row">
          <label for="staticEmail" class="col-sm-5 col-form-label">* Email</label>
          <div class="col-sm-7">
            <input type="text" class="form-control-plaintext" id="staticEmail" value="[email protected]">
          </div>
        </div>
        <div class="form-group row">
          <label for="staticAge" class="col-sm-5 col-form-label">* Age</label>
          <div class="col-sm-7">
            <input type="text" class="form-control-plaintext" id="staticAge" value="">
          </div>
        </div>
        <div class="form-group row">
          <label for="staticSelect" class="col-sm-5 col-form-label">* Which option best describes your current role?</label>
          <div class="col-sm-7">
            <select id="staticSelect" class="form-control" name="status">
              <option value="student">Student</option>
              <option value="full time job">Full Time Job</option>
              <option value="full time learner">Full Time Learner</option>
              <option value="Prefer not to say">Prefer not to say</option>
              <option value="Other">Other</option>
            </select>
          </div>
        </div>
        <div class="form-group row">
          <label for="staticSelect2" class="col-sm-5 col-form-label">* How likely is that you would recommend freeCodeCamp to a friend?</label>
          <div class="col-sm-7">
            <select id="staticSelect2" class="form-control" name="status">
              <option value="student">Student</option>
              <option value="full time job">Full Time Job</option>
              <option value="full time learner">Full Time Learner</option>
              <option value="Prefer not to say">Prefer not to say</option>
              <option value="Other">Other</option>
            </select>
          </div>
        </div>
        <div class="form-group row">
          <legend class="col-form-label col-sm-5 pt-0">Radios</legend>
          <div class="col-sm-5">
            <div class="form-check">
              <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
              <label class="form-check-label" for="gridRadios1">
            First radio
          </label>
            </div>
            <div class="form-check">
              <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios2" value="option2">
              <label class="form-check-label" for="gridRadios2">
            Second radio
          </label>
            </div>
            <div class="form-check disabled">
              <input class="form-check-input" type="radio" name="gridRadios" id="gridRadios3" value="option3" disabled>
              <label class="form-check-label" for="gridRadios3">
            Third disabled radio
          </label>
            </div>
          </div>
        </div>
      </form>
</div>

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

Tips on updating the highlighted color of the item currently selected in NavBarDropdown using react-bootstrap

I've been utilizing the react-bootstrap NavDropDown component from this source. Although I initially set it up correctly, I'm struggling to customize the background color of the navdropdow-items when they are in their normal or active (selected) ...

Executing a JavaScript function when a column in a Fusion Chart is clicked

I have two div elements in HTML and I would like to have div2 load when div1 is clicked. Additionally, whenever div2 loads, a back button should also appear to return to div1. Is there a way to achieve this using HTML? <td background="images/bgTd.gif ...

Storing additional data from extra text boxes into your database can be achieved using AJAX or PHP. Would you

A dynamic text box has been created using Jquery/JavaScript, allowing users to click on an "Add More" button to add additional input boxes for entering data. However, a challenge arises when attempting to store this user-generated data in a database. Assi ...

Update the page using Ajax without relying on jQuery

I want to implement automatic page updates without the need for a refresh using Ajax. However, most resources I've come across suggest using jQuery and PHP, which are areas of coding I am not very familiar with. My goal is to integrate Ajax into my HT ...

Appear and disappear div

I am seeking to achieve a specific goal: I want to fade in a div with text after a certain number of seconds, then fade it out. I also want to repeat this process for 4 other divs, ensuring that they do not interfere with each other by appearing while the ...

The vertical scrolling feature seems to be malfunctioning within my angular 10 application

I'm having an issue with the scrollbar not working on this Angular 10 template, even after adding the CSS style overflow: auto; to the main container. Although I've included the overflow property in the main container "cont" as shown in the HTML ...

Managing multiple sets of data in a structured form similar to an array

How Do I Send Form Data as an Array? Take a look at the code snippet below. I'm having trouble setting the index in product_attribute['index must be here']['key'] <tr v-for="index in attributes"> <td class="text-left ...

Bootstrap component malfunctioning and not performing as expected

Currently, I am learning how to use Bootstrap and attempting to replicate the example themes found on their official website. The specific theme I am focusing on is available at this link: https://getbootstrap.com/docs/4.3/examples/pricing/ Unfortunately, ...

When hovering over a single list item, only the top border will be displayed without affecting the

Check out the live link provided below: I am attempting to add a border and later an arrow in the middle on hover in the menu. However, the current code places a border over the entire menu, with individual list items on top of that. #menu ul li { margin ...

What steps do I need to take in order to successfully make a checkbox?

I am attempting to use Angularjs to set a checkbox to true. When saved, it should store an integer value (1 or 0) in my field. Below is the code snippet for the view: <input type="checkbox" ng-model="lis.SMSPromotion" id="SMSPromotion" ng-init="checke ...

Ant Design - Field validation triggers only upon clicking outside of the input field

I have a form with an email field that currently validates the input after each change. How can we modify it to only validate when the user clicks out of the field or submits the form? Below is an example of the form structure: return ( <Form {...l ...

What is the best way to include a background image in an Angular selector?

I'm having trouble setting a background image for an Angular selector. Here's the code I'm using: <app-highway-card [ngStyle]="{'background-image':'url(https://cdn.pixabay.com/photo/2021/09/04/09/32/road-6597404__340.j ...

Submitting the form with a target of _blank will result in the form being submitted on both a

I am currently working on a form that includes both a "Submit" button and a "Preview" button. While the submit button is functioning correctly, I am experiencing an issue with the Preview button. When clicked, it opens up a new page with the preview as in ...

How can I display a button (hyperlink) on a new line using CSS or jQuery?

I am looking to create a new line after the last input of my form. On this new line, I want to add a "remove-link". This is my HTML: <div class="subform dynamic-form"> <label for="id_delivery_set-0-price"> Price: </label> <inp ...

Ways to avoid Parents Click Event from triggering during a Child's (Grandchild's) click event

My parent div has a unique feature where clicking on it reveals one of the child divs, and clicking again toggles the visibility of the child div. Inside this child div, there is a switch toggle that functions as a hidden checkbox. The issue I'm facin ...

What is the best method for placing an element above all other elements on a page, regardless of the layout or styles being used?

I want to create a sticky button that remains fixed on the page regardless of its content and styles. The button should always be displayed on top of other elements, without relying on specific z-index values or pre-existing structures. This solution must ...

What is the process for linking functionality to buttons in Embedded Elixir?

When it comes to rendering templates, I follow this method: <%= for country <- @countries do %> <div> <div>A compilation of countries you have visited</div> <a href="/countries/<%= String.downcase(country) %& ...

Unable to select image inside linked container

I'm attempting to display a dropdown menu when the user clicks on the gear-img div using jQuery. However, because it's wrapped inside an a tag, clicking redirects me to a URL. I also want the entire div to be clickable. Any suggestions for a solu ...

Modifying the position of an image in Flask

I am trying to center an image on my webpage and have attempted the following code: <image height="300px" width="300px" src="{{url_for('static',filename = 'img/Rasd.jpeg')}}" > Visit this webpage fo ...

What is the best way to make a selected link stand out with a highlight?

I'm having an issue with the code below that is supposed to keep the selected link highlighted, but it only flashes the green color on click. Can someone help me figure out what's going wrong here? #sidebarContent a:active{ background-colo ...