What methods can be used to prevent divs from overlapping when the window size is reduced?

Creating a login page with two main content divs in a section layout. The first div contains the logo, input prompts, and login/password reset buttons. The second div serves as a footer with social media links. On a full-size window, the logo is positioned to the left of the login prompt, and the social media links are at the bottom. However, when the window height is reduced, the login buttons overlap into the social media bar at the bottom. Also, when the window width is too small, the logo overlaps the input form. I want to keep them separate and have the layout be scrollable on smaller windows.

I attempted to use a media query to address the issue, but it did not work as expected:

.hcustom {
    height: calc(100% - 73px);
}
@media screen and (max-width: 400px) {
    .hcustom {
        height: 100%; // I also tried with 100vh
    }
}

I experimented with adding and removing the word "Screen" in the media query, unsure of its correct usage. Another solution I found was to set the height of `.hcustom` to `min-height: 100vh;`, which resolved the issue on smaller windows but created a large gap between the first div and the social media bar on larger windows, causing unnecessary scrolling.

Below is the structure of my index.php file:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="Expires" content="0">  
        <meta name="Description" content="Login">
        <title>LOGIN</title>

        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
    
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js" 
        integrity="sha384-cuYeSxntonz0PPNlHhBs68uyIAVpIIOZZ5JqeqvYYIcEL727kskC66kF92t6Xl2V" crossorigin="anonymous"></script>
    
        <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.4/dist/jquery.min.js"
        integrity="sha256-oP6HI9z1XaZNBrJURtCoUT5SUnxFr8s3BzRl+cbzUq8=" crossorigin="anonymous"></script>

        <link rel="stylesheet" href="loginStyles.css">

    
    </head>

    <body>
    <section class="vh-100">

     <!-- FIRST Div -->        
         <div class="container-fluid hcustom">
            <div class="row d-flex justify-content-center align-items-center h-100">

                <div class="col-md-9 col-lg-6 col-xl-5 text-center">
                    <img src="img/main-logo.png"
                    alt="Login image" class="img-fluid" style="">
                </div>

                <div class="col-md-8 col-lg-6 col-xl-4 offset-xl-1">       
                    <form action="login.php" method="post">   
                        <div class="d-flex flex-row align-items-center justify-content-center justify-content-lg-start">
                                <h2>Login</h2>
                        </div>

                        ...
    
                    </form>
                </div>
            </div>
        </div>

<!-- Second Div --> 
       <div
        class="d-flex flex-column flex-md-row text-center text-md-start justify-content-between py-4 px-4 px-xl-5 bg-primary ">
            
            <div class="text-white mb-3 mb-md-0">
            Social Media 
            </div>
           
            ...

        </div>
    </section>
    </body>
</html>

Below is the content of my loginStyles.css file:

.hcustom {
    height: calc(100% - 73px);
}
@media screen and (max-width: 450px) {
    .hcustom {
        height: 100vh;
    }
}

I am utilizing Bootstrap 5 for the design.

Answer №1

Make sure to update the Image and Login div classes to class="col-4"

<!doctype html>
<html lang="en-US">
<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="Description" content="Login Page">
    <title>LOGIN</title>

    <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bee0ede5edeaecefd0f7e3f4b2e5f3c0e8e5eda8e5ede3">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-3TDBu59hiNp29cj4+thNVS/AMnzFoQQSyUHORh1Ipcz7ROy3uQLG3XysH1R3hm" crossorigin="anonymous">

    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="47636f676f686e6d42677562a467715d6068|77">[email protected]</a>/dist/js/bootstrap.min.js" integrity="sha384-Y9yOzEQcv5r6d5lYqCsprJTz7B8Q2GDDocGKraKV7/1UeFeq8GeYP5pj3LR0PQd" crossorigin="anonymous"></script>

    <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7608040c041313151609021512470e021a07360e031b5e030b07">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-KFmBNltWaIj1dG0YiAF3E4wEwz3Zx5pF5Jm3QcOl3G5hPRY3GGoS9X1R3G5Xg" crossorigin="anonymous"></script>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-Hy8dmikOj6AmD4UzFPFnI6jsoU0pq6qWEuUKlJhboag=" crossorigin="anonymous"></script>

    <link rel="stylesheet" href="styles.css">

    <style>

    </style>
