Aligning items in CSS Bootstrap: What's the secret?

How can I align label and input tags?

<div class="form-group row">
   <label class="form-control-label" 
    for="field_hasSernum">Has Sernum</label>
   <input type="checkbox" class="form-control" name="hasSernum" id="field_hasSernum"/>
</div>

I am having trouble positioning the "input" tag under the "label" tag.

Answer №1

When referring to Bootstrap's document regarding form layout, they suggest utilizing their grid system for aligning labels and inputs horizontally:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="form-group form-row">
  <label class="form-control-label col-2" for="field_hasSernum">Has Sernum</label>
  <div class="col-10">
    <input type="checkbox" class="form-control" name="hasSernum" id="field_hasSernum"/>
  </div>
</div>

It’s a straightforward process! By leveraging the full potential of Bootstrap's grid system, you can effectively enhance the display on various device sizes and align elements in different ways.

Answer №2

To create a horizontal form, you must include the .col class.

For more information, refer to: https://getbootstrap.com/docs/4.3/components/forms/#horizontal-form

Here is an example snippet:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

<div class="form-group row">
  <div class="col-3">
    <label class="form-control-label" for="field_hasSernum">Has Sernum</label>
  </div>
  <div class="col-9">
    <div class="form-check">
      <input class="form-check-input" type="checkbox" name="hasSernum" id="field_hasSernum">
    </div>
  </div>
</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

Populate HTML form with return values using jQuery AJAX

I am struggling with retrieving values from jQuery/AJAX and displaying them in an HTML form within the index.php file. This is what my index.php looks like: <script type="text/javascript"> $(document).ready(function () { $('#display'). ...

What are some other options besides object-fit?

Currently seeking a replacement for the css object-fit property that functions properly in Firefox and IE. While it works well in Chrome and Opera, it is not compatible with Firefox and IE. Experimented with the imgLiquid Plugin, but encountered issues w ...

`Inconsistencies between navbar hide and show toggling on smaller and bigger screens`

I've been experimenting with making my navbar collapsible using Flexbox. Initially, I was able to toggle the navbar correctly when the screen size is smaller. However, I encountered an issue where the navigation items do not reappear when I hide them ...

What is the best way to center align a Bootstrap 4 modal window?

I'm facing a small issue here, I would like to have the modal display in the center. Instead of it appearing like this https://i.sstatic.net/R518w.jpg, I want it to look like this https://i.sstatic.net/wwUo7.jpg. Here is the code: <!-- The Modal -- ...

What is the reasoning behind placing the CSS file in the header section and the JS file at the bottom

Hey there, I need some help. Why is the CSS file included in the header section but the JS file at the end of the page? Can I also include the CSS file at the bottom of the page? <!DOCTYPE html> <html> <head> <link type= ...

Is jQuery the key to Masonry's stacking magic?

Hey there, I could really use some assistance with my website at this link: I thought jQuery Masonry would stack the objects closely together, but when I randomize the div boxes, there are large gaps between them. Can anyone explain why this is happening? ...

Column-oriented and Slim-fit packaging

I have been working on designing a layout with a fixed height that will display multiple columns of specified size to accommodate flowing text. While I have successfully implemented this, I am facing an issue where the enclosing div does not adjust its siz ...

Tips for appending the id of an active element to a URL

My goal was to include the id value of the active element in a URL and then redirect to that URL with a button click. HTML <div class="icon" tabindex="0" id="company"> <img src="company.png"> </div> <button type="submit" onclick= ...

How can I fetch and show an image from a directory in Asp.Net Core 3.1 using a razor view?

What is the best way to retrieve an image from a directory and display it on a web page? "I've searched for solutions but haven't found one that works" I attempted this method, but it didn't yield the desired results Controller ...

Styling with CSS: Aligning Text with ":"

Here is the text I am working with: I'm looking to align the colons so they are in a neat, straight line - for better readability. For example: topic: domain: origin: date: Is there a simple method to achieve this alignment? Thank you ...

Eliminate spaces within a string using JavaScript

In my quest for knowledge about trimming strings in JavaScript, I came across this intriguing discussion with a regex-based solution. After learning from the thread, I was under the assumption that trim would eliminate the space between "Hello" and "World ...

gist-react: containing gist within a scrollable div

Struggling to contain a gist within a div with scrollbars on my next.js site using gist-react. It seems like my CSS is being overridden when the gist loads from the underlying dependency. Is there a way to achieve this without modifying the dependency itse ...

Is it possible to use a shell script to replace the external CSS file link in an HTML file with the actual content of the CSS file

Seeking a solution for replacing external CSS and JS file links in an HTML document with the actual content of these files. The current structure of the HTML file is as follows: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C ...

What about nested elements with percentages, set positions, and fixed placements?

Picture: https://i.sstatic.net/KFNR1.png I am working on a design with a yellow container div that I want to keep at 50% width of the window. Inside this container is a purple image div that stretches to 100% of the parent container's width, and ther ...

Issues with CSS hover event causing animation to fail to trigger

I have a container that contains an image holder and a text holder. I am able to set it so that when hovered over, the image scales and the same effect applies to the text. However, when attempting to set up the image holder hover to scale the image and ...

Tips on Importing a Javascript Module from an external javascript file into an <script> tag within an HTML file

I'm facing an issue while attempting to import the 'JSZip' module from an external node package called JSZip in my HTML File. The usual method of importing it directly using the import command is not working: <script> import ...

Divide HTML elements every two words

Can you use CSS to break up HTML content after every 2 words, ensuring it works for any word combination? Example: // Original HTML content The cat is sleeping // Desired result: The cat is sleeping ...

Unable to navigate to specific tab in Laravel 6 navigation tabs using URL parameter (e.g. myweb/pages#tab1)

I'm having trouble navigating to the tabs pages, they only show up in the URL (myweb/pages#tab1 .. myweb/pages/#tab2 ..). Can someone please help me out? View image <div class="card-body"> <ul class="nav nav-tabs" id="myTab" role="tabli ...

Connecting a static HTML page to a separate device: A step-by-step guide

We have an internal web PHP app that we use with a tool. There are some static HTML files I want to link to, which are located on another machine. Currently, I am linking to them like this: <a href="file:////123.145.226.8/Projects/E-Reports/E-Report-&a ...

Error alert: The $ symbol is not defined

I followed a tutorial to create an auto-advancing slideshow in JavaScript/jQuery and it worked perfectly on jsfiddle. However, when I transferred everything to Dreamweaver, it stopped functioning. I have triple-checked that all the necessary files are link ...