The fields in the row of the Rails form_tag are overly spacious

My login form in Rails 4 with Bootstrap 3 is giving me trouble. It doesn't format well on any device, especially smaller screens where it becomes unusable. I suspect the huge right margin of the rows is to blame, but I can't figure out the root cause.

The form has become needlessly complex in my attempt to make it usable. Once I resolve this issue, I plan to simplify it.

I'm trying to improve my HTML and CSS skills, and I use Firebug for troubleshooting. Any advice on how to handle similar issues in the future would be greatly appreciated.

Here's a view of the form as it should appear:

This shows the div containing the rows:

View of the rows, with the problematic right margin:

Rails view of the form:

<div class="col-md-6">
  <h1>Log in</h1>
  <%= form_tag sessions_path do %>
      <div class="col-md-6">
        <div class="field align_right">
          <%= label_tag :logon %>
          <%= text_field_tag :logon %>
        </div>
        <div class="break_line"></div>
        <div class="field align_right">
          <%= label_tag :password %>
          <%= password_field_tag :password %>
        </div>
        <div class="break_line"></div>
        <div class="field align_right">
          <%= label_tag :remember_me %>
          <%= check_box_tag :remember_me, 1, true %>
        </div>
        <div class="break_line"></div>
        <div class="field align_right">
          <%= label_tag :change_password %>
          <%= check_box_tag :change_password, nil, false %>
        </div>
        <div class="break_line"></div>
        <div class="field align_right never" id="new_password_div">
          <%= label_tag :new_password %>
          <%= password_field_tag :new_password %>
        </div>
        <div class="break_line"></div>
        <div class="field align_right never" id="password_confirmation_div">
          <%= label_tag :confirmation %>
          <%= password_field_tag :password_confirmation %>
        </div>
        <div class="break_line"></div>
        <div class="actions"><%= submit_tag "Log in" %></div>
      </div>
  <% end %>
</div>

HTML representation of the form:

<form method="post" action="/sessions" accept-charset="UTF-8"><div style="margin:0;padding:0;display:inline"><input type="hidden" value="✓" name="utf8"><input type="hidden" value="...=" name="authenticity_token"></div>
      <div class="col-md-6">
        <div class="field align_right">
          <label for="logon">Logon</label>
          <input type="text" name="logon" id="logon" style="background-image: url(&quot;...&quot;); background-repeat: no-repeat; background-attachment: scroll; background-position: right center;">
        </div>
        <div class="break_line"></div>
        <div class="field align_right">
          <label for="password">Password</label>
          <input type="password" name="password" id="password" style="background-image: url(&quot;...&quot;); background-repeat: no-repeat; background-attachment: scroll; background-position: right center;">
        </div>
        <div class="break_line"></div>
        <div class="field align_right">
          <label for="remember_me">Remember me</label>
          <input type="checkbox" value="1" name="remember_me" id="remember_me" checked="checked">
        </div>
        <div class="break_line"></div>
        <div class="field align_right">
          <label for="change_password">Change password</labe...

Answer №1

The Bootstrap 3 form and field classes you are using are not correct.

If you want to create a horizontal form similar to what you're trying to achieve, I recommend looking at the code sample provided in the Bootstrap documentation for horizontal forms.

Answer №2

After much searching, I discovered that there was a margin-right override causing the issue. It just goes to show that sometimes you have to rely on debuggers to find these elusive bugs. Appreciate your assistance!

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

Should I use Sqlite or Mysql for this project?

I'm in the process of developing an internet-based operating system and I am planning to utilize a database along with persistence.js to store installed apps. Can anyone recommend the optimal database for this purpose? ...

"Creating a new element caused the inline-block display to malfunction

Can someone explain why the createElement function is not maintaining inline-block whitespace between elements? Example problem First rectangle shows normal html string concatenation: var htmlString = '<div class='inline-block'...>&l ...

Concealing the rear navigation button within the material carousel

I have a material css carousel, and I am trying to hide the back button on the first slide. I attempted to use the code below from a previous post The following code snippet prevents the user from looping through the carousel indefinitely. Stop looping i ...

The issue of 'position: fixed' not properly functioning within the Materialize CSS modal