</head>

<body>
<section class="full-height">

 <!--FIRST Div -->
     <div class="container-fluid custom-height">
        <div class="row d-flex justify-content-center align-items-center full-height">
            <div class="col-4">
                <img src="img/logo.png" alt="Login Image" class="img-fluid" style="">
            </div>

            <div class="col-4">
                <form action="login.php" method="post">
                    <div class="d-flex flex-row align-items-center justify-content-center justify-content-lg-start">
                        <h2>Login</h2>
                    </div>
                    <hr>
                    <br>

                    <?php if(isset($_GET['error'])) {?>
                        <p class="error"><?php echo $_GET['error']; ?></p>
                    <?php } ?>

                    <div class="form-outline mb-4">
                        <input type="text" id="username" name="username" placeholder="Enter User Name" class="form-control form-control-lg" />
                        <label class="form-label" for="username">User Name</label>
                    </div>

                    <div class="form-outline mb-3">
                        <input type="password" id="password" name="password" placeholder="Enter Password" class="form-control form-control-lg" />
                        <label class="form-label" for="password">Password</label>
                    </div>

                    <div class="d-flex justify-content-between align-items-center">
                        <div class="form-check mb-0">
                            <input class="form-check-input me-2" type="checkbox" value="" id="remember" />
                            <label class="form-check-label" for="remember">Remember me</label>
                        </div>
                        <a href="#!" class="text-body">Forgot password?</a>
                    </div>

                    <div class="pt-1 my-3 text-center">
                        <button type="button" class="btn btn-primary btn-lg" style="padding-left: 2.5rem; padding-right: 2.5rem;">Login</button>
                    </div>

                    <div class="text-center mt-4 pt-2">
                        <p class="small fw-bold mt-2 pt-1 mb-0">Don't have an account? <a href="" class="text-danger">Register</a></p>
                    </div>

                </form>
            </div>
        </div>
    </div>

<!-- Second Div -->
   <div class="d-flex flex-column flex-md-row text-center text-md-start justify-content-between py-4 px-4 px-xl-5 bg-primary">

        <div class="text-white mb-3 mb-md-0">Social Media</div>

        <div>
            <a href="" class="text-white me-4 text-decoration-none">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-facebook" viewBox="0 0 16 16"></svg></a>
            <a href="" class="text-white me-4 text-decoration-none" >
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-youtube" viewBox="0 0 16 16"></svg></a>
            <a href="" class="text-white me-4 text-decoration-none">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-instagram" viewBox="0 0 16 16"></svg></a>
            <a href="" class="text-white text-decoration-none">
                <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-book-half" viewBox="0 0 16 16"></svg></a>

        </div>

    </div>
</section>
</body>
</html>

Answer №2

Consider using a single container to house both of your div elements rather than placing them in individual containers. This approach allows you to evenly split the container's space, with each div taking up 50% of the available area.

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

Dispatching information to a designated Google Analytics tracking code

