Adjust the radio buttons to appear vertically in extra small screen mode by styling the Bootstrap class '.radio-inline' with CSS

What is the best way to adjust a group of radio buttons, initially laid out horizontally for desktop view, to align vertically for mobile view using solely CSS.

Here is an example:

<div class="row">
<div class="col-md-12">
    <fieldset>
        <legend>- Hello fellow developer, please select a radio button</legend><br>
        <label class="radio-inline">
            <input type="radio" name="optionsRadios" value="1" checked="checked">Option 1
        </label>                
        <label class="radio-inline">
            <input type="radio" name="optionsRadios" value="2">Option 2
        </label>
        <label class="radio-inline">
            <input type="radio" name="optionsRadios" value="3">Option 3
        </label>
        <label class="radio-inline">
            <input type="radio" name="optionsRadios" value="4">Option 4
        </label>
        <label class="radio-inline">
            <input type="radio" name="optionsRadios" value="5">Option 5
        </label>
    </fieldset>
</div>

http://www.bootply.com/zPwSnZjDoQ

To achieve the desired layout using only CSS, you can try something like this:

@media (max-width: 767px) {
  .radio-inline {
    display: block;
    margin-bottom: 10px;
  }
}

Answer №1

To achieve the desired effect using only CSS, simply make adjustments to the bootstrap .radio-inline class directly when the screen size is extra small (xs). By adding display: block to this class, you can customize how it appears on the page.

@media (max-width: 768px){ 
  .radio-inline{
  display: block; 
  }
}

It's worth noting that some developers prefer not to alter styling of framework classes directly. However, personally, I don't see an issue with making minor adjustments as long as they do not impact the core design principles of Bootstrap.

Answer №2

@media (max-width: 479px) {
  .radio-inline {
    display: block;
    padding: 10px 20px; /* custom */
  }
}

It seems like Bootstrap automatically includes a 10px left margin for .radio-inline+.radio-inline. To override this, you'll need to use a more specific selector.

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

Placing an image on a three.js cube using overlay does not function properly

I attempted to superimpose an image onto a cube by utilizing code from GPT chat and Blackbox AI, but in both cases, I encountered a black screen. I saved the code in a file named test.html and tested it on Google Chrome and Opera GX browsers, only to be me ...

CSS regression testing through version control systems and continuous integration

Is there a tool that integrates with CI systems and VCS like Git to automatically assign regression test results to individual commits? Ideally, this tool would provide a concise summary on a main page showing passed/failed numbers for each commit, with th ...

The background image item in C# Outlook Mail does not repeat as expected when used inline

Hey there, I need to set up an email campaign with data in the mail body and a background image. However, I'm running into issues with the background image repeating. When I try to prevent repetition using background-repeat: no-repeat;, the image does ...

Is the web browser stylesheet the dominant CSS style over all others?

Could you clarify whether the web browser style sheet supersedes all other CSS styles, or is that simply a misconception? ...

Scroll automatically when dragging the mouse

My D3 tree creation is causing an issue with the horizontal scroll bar in Firefox 37. When trying to drag select a tree node, the horizontal scroll bar does not work. However, in Chrome, the horizontal scroll works fine during drag selection. <div cl ...

Consolidate radio group in Vuetify platform

I'm having trouble centering the v-radio-group. Here's my current setup: <v-container grid-list-md text-xs-center> <v-form ref="form"> <div v-if="question.question_type == 'YESNO' "> <v-radio-group ...

Problem with Internet Explorer

There seems to be an issue with the center content on this website. In Internet Explorer, a few letters are getting cut off by the sidebar. I've tried adding some extra margin to the right, but it didn't solve the problem. It's happening on ...

Eliminate the hover effect from every element

Is there a method in CSS or Javascript that allows me to eliminate the hover effect on all elements? I am specifically looking for a solution that will disable the hover effect on mobile devices while keeping it intact on desktop. I attempted using pointer ...

Unable to load a different webpage into a DIV using Javascript

Today has been a bit challenging for me. I've been attempting to use JavaScript to load content into a <div>. Here is the JavaScript code I'm working with: function loadXMLDoc(filename) { var xmlhttp; if (window.XMLHttpRequest) { ...

Tips for optimizing HTML5 markup elements to render effectively in Internet Explorer

How can I ensure that HTML5 markup elements such as <header>, <section>, and <footer> are displayed properly in Internet Explorer? I've noticed that when I apply CSS to these elements, the styling doesn't always work as expecte ...

Tips for enhancing the appearance of a dir-paginate

As a newcomer to AngularJS, I'm interested in learning how to apply styling to a pagination box. Below is the code for displaying a rectangular box view: ` <dir-pagination-controls max- size = "10" direction-links = "true" ...

.Net RadioButton object

Having trouble styling my radio button. When I compile and check the code with Firebug, something unusual happens. Code snippet: <asp:RadioButton ID="selType1" GroupName="Type" runat="server" CssClass="radioB" Checked="true" /> Firebug result: & ...

Customize button design with data from API request

I am currently working on a project to showcase the status of multiple servers within a cluster. To achieve this, I have established a status route in my web service that returns 'ok' if the server is functioning correctly and an error message if ...

Adjust the background color of Bootstrap 4 checkboxes

I'm trying to figure out how I can modify the background color of a Bootstrap 4 checkbox in this specific scenario. .custom-control-label::before, .custom-control-label::after { top: .8rem; width: 1.25rem; height: 1.25rem; } <link rel="style ...

What could be causing the issue with my CodePen not displaying properly on my website?

First Attempt: After implementing My code pen on a page, I encountered a blank screen. I then created a separate JS sheet for my sober child theme and tested it with an alert which worked fine. However, when I tried to implement the desired JS code, nothi ...

Verify if a specific image file is present in Wordpress using PHP. If not found, utilize a default banner instead

Can I achieve a setup similar to the Wordpress header/theme, where there is a default image banner that will only be used if the specified image file does not exist? The idea is for the logic to function as follows: if (the specified image file does not e ...

Transforming traditional HTML table layout to modern div structure

We are currently in the process of transitioning old pages from our previous website structure, which used tables, to our new layout based on DIVs. Our website is structured using a PHP include system with separate components for the header, body, and foot ...

Having difficulty with CSS to position a bottom border under the logos at the top right of the page

Can anyone help me with adding a border under my logos positioned at the top right of the page? Prior to including position:absolute; in the div, my two logos were correctly placed under the "Contact Me" section at the top right. However, when I added pos ...

The names in the lists appear with a visible scrollbar, making them easily

I'm having some issues with this dropdown menu. http://jsfiddle.net/vnr0rbuu/2/ The problem arises when using a different mouse or a PC, as the scrollbar appears and my list items don't apply the inline-block style correctly. Any suggestions on ...

Locate an element by filtering and finding two distinct values using the .eq() method

I need help filtering a table row based on the values in two different columns. The idea is to show only the row where one column has "value1" and another column has "value2", while hiding all other rows. If none of the rows meet this condition, then hide ...