Tips on arranging radio buttons in a vertical layout with bootstrap

I am designing an exam system and I am trying to display the options per line. I attempted using display: block;, but it did not produce the desired result. Here is the snippet of my code.

<div class="col-md-10">
    <div class="box box-primary">
        <div class="box-header">
            <h3 class="box-title">Add Question</h3>
        </div>
        <div class="box-body">
            <form method="post" action="{{url('tests')}}">
                @csrf
                <div class="form-group row">
                    <label for="name" class="col-md-2 col-form-label text-md-right">{{ __('Question') }}</label>

                    <div class="col-md-6">
                        <textarea style="border: none"
                            class="form-control{{ $errors->has('question') ? ' is-invalid' : '' }}" name="question"
                            placeholder="Enter Question Here">{{$questions->question}}</textarea>
                        @if ($errors->has('question'))
                        <span class="invalid-feedback" role="alert">
                            <strong>{{ $errors->first('question') }}</strong>
                        </span>
                        @endif

                    </div>
                </div>
                <div style="display: block"><br>
                    <span class="input-group-addon">
                        <input type="radio" name="q" id="option1" style="w">{{$questions->option1}}
                    </span>
                    <span class="input-group-addon">
                        <input type="radio" name="q" id="option1" style="w">{{$questions->option2}}
                    </span><span class="input-group-addon">
                        <input type="radio" name="q" id="option1" style="w">{{$questions->option3}}
                    </span><span class="input-group-addon">
                        <input type="radio" name="q" id="option1" style="w">{{$questions->option4}}
                    </span>
                </div>

Here is the output generated by the aforementioned code

https://i.sstatic.net/SSd16.jpg

Answer №1

When working with Bootstrap, it's best to let the framework handle the layout. According to their documentation:

Bootstrap automatically stacks forms vertically by default due to applying display: block and width: 100% to most form controls.

To ensure your elements stack vertically as intended, make use of elements like div instead of inline elements like span. Bootstrap provides dedicated classes for various form layouts, including horizontal options.

The recommended solution emphasizes semantic markup. It's crucial to prioritize semantics in web development for reasons such as SEO and accessibility. Familiarizing yourself with Bootstrap's documentation can greatly benefit your projects. Here is an example directly from their docs:

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-md-10">
  <div class="box box-primary">
    <div class="box-body">
      <form method="post">
        <h3>Question</h3>
        <div>
          <div class="form-check">
            <input type="radio" class="form-check-input" name="q" id="option1">
            <label class="form-check-label" for="option1">Option 1</label>
          </div>
          <div class="form-check">
            <input type="radio" class="form-check-input" name="q" id="option2">
            <label class="form-check-label" for="option2">Option 2</label>
          </div>
          <div class="form-check">
            <input type="radio" name="q" id="option3" class="form-check-input">
            <label class="form-check-label" for="option3">Option 3</label>
          </div>
          <div class="form-check">
            <input type="radio" name="q" id="option4" class="form-check-input">
            <label class="form-check-label" for="option4">Option 4</label>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>

Additional points to consider:

  • The style attribute style="w" is non-standard and may not function correctly.
  • Each radio button should have a unique ID, as sharing IDs does not align with HTML standards.
  • Utilizing labels for radio inputs, like demonstrated in the code snippet, is advisable for easier styling adjustments and maintenance.

Answer №2

There are often multiple ways to accomplish a task, but for simplicity's sake, consider using a break tag after each span element.

<span></span> <br>
<span></span> <br>

To style with CSS:

div span { display :block }

Answer №3

Could you please enclose them within <p> elements? On another note, utilizing a flexbox with vertical alignment could be beneficial.

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 the method for switching the parent element following the adjustment of the selected child's opacity

I am trying to find a way to use CSS to adjust the parent element's opacity if it contains a child element with a specific class. Currently, I have only been able to achieve this on hover by adding a background color to the parent element's ::aft ...

Show the final element in a list in a new and innovative style

How can I style the last item of a list differently? The issue is with the display of the last item in the list, which may go out of bounds on smaller screens. To ensure proper display, the list item "Argenti" needs to be shown in a single column. To ach ...

Enhance the color scheme of your collapsed or expanded Bootstrap NAV for mobile devices

Currently working on customizing the navbar using Bootstrap. I've been able to style it perfectly for both desktop and mobile devices in its initial state. The issue arises when attempting to style the navbar in its expanded and collapsed states on m ...