Within our website, we have a unique dimension that is configured on Google Analytics and utilized when sending the page view event: gtag('config', 'UA-TrackingCode', { 'custom_map': { 'dimension1': &apo ...

Sending simple form information through AJAX to a PHP web service

Attempting to send form data via jQuery and Ajax to a PHP web service (php file) for echoing the results. This is my index.html file <html> <head> <title>PHP web service &amp; AJAX</title> <link rel="stylesheet" type="text/ ...

JQuery preventing the opening of a Bootstrap modal window

Having multiple modal windows in a CodeIgniter view and facing issues while trying to open them using JQuery. Attempted using .modal('toggle') and .modal('show') but failed. Interestingly, using a button with data-toggle and data-target ...

Unknown Parameters Issue with Vue.js Router Links

Within my Vue.js project, I am utilizing params in my navigation.vue component to pass data onto the next page for dynamic routing purposes. Below is an example of how I am using this: <router-link tag="p" :to="{name: 'Main', ...

Can you explain the distinction between $(document) and $('*') and how can we determine which library $ is referring to?

My interpretation is this: $(document) will contain the entire DOM of the current page just like document, while $('*') also selects the entire DOM. What sets them apart, aren't they essentially the same? Will assigning $ from different lib ...

What is the process for obtaining the hashed password to store in my database?

Despite being able to run a test in Postman, I am facing difficulties with passing my hashed password into the DB correctly. const express = require("express"); // const helmet = require("helmet"); const { User } = require("./db/mo ...

Update the contents of TubeBufferGeometry with a new TubeBufferGeometry directly, avoiding unnecessary memory allocation

I am working with a mesh that is based on a TubeBufferGeometry. In each animation cycle, the path of the TubeBufferGeometry needs to change based on values provided at runtime. To achieve this, I want to update the geometry with a new TubeBufferGeometry ev ...

Having issues with AngularJS where ng-table/ng-repeat rows are failing to load properly

I've been following a tutorial on using ng-Table, which can be found Here. When I download the example from Git, it loads without any issues. However, when I try to replicate even the simplest example myself, the column headers and filters load but th ...

What methods do you use to gather user inputs and transmit them to a server?

I've been struggling to find information online about how to capture user input and submit the data through a POST request to a server, even though this may have already been answered. Currently, I am working with Material UI, React, and JavaScript t ...

Cancellation of event by keypress handler

I found this code snippet: jQuery('#parent').on('keypress', '.textbox', function(e) { var btn = jQuery(this).closest('tr').find('.btn'); if (btn.length) { btn.triggerHandler('click&apo ...

Utilizing jQuery for adding/removing classes, however, elements are not refreshed to show changes

I am dealing with a situation involving two elements, similar to two buttons placed side by side. I am dynamically toggling the class "focusd" to alter the highlighted effect. However, I have noticed a peculiar issue where the changes are not always proper ...

"Combining variables in programming: A step-by-step guide with a sample

When I press the first button, I expect to see random numbers displayed: 817 754 692 Pressing the second button '123:123' should show the numbers like this: 817:817 754:754 However, the output I am getting is: 817 754 :817 754 How can I com ...

The importance of context visibility for functions in JavaScript within a React.js environment

Why is it that the react state is visible in the function handleFinishChange, but cannot be seen in validationFinishTime? Both are passed to the component InputFieldForm. When executing this code, an error of Uncaught TypeError: Cannot read property ' ...

Choose an option from the dropdown menu and set both the value and

I have a seemingly silly question, but I am currently facing an issue. I have a select box <select class="valid sbi" name="FORM[rd]" id="rd" data-error=""> <option value="1">11</option> </select> and some data (text an ...

Creating a worldwide object in JavaScript

I am trying to create a global object in JavaScript. Below is an example code snippet: function main() { window.example { sky: "clear", money: "green", dollars: 3000 } } However, I am unable to access the object outside th ...

Having trouble with popovers after upgrading to bootstrap v4

I am facing an issue while trying to migrate Bootstrap from version 3 to 4. The problem specifically lies with popovers and the popper.js library. Each time I hover over an element, the following error is displayed: Uncaught TypeError: Cannot read property ...

Delete particular user inputs following a $.ajax request

I have created a search feature with inputs that allow users to search the database using ajax requests. Unfortunately, I am facing an issue where the response from the server includes the search inputs themselves. This is not what I want. Here's a ...

Modifying the font style of text within an HTML string using SQL Server

I need to standardize font sizes in my database where strings are stored as html and users can modify the font size. However, for generating reports, I require all font sizes to be consistent. If I have the following html code, how can I change the font si ...

Refreshing a webpage following an AJAX call

Whenever I make a post request to an API, I receive a response. However, even though the data is saved when I hit the API, I have to manually refresh my blade.php page to see the newly added data. Is there a way to automatically update my blade with the ...

Could anyone assist me in positioning my personalized Context Menu beside my cursor?

If possible, I would appreciate some assistance with my custom context menu. It may require some minor tweaks or a fresh idea on how to address the issue. Ideally, I would like to keep the HTML and CSS somewhat unchanged. [I'm not sure what to write ...