My goal is to have the header of the Modal stay fixed while scrolling, but for some reason, the option position:fixed; is not working. I am currently using Materialize CSS to build the modal and surprisingly, position:sticky; is working. $(document).rea ...

What could be causing the issue with Hindi text not displaying properly on Safari?

I'm having trouble with displaying Hindi text on my website. I tried pasting the text in a new file and it worked, so why is it not loading correctly in this case? The Hindi script is within the second span with the class word w2. "use strict"; le ...

The jQuery selectors are not able to identify any dynamically generated HTML input elements

After successfully injecting HTML code into the DOM using Ajax, I encountered an issue where my jQuery selector was not working for a specific HTML input element. For example, when attempting to use the following jQuery code: $("input[id*='cb_Compare ...

Obtain the URL found within the href tags

Is there a way to extract the links from the href tags? When I coded it, the entire 'a' tag is showing up... Here's the code: page = urllib2.urlopen('https://www.meetup.com/') soup = BeautifulSoup(page, 'lxml') categor ...

"Enhance Your Video Experience with a Personalized Play Button

Is it possible to customize the play icon for an embedded YouTube video? I came across a post discussing this topic: Can I change the play icon of embedded youtube videos? However, when trying to use something transparent as the new play button, the origin ...

Tips for getting the setInterval function to work with a progress bar even when a tab is not in focus

After browsing through similar questions, I couldn't find the answer I was looking for. As a newbie in programming experimenting with JavaScript Progress Bar, I encountered an issue where the progress bar would pause and the counter wouldn't coun ...

Discover the position of a div relative to another div using ng-drag-drop

I'm currently working on a web application that allows users to create their own identity cards. For this project, I am incorporating the ng-drag-drop library from https://www.npmjs.com/package/ng-drag-drop. The main goal is to obtain the coordinate ...

What could be causing the message "Please right click to enable Adobe Flash Player" to appear on my site?

Recently, every time I try to reload my webpage, a strange message from Adobe Flash Player pops up and quickly disappears, even though I don't have any flash animations on my site. It's puzzling me as to why this is happening. If you'd like ...

Executing AJAX function via a dropdown button

Utilizing a jquery-based dropdown menu from here. The dropdown is added to an existing button triggering an AJAX call that removes a row from the screen. The goal is to execute the AJAX call when any option in the dropdown is selected, instead of using th ...

Once you utilize the register function with react-hook-form, the input text becomes uneditable

Struggling to configure react-fook-form for form validation, I encountered an issue where the text input (specifically the username field) becomes uneditable after using the register function. Despite my efforts, I can't type anything into it. const { ...

Steps to create a zigzagging line connecting two elements

Is it possible to create a wavy line connecting two elements in HTML while making them appear connected because of the line? I want it to look something like this: Take a look at the image here The HTML elements will be structured as follows: <style&g ...

Ways to include "working hours" if statement a particular holiday dates are specified

Trying to update the code for an "if statement" to include specific dates that are official holidays when the business is not operational. The current code works if the day falls on Mon, Tue, Wed, Thu, or Fri and the time is between 09:00 and 15:00 in a 24 ...

Issue with the execution of Javascript code. Edit required

After creating a registration form that allows users to input their information for registration, I encountered an issue where if certain fields were left empty or if the user name was unavailable or the email address was already registered, a warning mess ...

Top tips for optimizing HTML and utilizing div elements

Could you please provide some insights on how to effectively utilize HTML5 in conjunction with div tags? Below is the snippet of my HTML code. I am incorporating the article tag and have segmented sections, which seem to be in order. However, I am also ...

Height problem with the data-reactroot component

On one of my web pages, there is a data-reactroot element with a height of approximately 1906px. However, the surrounding divs and html tags have a height of only 915px. I am trying to figure out how to make all the enclosing elements match the same heigh ...

Tips for customizing the appearance of a specific cell in the first column of a Material UI table

Currently, I am modifying the material ui table found in this codesandbox link. My goal is to adjust the style of the first column's cell in the table when it is selected to match the image provided below. https://i.sstatic.net/DGubN.png It seems lik ...

Switch between displaying the HTML login and register forms by clicking a button

Currently, I am working on a website that requires users to either log in or register if they do not have an account. Below is the code I have developed for the login page: <span href="#" class="button" id="toggle-login">Log in</span> <di ...