inline checkbox is positioned on top of the text rather than next to it

I am attempting to enhance my form by adding checkboxes, but I have encountered an issue with the bootstrap class "checkbox-inline" not working as expected.

Below is the code snippet:

<strong>Styles:</strong>
<%= f.collection_check_boxes :style_ids, Style.all, :id, :name do |cb| %>
  <% cb.label(class: "checkbox-inline input_checkbox") {cb.check_box(class: "checkbox") + cb.text} %>
<% end %>
<br><br>

<strong>Ingredients:</strong>
<%= f.collection_check_boxes :ingredient_ids, Ingredient.all, :id, :name do |cbi| %>
  <% cbi.label(class: "checkbox-inline input_checkbox") {cbi.check_box(class: "checkbox") + cbi.text} %>
<% end %>

The result appears below:

Please assist if possible, as I have been struggling to resolve this issue.

Edit: Upon reviewing the bootstrap documentation, it seems that checkbox-inline and radio-inline are no longer supported. I need to find a way to position the checkboxes next to their respective labels.

Edit 2: A solution has been found! It turns out that removing the following CSS caused my forms to break, but correctly positioned the checkboxes:

input {
  width: 100%;
}

Instead, I applied the following adjustment in the CSS:

.input_checkbox input {
  width: auto !important;
}

--resulting in everything being resolved successfully.

Answer №1

Check out this example featuring Bootstrap 4 and two inline checkboxes. Ruby can easily handle implementing this layout:

<div class="form-check form-check-inline">
  <strong>Options:</strong>

  <label class="form-check-label">
    <input class="form-check-input" type="checkbox" id="inlineCheckbox1" value="2">Option A
  </label>
  <label class="form-check-label">
    <input class="form-check-input" type="checkbox" id="inlineCheckbox2" value="3"> Option B
  </label>
</div>

https://jsfiddle.net/30c40odf/

Answer №2

Test out the code snippet below

<%= f.collection_check_boxes :style_ids, Style.all, :id, :name do |cb| %>
  <%= cb.label  { "#{cb.check_box} #{cb.text}".html_safe } %>
<% end %>

Answer №3

Consider implementing it this way:

<div class="form-group">
  <label>Choose Styles:</label>

      <%= f.collection_check_boxes :selected_styles, Style.all, :id, :chosen_style do |cb| %>
        <% cb.label(class: "checkbox-inline input_checkbox") {cb.check_box(class: "checkbox") + cb.text } %>
      <% end %>
</div>

This approach may be more suitable for your needs.

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

Stylish Interactive Menu Item

Having a fixed navigation at the bottom of my website has presented me with an issue. The hover effect, specifically the background slide, triggers before I even place my mouse over the text. Currently, the background slides up when my mouse enters the .it ...

Step-by-step guide on making a card with one side of the image extending outside the card using CSS

https://i.sstatic.net/Lbc0h.jpg Can you provide instructions on how to achieve the design of this card using css? ...

The functionality of z-index is unreliable when article elements are utilized

Essentially, my goal is to display the <article id="characters"> above the <article id="accordion">. However, despite my efforts, the characters article appears below the accordion article instead of on top or even behind it. Where did I go wr ...

Adjusting the flex columns to be mobile-friendly for various screen sizes, I noticed that the HTML text is spilling over into the adjacent section and the columns appear to

Hi everyone, I've been diligently working on my portfolio website and I'm thrilled that it appears responsive on mobile devices, my Macbook Air, and both of my desktop monitors. However, I've encountered an issue on my Lenovo laptop where th ...

Creating a visually appealing website with Bootstrap 3

Looking to create a unique HTML design using Bootstrap. So far, this is what I've come up with: Plunker Any suggestions or assistance would be greatly appreciated. ...

Scrolling with Buttons in both Right and Left directions

I am working with three divs: left, middle, and right. The middle div will contain content, while the left and right divs are designated for buttons that will scroll the middle div. Specifically, I plan to display lists of pictures in the middle div. If a ...

Incorporating Unique Typography into Your HTML 5 Design

Struggling with implementing Custom Fonts in my HTML 5 project. Despite following various tutorials online, nothing seems to be working for me. Currently utilizing the 960 grid system and housing my CUSTOM FONTS CSS within custom.css. Snippet of my HTML ...

Using jquery ujs to stop a form submission if the field is empty

I'm facing an issue with a form that submits using data-remote => true. The form consists of a single field, a textarea. My goal is to block the submission of the form if the textarea's length is 0 and only permit form submission if the lengt ...

The example in the MUI x-data-grid documentation always seems to fall short of expectations

I followed the code from the material-ui library documentation located at this link: https://mui.com/x/react-data-grid/layout/#flex-layout My aim is to set up a flex layout on my project, I went through the steps mentioned in the documentation but keep ...

Utilize the v-for second argument in VueJS 2 to showcase the index and index+1

For a VueJS 2 project, I am tasked with enhancing the display of the first and second elements in an array by making them stand out from the rest. To achieve this, I am utilizing the v-for syntax to iterate over a child component within a parent component. ...

Are there any methods to personalize the CSS transition?

I have a question about modifying the style of an element with the transition property. It seems that any changes made are done gradually. Is there a way to monitor these style changes, prevent immediate modifications, and instead replace them with a cus ...

Applying the 'overflow: scroll' property creates a scroll bar that remains fixed and cannot be scrolled

Looking to showcase the seating arrangement in a cinema hall. If the seats occupy more than 50% of the page, I want a scroll bar to appear. Attempted using "overflow-scroll" without success. View result image <div class="w-50"> <div ...

How can I use HTML to display a new image next to the base image when I hover over it, showing both images side by side?

Looking for assistance with creating a comic webpage containing 2 cartoons. I want the dialog or mind-thought of each cartoon to appear on the page when a user hovers over them. Anyone able to offer some help with this? ...

Prevent one individual cell in a table from dictating the overall table width

A B A B A X A B In a contained block with a fixed width of 400px, there is a table. When the browser width drops below 421px, the width of the containing block changes to 95%. The cells labeled "A" and "B" contain simple text. There is one cel ...

Using a Jquery selector with either the ID Regex or a repetitive class

There is a collection of similar elements with matching IDs Below are two methods for selecting them using Jquery: Select by ID + Regex (For example, How can I select an element by ID with jQuery using regex?) Add a redundant class to all the elemen ...

Searching Categories with jQuery: Explore Remote Results and Cache System

Seeking to enhance user experience on my website, I have decided to implement the JQuery Category Autocomplete plugin. This will enable users to search through categorized results stored in a separate file at "/search_basic.php" (details of the file's ...

Tips for successfully implementing CSS animations in EmberHere are some helpful ways to

I am currently using the INSPINIA administrative theme and have a question that extends from a previous one regarding installing bootstrap 4 template on an Ember web project. My query is related to getting CSS animations to work properly in Ember. I am t ...

Animating changes in Bootstrap column widths and positions within a row

Currently, I am in the process of developing a web application with React and Bootstrap on the frontend. Within the application, there are multiple Bootstrap columns that have the ability to expand. You can see this functionality demonstrated in the CodeSa ...

Creating a sleek and modern look with Bootstrap 4: The Transparent sticky

Currently in the process of developing a webpage with sticky navigation. The main challenge I am facing is that I have multiple sections with background images and a transparent navigation bar. It's crucial for the logo to be displayed above the navig ...

Is there any specific reason not to use a short HTML/CSS syntax like <div a b c></div>?

When it comes to writing HTML in less standard environments, such as a phonegap app where strict syntax and semantics are not crucial, I have developed a unique approach that works for me. I aim to keep my HTML code short and concise by using the followin ...