The white-space property disrupts the normal width of elements

My initial goal was to stack two elements together side-by-side, both taking the full available height. One element has a fixed width of 200px with an image (70px wide) inside, while the other element should only fit one line of text, clipping any overflow ...

Troubleshooting CSS rendering issues on Chrome browser

Currently in the process of developing a new website based on an old template. The site appears as intended in IE, Safari, and Firefox, but for some reason Chrome is not rendering any of the css. Just to clarify, none of the links are functioning at this ...

What is the best method to restrict the size of a div to match the dimensions of the

In my webpage, I have a menubar (div) that contains bookmarks. However, when too many bookmarks are added, the menu becomes too wide for the page size I prefer (1280, 720) and becomes scrollable, causing some bookmarks to be out of view. My goal is to ens ...

Linking the location of the pop-up to the currently selected text box

I am currently experimenting with setting the top and left values relative to the selected_element (which is active at the time of triggering the popup) in a manner similar to a tooltip. I attempted to use $().position() in combination with jQuery, but it ...

Enhance the appearance of Font Awesome stars by incorporating a hover effect

Is there a straightforward way to make them turn solid yellow when you hover over them? const styles = theme => ({ root: { flexGrow: 1, overflow: 'hidden', padding: theme.spacing(0, 3), }, paper: { maxWidth: 800, mar ...

Unusual occurrence: unexpected positioning issue with iOS and Chrome (Windows)

My website looks perfect on Firefox, but unfortunately, it's not displaying correctly on Safari (iOS) and some Chrome devices. The Menu-Bar, which should be position fixed, is not showing properly. I'm not sure what the issue is. Screenshots: ...

AngularJS Material Design sticky header MD table container

I am looking to create a table container to display records with a unique requirement - when the table reaches the top of the screen, its header should stick in place. Can you provide guidance on how to implement this feature? For reference, please check ...

Phonegap - Retaining text data in a checklist app beyond app shutdown

This is my first time developing an app with Phonegap. I am looking to create a checklist feature where users can input items into an input field. However, I am struggling with figuring out how to save these items so that they remain in the checklist even ...

Does the height of the rendered font adjust based on the length of words in Japanese formatting?

I can't figure out why this strange issue is occurring... It seems that the font "size" (or rather, the height it occupies) changes depending on the length of a word. I tried to reproduce this in English without success, but it consistently happens w ...

Enhance your webpage with dynamic styling using third-party CSS animation

Apologies for any similarity to other questions on this topic. I have searched extensively, but any assistance would be greatly appreciated. I am utilizing a new animation library from Animista to animate specific elements on a test website. Animating ele ...

Different Ways to Customize Button Click Events in Angular 9 Based on Specific Situations

In my Angular 9 web application development, I frequently need to integrate Bootstrap Modals like the example below: <div class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="do ...

Learn how to design a customized loading screen using CSS with Phonegap

Currently working in Android with Phonegap / Cordova, I am faced with the challenge of optimizing page loading time due to numerous DOM objects being created. To address this issue, I am attempting to implement a "Loading..." screen to prevent users from b ...

Customizing the label styles within MUI's Chip component

Incorporating React with MUI's library has been a seamless experience for me. One of the key MUI components I have integrated is the Chip Within this particular Chip, there lies the label attribute, offering the option to showcase a text f ...

Experiencing issues with a malfunctioning Chrome extension? The CaptureVisibleTab feature seems to be failing when using

Whenever I try to use the captureVisibleTab function on a page where I have a div with preserve3d in CSS3, all I see is a blank page. How can I solve this issue? Here is my simple code for capturing the browser screen: chrome.browserAction.onClicked.addL ...

Ways to determine if an element is the initial child

I am currently facing issues while attempting to make my bootstrap carousel dynamic and inject data properly. My aim is to locate the first child of the injected data and apply the "active" class to it. I am utilizing Laravel Blade for rendering my data. B ...

How to effectively eliminate the border of a single cell within a Bootstrap Table

Is there a way to remove the border of a single cell in a bootstrap table without affecting the others? I attempted using an id on that specific cell and adding the following CSS code: #borderless-cell { border: 0; } Unfortunately, this solution doesn&ap ...

What methods can I use to make sure the right side of my React form is properly aligned for a polished appearance?

Trying to create a React component with multiple input field tables, the challenge is aligning the right side of the table correctly. The issue lies in inconsistent alignment of content within the cells leading to disruption in overall layout. Experimente ...