Inline phone form input using Bootstrap

I'm attempting to design a nested Bootstrap grid for a phone number input. The concept is to have a label for the phone number, and it's fine if on smaller screens the "label" and "phone group" stack. However, I want to maintain the inline layout of the 3 phone inputs without stacking them. I am unsure of how to achieve this using the appropriate inline classes in this particular situation.

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">

<div class="form-row">
  <div class="col-md-5">
    <label for="ph1">Label</label>
    <input type="text" class="form-control" id="label">
  </div>
  <div class="col-md-5">

    <div class="form-inline">
      <div class="col-md-3">
        <label for="ph1">Country</label>
        <input type="text" class="form-control" id="ph1">
      </div>
      <div class="col-md-3">
        <label for="ph2">Area</label>
        <input type="text" class="form-control" id="ph2">
      </div>
      <div class="col-md-6">
        <label for="ph3">Number</label>
        <input type="text" class="form-control" id="ph3">
      </div>
    </div>
  
  </div>
</div>

Answer №1

Opt for nesting another form-row instead of using form-inline, and employ no-gutters to minimize the space between the input fields. Utilizing col-* over col-md-* will avoid stacking the phone number inputs.

<div class="form-row">
    <div class="col-md-5">
        <label for="ph1">Label</label>
        <input type="text" class="form-control" id="label">
    </div>
    <div class="col-md-5">
        <div class="form-row no-gutters">
            <div class="col-3">
                <label for="ph1">Country</label>
                <input type="text" class="form-control" id="ph1">
            </div>
            <div class="col-3">
                <label for="ph2">Area</label>
                <input type="text" class="form-control" id="ph2">
            </div>
            <div class="col">
                <label for="ph3">Number</label>
                <input type="text" class="form-control" id="ph3">
            </div>
        </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

Background anchor in Internet Explorer 7

Why is there an issue with the css background property for anchors in IE 7? css: .nav a { float: left; display: block; padding: 5px; height: 25px; line-height: 25px; font-weight: bold; } .nav a:hover { background: #fff; co ...

What is the best way for a background-image to determine its height in CSS?

I am currently working on a website project and I would like to include my title using a background-image because it uses a unique font. In my design class, we were taught that this is the best approach. However, I am struggling with setting the correct di ...

I struggle with managing a z-index in conjunction with an absolute position

Check out this codesandbox to see the issue where the 3 dots button is displayed over the menu. Click on the 3 dots to understand the problem. Below is the CSS code for the menu: .more-menu { position: absolute; top: 100%; z-index: 900; float: l ...

The Bootstrap navigation menu is not responsive as expected

Below is the HTML code for the navbar: <nav class="navbar navbar-light" style="background-color: #967BB6;"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle" ...

I am looking to enable the selection of multiple buttons within a List group

I'm facing an issue with my code where the dropdown menu is not displaying dropdown items. I need help fixing this problem, it would be greatly appreciated. Additionally, I also want to enable multiple selection of buttons and change the color of each ...

Div I add to page is not being styled by CSS

I'm currently developing a Chrome extension that provides a preview of a webpage when hovering over a hyperlink to it. To achieve this, I am creating a div and filling it with different items. However, the issue I'm facing is that the CSS styles ...

Is there a way to apply two distinct styles to a single component on a webpage?

Currently, I am in the process of developing a web application using Node JS, React, and Bootstrap. Within the application, I have implemented a main menu and a secondary menu using tabs. I have successfully defined a style for the main menu, but I am faci ...

Issues with responsiveness in CSS across various devices

Struggling to make CSS work across different devices like desktop, iPad 4, and Sony S8? Here are my media queries: @media screen and (min-width: 1200px){ body{ background: red; } } @media screen and (min-width: 768px) and (max-width: 979px ...

What is the best way to conceal my class element if the data-reviews number is under 5?

I have been experimenting with basic JavaScript for the data-reviews="2" scenario and it worked successfully. However, what I am aiming for is to hide the entire <span> section when the value of data-reviews is less than 5 or any specific ...

Learn the technique for showcasing numerous markers on Google Maps, each equipped with its own individualized info windows

https://i.sstatic.net/1tTUD.png // map center var center = new google.maps.LatLng(2.855262784366583, 105.4302978515625); function initialize() { var mapOptions = { center: center, zoom: 7, mapTypeId: google.maps.MapTypeId.ROADMAP }; // Create a < ...

Elements centered within a flex container are expanding and overflowing above

It seems like I'm missing a key point when it comes to my flexbox setup for vertical and horizontal centering. The issue arises when the container's height exceeds that of its parent, causing the content to extend beyond the top but remain fixed ...

Single-line form with labels positioned above the input fields

For my web app project, I am using AngularJS and Bootstrap 3 for CSS (although my CSS knowledge is limited). I am trying to design an inline form with 5 input fields and labels positioned on top of them. The first field should take up more space than the o ...

Creating a straightforward CSS design that stretches to fit the entire viewport dimension

I am attempting to create a simplistic layout using HTML/CSS, as depicted in the wireframe below: /------------------------------------------\ | | | header div | | ...

Seamless transition of lightbox fading in and out

Looking to create a smooth fade in and out effect for my lightbox using CSS and a bit of JavaScript. I've managed to achieve the fading in part, but now I'm wondering how to make it fade out as well. Here is the CSS code: @-webkit-keyframes Fad ...

Creating a promotional slide-up feature on a website page using jQuery and Bootstrap

Is there a way to achieve a promotional slide-up similar to the one showcased below using the features provided by Bootstrap/jQuery? https://i.sstatic.net/ZMLeD.png ...

Tips for hiding a bootstrap modal in Angular4 when it has no content

I am currently working on an Angular 4 e-commerce application. One of the requirements is to hide a bootstrap modal when there are no products in the cart. When a user selects some products, they are added to the mycart modal screen. The user also has the ...

Can the jQuery UI slider button display its current value?

I have been tasked by my client to code a UI that looks like the one in the image linked below. The slider value is displayed on the slider button itself. Can someone provide me with guidance on how to achieve this with minimal effort? Is it feasible to u ...

What is the best way to expand a scrollbar's width with CSS?

Can the width of a scrollbar on a <div> element within the <body> be increased? I mean the scrollbar specifically on the inner <div> element, not the default browser scrollbar since this page is in full screen mode and does not display t ...

Django file upload causing files to be unexpectedly renamed

In my Django application, I am utilizing a file upload control (Code provided below). It is known that Django employs two FILE_UPLOAD_HANDLERS to handle file upload requests. Memory based: If the file size is less than 2.5mb, it utilizes MemoryFileUpload ...

What are the implications of dynamically setting or changing event handlers in web development?

Looking to streamline the process of replacing standard confirm() boxes with Bootstrap modals for saving and deleting on a page. Each operation has its own button (referred to as the action button) which triggers the corresponding modal. Upon clicking the ...