Struggling to vertically center input within Bootstrap 4 column

I'm attempting to design some form elements and align the inputs vertically within the columns. I've experimented with vertical-align:middle; and margin:auto 0;, however, neither of these solutions seem to be effective.

input {
  vertical-align:middle;
  margin:auto 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
  <div class="row">
    <div class="col-sm-9">
      <div class="form-group">
          <div class="row">
            <label for="phonenum" class="col-sm-2">Please enter your phone number</label>p>
            <div class="col-sm-10">
                <input type="text" name="phonenum" />
            </div>
          </div>
      </div>
    </div>
  </div>
</div>

Answer №1

It seems like you might be looking to vertically center elements, in which case you can utilize the align-items-center class from Bootstrap. This class works well with flexbox and can help with vertical alignment.

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
  <div class="row">
    <div class="col-sm-9">
      <div class="form-group">
        <div class="row align-items-center">
          <label for="phonenum" class="col-sm-2">Enter your phone number</label>
          <div class="col-sm-10">
            <input type="text" name="phonenum" />
          </div>
        </div>
      </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

Discover the hidden content within a div by hovering over it

Here is an example of a div: <div style="width:500px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis pulvinar dui. Nulla ut metus molestie, dignissim metus et, tinc ...

Only displaying sub items upon clicking the parent item in VueJS

I'm in the process of designing a navigation sidebar with main items and corresponding sub-items. I want the sub-item to be visible only when its parent item is clicked, and when a sub-item is clicked, I aim for it to stand out with a different color. ...

Steps for turning off image maps on a slider for mobile users

Hello, I'm currently working on a website that has an image slider with image maps embedded in each image. Everything works perfectly on desktop, but when it comes to mobile versions, things start to get messy. I was wondering if there is any way to d ...

"Troubleshooting a dropdown navigation bar problem in CSS

I am currently working on creating a CSS navbar dropdown, but I am encountering some issues. I am not very experienced with CSS, so any assistance would be greatly appreciated. The text within the "Products" box is not changing color like it should, and yo ...

The automatic width feature in Firefox is malfunctioning and not behaving as expected

Here is my question: I have an image wrapped in a div (.indexWrap): <div id = "slider"> <div class="indexWrap"> <img class="indexImage" src=""> </div> ...

Utilizing Bootstrap's styling features for iOS browser: customizing borders and text in HTML

On the iPhone browser, I am encountering an issue with my code. Specifically, the text disappears and the div border or shadow changes, but when I test it on Safari browser, everything looks fine. The developer version of the website can be found at: Conta ...

Having trouble with the flexbox flex-direction: column property not functioning properly with the textarea element in Firefox?

Inconsistencies between Chrome and Firefox have been noticed in the following example. While the footer height is set to height:40px and appears fine in Chrome, it seems smaller in Firefox, around 35px. Any specific reasons for this difference? Link to t ...

ColorBox refuses to adjust width dynamically

Utilizing the Jquery plugin called colorbox in my HTML application has presented me with a challenge. I have two divs on my page – one positioned at the left and the other at the right. What I desire is for the right div to initially have its display set ...

Differences in window height between Firefox and Chrome

When positioning a modal vertically, how can I ensure consistent alignment across different browsers? method.center = function () { var top, left; top = Math.max($(window).height() - $modal.outerHeight(), 0) / 2; left = Math.max($(window).widt ...

The width of the unordered list is not what I defined

when I set this line: <ul style="width:100px; height:100px; background-color:green"> <li style="width:100px; height:100px; border:1px solid blue"> 1 </li> </ul> The ul ends up wider than my specified 100px width. Any thoughts ...

Tips for adding a border-bottom a few pixels underneath a list item:

I'm working with a menu that has dynamic content. When a user clicks on a li tag, it receives the class "active". I want to show which class is active by adding a border-bottom to it, but I want the border-bottom to be positioned 5px under the li tag ...

What is the best way to eliminate the "#" symbol from a URL?

I'm currently updating a website that features a hash symbol in every link when switching pages. This causes the page to not refresh everytime I switch, instead it stays on the last position of the site. Where can I locate the code responsible for th ...

Creating a PDF of a dynamic PHP webpage

Currently, I'm working on developing a customized invoicing application that uses PHP and MySQL to create interactive invoices directly in the web browser. The design includes tables and CSS to enhance the layout. I have a concept in mind to improve ...

How do you prevent items from shrinking in a flex container when they have more content?

I am facing an issue with a flex container where the items are set in a row. Once it reaches the end of the viewport width, I want it to overflow-x: scroll. However, instead of enabling scrolling, all items shrink when more items are added to fit the scree ...

Can the site be shown in the background?

I have a unique idea for a games website that I want to share. It's a bit difficult to explain, so please bear with me as I try to convey my vision! The inspiration for this project comes from a website called . Have you seen it before? The concept i ...

SVG's height attribute not adjusting properly

I am currently working on implementing an SVG sprite sheet using the "symbol" method outlined here. My HTML code is quite straightforward. <svg><use xlink:href="/images/iconSprite.svg#camera"/></svg> Below is a sample symbol extracted ...

Tips for updating the color of the mat-paginator's border at the bottom

Is there a way to change the border bottom color of my mat-paginator when an option is selected? It currently defaults to purple, but I would like to customize it. Any suggestions? Click here for an example of the current purple border on Mat-paginator. ...

Version 5.1.3 of Bootstrap now combines the $colors with the $theme-colors map for enhanced customization

I am attempting to introduce some color variables like "blue", "indigo" ... to the $theme-colors map. It appears to be functioning, but after compiling, it seems duplicated in the :root selector as shown in the image below. Here's ...

Adjust the parent element to match the width of the child by utilizing the "display: grid" property

edit: I'm uncertain if this is a duplicate issue. My concern is not about the background color extending beyond the container width, but rather about expanding the container to match the size of its child with display: grid. I have updated the example ...

What could be causing the issue with the JQuery .hide() function not functioning properly with the bootstrap spinner?

As I implement a basic spinner feedback for a server response to an ajax query, I encounter an issue. I utilize the JQuery .show() function before initiating the ajax call, and then invoke the .hide() function within the .always() callback of the request. ...