I would like the background image to perfectly fit the dimensions of the parent container

https://i.sstatic.net/PlCYU.png

Is there a way to prevent the background image from overflowing and causing a horizontal scroll bar to appear? The layout of the page consists of two columns, with each column taking up 50% of the width. The left column contains the login form, while the right side displays the background image and logo. Bootstrap 5.3 is also being used for styling.

Below is the code snippet:

<!DOCTYPE html>
<html lang="en>
<head>
    <?php include_once './include/head.php'?>
    <title>Login</title>
    <style>
        .login-form-section {
            display: grid;
            place-items: center;
        }

        .photo-logo-section {
            background-image: url("./assets/images/bu-bg.jpg");
            background-size: cover;
            background-position: center center;
            background-repeat: no-repeat;
            overflow: hidden;
        }

        #dark-hue {
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            mix-blend-mode: multiply;
        }
    </style>
</head>
<body>
    <main class="row" style="height: 100vh;">
        <section class="login-form-section col-lg-6">
            <form action="" method="post">
                <div class="form-group w-100">
                    <label for="email">Email</label>
                    <input type="email" id="email" name="email" class="form-control" required>
                </div>
            </form>
        </section>

        <section class="photo-logo-section col-lg-6">
            <div id="dark-hue"></div>
        </section>
    </main>
</body>
</html>

Answer №1

The issue doesn't lie in the image itself but rather in the default gutter that Bootstrap includes with the .row class. To eliminate these gutters, you can add the .g-0 class along with the .row:

<main class="row g-0" style="height: 100vh">
 ...
</main>

Below is a functional example. Make sure to check it out in full screen mode:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Login</title>
    <link
      href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b0904041f181f190a1b2b5e455b4559">[email protected]</a>/dist/css/bootstrap.min.css"
      rel="stylesheet"
      integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
      crossorigin="anonymous"
    />
    <style>
      .login-form-section {
        display: grid;
        place-items: center;
      }

      .photo-logo-section {
        background-image: url('https://source.unsplash.com/VWcPlbHglYc');
        background-size: cover;
        background-position: center center;
        background-repeat: no-repeat;
        overflow: hidden;
      }

      #dark-hue {
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        mix-blend-mode: multiply;
      }
    </style>
  </head>
  <body>
    <main class="row g-0" style="height: 100vh">
      <section class="login-form-section col-lg-6">
        <form action="" method="post">
          <div class="form-group w-100">
            <label for="email">Email</label>
            <input
              type="email"
              id="email"
              name="email"
              class="form-control"
              required
            />
          </div>
        </form>
      </section>

      <section class="photo-logo-section col-lg-6">
        <div id="dark-hue"></div>
      </section>
    </main>
  </body>
</html>

Answer №2

The issue was resolved by applying the 'container-fluid' class to the main container and inserting a div with a 'row' class.

Check out the modified code snippet below:

