Guide to adding dividing lines between columns with bootstrap

https://i.sstatic.net/FHO1v.pngCan someone help me with adding separators between columns in my HTML code? I've tried the code below but it's not working. Is there a way to achieve this? I've attached a screenshot of what I'm expecting.

HTML Code:

<div class="jumbotron jumbotron-fluid controls">
  <div class="container">
    <form class="form-form-submit">
      <div class="row">
        <div class="col">
          <div class="form-group">
            <label for="form_name">Name *</label>
            <input id="form_name" type="text" name="surname" class="form-control" placeholder="Please enter your name *"
              required="required" data-error="name is required.">
            <div class="help-block with-errors"></div>
          </div>
        </div>
        <div class="col">
          <div class="form-group">
            <label for="form_email">Email *</label>
            <input id="form_email" type="email" name="email" class="form-control"
              placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
          </div>
        </div>
        <div class="w-100"></div>
        <div class="col">
          <div class="form-group">
            <label for="form_phone">Phone</label>
            <input id="form_phone" type="tel" name="phone" class="form-control"
              placeholder="Please enter your phone number">
            <div class="help-block with-errors"></div>
          </div>
        </div>
        <div class="col">
            <div class="btn-group" style="padding-top: 25px;">
                <input type="submit" class="btn btn-primary" value="Submit">
            </div>
          </div>
      </div>
    </form>
  </div>

To add lines between columns, I want to use the following code:

<div class="col-md-2 col-sm-4">
<div class="line">|</div>
<div>OR</div> 
<div class="line">|</div>
</div>

The desired output format should look like this:

                 |
Name             | Email
                OR
Phone  Button    |
                 |

Answer №1

It's possible that this might not align with your intentions.

.v-line {
  width: 5px;
  background-color: teal;
}

