Centering both vertically and horizontally will reveal hidden elements

Within the following code snippet, there are 6 instances of form-group. All elements are styled using Bootstrap 4 to achieve both vertical and horizontal centering. The center alignment appears to work correctly, but when resizing the browser window vertically, some elements at the top may be hidden by the browser's scrollbar. (To see this behavior in action, run the code snippet).

https://i.sstatic.net/0gPwE.png

Could someone provide guidance on how to resolve this issue?

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    ... (remaining HTML code continues)
            

Answer №1

To ensure a minimum height for the row, simply use 100vh.

Visit this link for an example

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"
        crossorigin="anonymous">
    <style>
        .min-100 {
            min-height: 100vh;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="row min-100 justify-content-center align-items-center">
            <div class="col-lg-5 col-md-8 col-sm-11">
                <form class="form-control" method="post">
                    <div class="form-group mb-2">
                        <label class="col-form-label col-form-label-sm pt-0 pb-0">
                            Email 1
                        </label>
                        <input type="text" class="form-control form-control-sm" />
                    </div>
                    <div class="form-group mb-2">
                        <label class="col-form-label col-form-label-sm pt-0 pb-0">
                            Email 2
                        </label>
                        <input type="text" class="form-control form-control-sm" />
                    </div>
                    <div class="form-group mb-2">
                        <label class="col-form-label col-form-label-sm pt-0 pb-0">
                            Email 3
                        </label>
                        <input type="text" class="form-control form-control-sm" />
                    </div>
                    <div class="form-group mb-2">
                        <label class="col-form-label col-form-label-sm pt-0 pb-0">
                            Email 4
                        </label>
                        <input type="text" class="form-control form-control-sm" />
                    </div>
                    <div class="form-group mb-2">
                        <label class="col-form-label col-form-label-sm pt-0 pb-0">
                            Email 5
                        </label>
                        <input type="text" class="form-control form-control-sm" />
                    </div>
                    <div class="form-group mb-2">
                        <label class="col-form-label col-form-label-sm pt-0 pb-0">
                            Email 6
                        </label>
                        <input type="text" class="form-control form-control-sm" />
                    </div>
                </form>
            </div>
        </div>
    </div>
</body>

</html>

Answer №2

To achieve the desired outcome, ensure that you set min-height to .h-100.

.h-100 {
    height: 100%!important;
    min-height: 393px; // Remember to include this
}

If you cannot add CSS directly to h-100, you have the option to create your own class in HTML with h-100 and apply min-height to that custom class as demonstrated below:

<div class="h-100 myForm">

</div>

Your corresponding CSS code would look like this:

.myForm {
  min-height: 393px;
}

You can view a working example on this fiddle here

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

Javascript issue: opening mail client causes page to lose focus

Looking for a solution! I'm dealing with an iPad app that runs html5 pages... one specific page requires an email to be sent which triggers the Mail program using this code var mailLink = 'mailto:' + recipientEmail +'?subject=PDFs ...

Creating artwork using a "graphite drawing tool" on a blank canvas

I created a script that draws a series of lines on a canvas, giving it a sketch-like appearance. However, I have encountered two issues with the script. Firstly, why is the y value appearing to be twice as much as it should be? Secondly, why is the line w ...

Developing a feature that allows users to switch between different sets of information

I'm currently exploring a new project and attempting to design a toggle that switches between monthly and annual payments based on the user's selection, much like the functionality found here: . At present, I have implemented two sets of price c ...

ensure that pagination is optimized for mobile viewing in Laravel using Bootstrap

I am facing an issue with fitting the pagination on a mobile device using Laravel 6 and Bootstrap 4. After some research, I discovered a useful function for pagination called onEachSide(). $products->onEachSide(1)->links() Initially, everything l ...

Creating a list of definitions in the form of an HTML table using a multidimensional array in

Currently, I am tackling the following challenge: I must create a public static buildDefinitionList() method that produces an HTML list of definitions (using <dl>, <dt>, and <dd> tags) and then returns the resulting string. If the array c ...

Vue.js component communication issue causing rendering problems

When it comes to the Parent component, I have this snippet of code: <todo-item v-for="(todo, index) in todos" :key="todo.id" :todo="todo" :index="index"> </todo-item> This piece simply loops through the todos array, retrieves each todo obj ...

Is it possible for a website to instruct a user's browser to save the entire page locally?

Is it possible for a (single-page) website to instruct a user's browser to save the entire page locally? To provide some background: I am running a website on a server that bills based on bandwidth usage. Since the content of the site remains mostly ...

Layout your Angular components with a column design using Flex Layout

Is there a way to adjust the width of a child component in an fxLayout set to column? Take this example for reference: https://stackblitz.com/edit/angular-fxlayout-custom-breakpoints?file=app%2Ftest.component.ts In the provided example, there are three f ...

Create and dispatch a JSON POST request to a remote domain without direct server access

My current hurdle involves attempting a POST request in JSON to an external domain without having access to the server's files for modification. However, upon making the request, I encounter the following error: XMLHttpRequest cannot load . No & ...

Arranging my HTML text fields for optimal organization

I am struggling to format my text fields the way I envision. Here's what I want: - Username field at the top - First and last name underneath each other - Password and confirm password next to each other below names As a newcomer to HTML, I'm fi ...

Having trouble locating and interacting with the textarea element in Salesforce using Selenium Webdriver

Encountering an issue with the Selenium Webdriver where it throws an error stating that the element is not visible and cannot be interacted with when attempting to access a textarea. 1. The textarea is located within a pop-up window, which can be accessed ...

How can I create a dynamic height for a scrollable div?

How can I build a section with a defined height that contains a sticky header (with a dynamic height) and a scrollable body? I want the body to be scrollable, but due to the header's changing height, I'm unable to set an exact height. What should ...

Is there a way to extract the unicode/hex representation of a symbol from HTML using JavaScript or jQuery?

Imagine you have an element like this... <math xmlns="http://www.w3.org/1998/Math/MathML"> <mo class="symbol">α</mo> </math> Is there a method to retrieve the Unicode/hex value of alpha α, which is &#x03B1, using JavaScrip ...

JavaScript double-click functionality is not operational on IE9 and IE11 browsers

My JavaScript code has an issue where single-click opens a link in a new tab and double-click opens a lightbox. This works perfectly in all browsers except for IE9 and IE11. In my initial code, both single-click and double-click function correctly. However ...

Having trouble debugging a website remotely? Dealing with a JSON problem specifically in IE8

Currently, the website is functioning flawlessly on various machines except for those used by the client in Africa. Unfortunately, I have no way of accessing his specific machine due to geographical constraints. The client has limited IT knowledge, and we ...

What could be causing these "areas" or "panels" to intersect with each other?

As I work on constructing a website, I'm facing an issue with the top two sections. They appear correctly when my screen is full size, but as soon as I adjust the screen size, they jump down and create white space. It seems like I may have approached ...

What could be causing my select value to stay unchanged? Issue with the "selected" attribute or property

var original_role = $('option:selected', '#user_role').val(); $('#role_cancel').click(function() { //console.log(original_role); $('option:selected', '#user_role').removeAttr('selected'); //des ...

Elements in Internet Explorer become unresponsive after being hidden or shown using jQuery

One issue I'm encountering is with a group of tabbed divs that I'm using jQuery hide() and show() to toggle the visibility. This method functions perfectly in most browsers, but unfortunately in Internet Explorer (IE), the hidden tabs become unre ...

The text/font-weight of the header button is mysteriously shifting without warning

While creating a header for my webpage, I encountered an issue where the text family was changing when the dropdown menu was launched in Safari 8. Curiously, this behavior did not occur when using Chrome to launch the jQuery function. Even after attempting ...

The symbols ">>" have been changed to "�"

There has been a report from one of our application users stating that they are seeing the character � instead of >> on their home and other pages. This issue is only affecting one out of 100 users, and the user in question is using IE11. What c ...