<!DOCTYPE html>
<html lang="en">
<head>
    <?php include_once './include/head.php'?>
    <title>Login</title>
    <style>
        .login-form-section {
            display: grid;
            place-items: center;
        }

        .photo-logo-section {
            max-width: 50%;
            background-image: url("./assets/images/bu-bg.jpg");
            background-size: cover;
            background-position: center center;
            background-repeat: no-repeat;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <main class="container-fluid">
        <div class="row" style="height: 100vh;">
            <section class="login-form-section col-lg-6">
                <form action="" method="post">
                    <div class="form-group w-100">
                        <label for="email">Email</label>
                        <input type="email" id="email" name="email" class="form-control" required>
                    </div>
                </form>
            </section>

            <section class="photo-logo-section col-lg-6">
                <div id="dark-hue"></div>
            </section>
        </div> 
    </main>
</body>
</html>

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

Issues with message display validation in jQuery

Validation has been applied to the form, and there are div elements within the input fields with corresponding IDs. The goal is to display error messages within those divs. Specifically, if an input field is missing, the errorMessage should be set in the ...

Using Javascript or Jquery, you can submit a form without the need for a button

I'm attempting to submit a form without using a button by invoking a JavaScript function and processing the form with JQUERY/PHP. My goal is for the form to be submitted silently on the backend without causing the page to reload. However, I keep encou ...

What is the method to incorporate spread into inner shadow within an SVG file?

Seeking assistance with creating an inset-shadow effect with spread for an SVG rectangle in Figma. Check out this example of a rectangle with inner-shadow and spread. I have successfully added blur and positioned the shadow using x and y coordinates, but ...

Activate night mode in ElementPlus using CDN

Is there a way to set the theme to dark in ElementUI + Vue when using CDNs instead of npm? <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width,initial-scale=1.0" /> ...

Clickable div containing a hyperlink

I need assistance with a clickable div that contains a link. Here is the setup: HTML: <div onClick="goToCat(2);" class="author-topics-block "> <a href="http://mywebsite/page/?cat=2">The woman in steel</a> </div> CSS: .author ...

Is there a way to achieve a XNOR-like response with necessary input?

I'm currently working with a form that looks like this: <form> <input type="text" name="input1"> <input type="text" name="input2"> <button type="submit"> ...

What are the steps for implementing responsive design animation in my particular scenario?

Can someone please help me with a strange bug in Chrome? I am trying to create a responsive design for my app. The width of the 'item' element should change based on the browser's width. It works fine when the page first loads in Chrome, b ...

Are there any alternative methods to avoid duplication of Navbar link margin classes in Tailwind CSS?

It feels really repetitive to have to add margin classes to each LI manually on a non-dynamically generated menu. It almost seems as messy as using inline style attributes... Is there a more efficient way to handle this? While it may not be a big deal fo ...

What could be causing my React button to stop functioning as a link to an external website when using anchor tags?

I recently created some buttons for my website using React. Initially, everything was working perfectly with the buttons, but suddenly they stopped functioning. Strangely, I didn't make any alterations to the code and I'm puzzled as to why they a ...

Creating personalized static HTML cards with PHP Mirror API for Google Glass

Looking to integrate an HTML formatted card into Google Glass timeline using the Mirror API. Utilizing the PHP PHP Mirror Client API, which accepts a message and image as parameters, displaying the image in the background similar to this example: insert ...

Form submission causing page to reload, getElementById function fails to return value, rendering form ineffective

The objective of this code snippet is to extract data from a form using IDs and store it in an array object named studRec. The entire process is intended to be carried out on the client-side in order to preserve the data for future use in other functions. ...

Refine the search outcomes by specifying a group criteria

I have a scenario where I need to filter out service users from the search list if they are already part of a group in another table. There are two tables that come into play - 'group-user' which contains groupId and serviceUserId, and 'gro ...

Set a class for the nth table row

I'm trying to find a solution using jQuery where I can assign different classes to each <tr> in a table. For the first row, I want to add class='alt', for the second row class='alt-2', and for the third row class='alt-3& ...

"Customize the appearance of ng-bootstrap datepicker selection with a unique

Having trouble with the ng-bootstrap datepicker when selecting style for month and year. https://i.sstatic.net/grlK6.png The issue seems to be with the select style. select[_ngcontent-c21] { -ms-flex: 1 1 auto; flex: 1 1 auto; padding: 0 .5re ...

Responsive CSS design that adjusts to fit the content

Struggling to make the wrapper expand with its content... This is the structure: * { padding: 0; margin: 0; } body { background-color: #ccc; background-repeat:repeat; font: Tahoma, Geneva, sans-serif; color: #FFF; } .wrapper { width: 95%; margin: 0 au ...

How can you make an object float above an image using CSS?

Is CSS capable of positioning an object over an image? I am trying to overlay a form on top of an image that is not a background. Floating the form doesn't achieve the desired effect, so I'm wondering if there is another way to accomplish this. ...

Combining Files in Angular 2 for Optimal Production Deployment

What is the best method for packaging and combining an Angular 2 application for production? My goal is to have an index.html file and a single app.min.js file. Although the Angular 2 documentation mentions using webpack, I found it to be overly complex f ...

Unexpected display issues with CSS shapes in Bootstrap framework

Been experimenting with creating custom shapes in Bootstrap - they display correctly in HTML and CSS, but Bootstrap distorts them. It seems like there are no conflicting classes. Could it be necessary to use '!important' on some of the elements? ...

The background refuses to cooperate, soaring upward only to be abruptly sliced in two

I am in the process of creating a website login window with an image background, but I'm experiencing issues where the image is being cut in half and moved up. Here is the code snippet I am currently using: .loginbody { background: url(img/LoginB ...

Labels can sometimes cause text input fields to become unresponsive

I've encountered a bug while working on my website with the materializecss framework. Sometimes, inputs are not responding correctly. This issue seems to occur when clicking on the first input and accidentally targeting the higher part of the second ...