.or {
  background-color: #e9ecef;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<div class="jumbotron jumbotron-fluid controls">
  <div class="container">
    <form   class="form-form-submit">
      <div class="d-flex flex-row">
        <div class="d-inline-block w-50">
          <div class="col">
            <div class="form-group">
              <label for="form_name">Name *</label>
              <input id="form_name" type="text" name="surname" class="form-control" placeholder="Please enter your name *"
                required="required" data-error="name is required.">
              <div class="help-block with-errors"></div>
            </div>
          </div>
          <div class="col">
            <div class="form-group">
              <label for="form_phone">Phone</label>
              <input id="form_phone" type="tel" name="phone" class="form-control"
                placeholder="Please enter your phone number">
              <div class="help-block with-errors"></div>
            </div>
          </div>
        </div>
        <div class="v-line d-flex align-items-center justify-content-center">
          <span class="or">OR</span>
        </div>
        <div class="d-inline-block w-50">
          <div class="col">
            <div class="form-group">
              <label for="form_email">Email *</label>
              <input id="form_email" type="email" name="email" class="form-control"
                placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
            </div>
          </div>
          <div class="col">
              <div class="btn-group"  style="padding-top: 25px;">
                  <input type="submit" class="btn btn-primary" value="Submit">
              </div>
          </div>
        </div>
      </div>
    </form>
  </div>

Answer №2

To adjust the size of the fields, reduce each by one unit to col-md-5 on both the left and right sides. This results in a combined column span of 10, with 2 columns left over (since Bootstrap columns always total 12).

After this adjustment, you can include offset-md-2 on the right-most columns to create a 2-column gap:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="jumbotron jumbotron-fluid controls">
  <div class="container">
    <form class="form-form-submit">
      <div class="row">
        <div class="col-md-5">
          <div class="form-group">
            <label for="form_name">Name *</label>
            <input id="form_name" type="text" name="surname" class="form-control" placeholder="Please enter your name *" required="required" data-error="name is required.">
            <div class="help-block with-errors"></div>
          </div>
        </div>
        <div class="col-md-5 offset-md-2">
          <div class="form-group">
            <label for="form_email">Email *</label>
            <input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
          </div>
        </div>
        <div class="w-100"></div>
        <div class="col-md-5">
          <div class="form-group">
            <label for="form_phone">Phone</label>
            <input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your phone number">
            <div class="help-block with-errors"></div>
          </div>
        </div>
        <div class="col-md-5 offset-md-2">
          <div class="btn-group" style="padding-top: 25px;">
            <input type="submit" class="btn btn-primary" value="Submit">
          </div>
        </div>
      </div>
    </form>
  </div>

It's important to note that creating a gap of only 1 unit while maintaining equal column lengths is challenging (due to the even total column count). However, you can achieve a total of twelve with any combination like col-md-5 + offset-md-1 + col-md-6.

Answer №3

Although I know there may be a more efficient way to approach this, for now, this is how I recall it. Essentially, just insert an empty column div between the two existing columns:

<div class="jumbotron jumbotron-fluid controls">
  <div class="container">
    <form   class="form-form-submit">
      <div class="row">
        <div class="col-5"`enter code here`>
          <div class="form-group">
            <label for="form_name">Name *</label>
            <input id="form_name" type="text" name="surname" class="form-control" placeholder="Please enter your name *"
              required="required" data-error="name is required.">
            <div class="help-block with-errors"></div>
          </div>
        </div>
         <div class="col-1">
        </div>
        <div class="col-6">
          <div class="form-group">
            <label for="form_email">Email *</label>
            <input id="form_email" type="email" name="email" class="form-control"
              placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
          </div>
        </div>
        <div class="w-100"></div>
        <div class="col-5">
          <div class="form-group">
            <label for="form_phone">Phone</label>
            <input id="form_phone" type="tel" name="phone" class="form-control"
              placeholder="Please enter your phone number">
            <div class="help-block with-errors"></div>
          </div>
        </div>
        <div class="col-1">
        </div>
        <div class="col-6">
            <div class="btn-group"  style="padding-top: 25px;">
                <input type="submit" class="btn btn-primary" value="Submit">
            </div>
          </div>
      </div>
    </form>
  </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

Challenges with displaying css/bootstrap classes within angular2

Experiencing difficulties with CSS/Bootstrap integration when displayed in an angular2 component. When attempting to display the CSS and HTML content in the Index.html file (with proper CSS and JS references), everything functions correctly. However, once ...

Tips for preventing text from changing its padding within a div when reducing the width and height dimensions

I am facing an issue with a div inside another div. The child div contains text, and when I apply animation to decrease the width and height, the text inside gets reset according to the new size. While I understand why this happens, I want to find a way to ...

Dynamically showing a div using JavaScript and AJAX after changing the window location

After successfully fetching data from the server through AJAX, I am redirecting to the same screen/URL. Is it possible to show/display a div after redirecting using jQuery? $.ajax({ type: "POST", url: action, data: form_data, success: func ...

Issue with unordered list item styling in CSS

Encountered a peculiar problem: Within my .cshtml file, there is another element: <ul> <li>Test</li> <li>Test2 <ul> <li>Test3</li> </ul> </li> <li>Tes ...

Change the image displayed when hovering over the div containing it

I've come to a roadblock while attempting to change an image when hovering over its containing div. I could achieve this using CSS, but I have 6 divs with 6 images inside them. If I were to use CSS, I'd need 6 sets of hover events to swap the ba ...

How can the <animate /> tag be triggered using only CSS and HTML?

Looking for a way to trigger the animation rules of the <animate /> tag using only HTML and CSS. Is there a new standard in HTML and CSS that allows something like input:checked ~ svg animate {enabled:true;} coming up in 2020? Or some other creative ...

Unable to adjust the width of a table column within a horizontally scrollable container

I am struggling to resize the columns of a large table with 20 headers. Despite trying to place the table inside a div with overflow:auto, I still cannot achieve horizontal scrolling or make the div expand when resizing the columns. A sample code snippet ...

What can be done to stop the Datepicker from exiting the Dialog box and causing it to malfunction?

While creating a form inside a dialog box, I encountered an issue with the date picker functionality. Whenever I try to select a date, it disappears and breaks, rendering the last days of the calendar inaccessible. You can view an example of this problem i ...

Guide on how to set the grid cell width to 0 for specific dimensions

What can be used in place of mdl-cell--0-col-phone to either disable an element or make its width zero? <div className="mdl-grid"> <div className="mdl-cell mdl-cell--2-col-phone mdl-cell--2-col-tablet mdl-cell--2-col-desktop"> <Left ...

The correct way to write media queries in CSS for the iPhone

After successfully formatting a website for various devices using an online responsive design tester and CSS declarations like @media only screen and (max-width: 480px), I encountered an issue during testing on an actual iPhone. The browser was not computi ...

Eliminate the error notification on the login page if it corresponds to the input

I am facing an issue with my login page and the API for password validation. Even when the password matches, an error message is still being displayed. This is because I am looping through the data and need to break the loop once a match is found. How can ...

What is the best way to ensure that Bootstrap 4 utilizes the full width of the screen?

Currently, I have integrated Bootstrap 4 into my project with the following viewport configuration: <meta name="viewport" content="width=device-width, initial-scale=1"> While everything displays and scales properly on different devices, I noticed a ...

What is the best way to create five equal columns using bootstrap vue?

I found the reference here: My goal is to create 5 columns in 1 row This is my current script: <template> ... <b-row> <b-col cols v-for="club in clubs"> {{club.name}} </b-col> ...

Ways to animate elements while scrolling in React.js?

I am new to using React.JS and currently working on setting up an E-commerce Store. My goal is to have 5 images stack on top of each other and move together as the user scrolls. I used to achieve this effect in Vanilla JavaScript by adding a window.addEven ...

Using HTML and CSS, create a layout with three columns where the side columns are flexible in width and the middle

Currently, I am facing an issue with the header design of my website. The layout consists of 3 columns of divs and my goal is to have a middle column with a fixed width of 980px. In addition, I want the left side of the header to span across the entire bro ...

<ul><li>issue with indentation

Is there a way to eliminate the indent from my unordered list? While inspecting the element, I noticed what appears to be padding between the width of the box and the content. However, setting padding to 0px and margin to 0px doesn't seem to work as t ...

modify the name attribute of a select dropdown using jQuery dynamically

In my current project, I am working on dynamically changing the "name" attribute for each select box based on user interactions. The scenario is as follows: When a user clicks on an option in the first select box, a new select box appears with the remainin ...

What is the best way to include an arrow in a dropdown menu?

I've been working on restyling a Select box and I want to add a CSS arrow that rotates as the Select box expands. However, I'm struggling to align the arrow properly with the Select box. I've tried using code from the internet, but it hasn&a ...

Does CSS have a selector that does not include any elements?

Considering the examples below <span id="foo_repeater_bar_0"></span> <span id="foo_repeater_batz_1"></span> I am looking for a CSS selector that will allow me to target only the elements whose id does not include foo_repeater. ...

Moving from one page to another

I am attempting to create a transition effect between sections within a single-page application. All the sections are contained on the same page, with only one section displayed at a time while the rest are set to display none. When a specific event is tri ...