Troubleshooting a login page design issue in Bootstrap with flex containers and background image display

Recently, I've been facing some challenging issues.

I'm attempting to design a login page with a basic layout:

For screens wider than 800px:

  • Two columns
  • The left side will feature a logo, login form, text box, and button. No background image.
  • The right side will display a div with a background image.

For screens equal to or less than 800px wide:

  • A single column containing the logo, login form, text box, and button.
  • The background image shown on the right side of larger screens should be the background image for this single column on smaller screens.

HTML file

<div class="flex-container">
<div class="col-lg-4 index-top">
    <div class="row">
        <div class="col log-in">
            <div class="col no-padding">
                <h1>
                    <img src="/img/AnonimowySygnalista.svg" alt="logo Anonimowy Sygnalista" class="logo-login" />
                    <span class="sr-only hidden">Anonimowy sygnalista</span>
                </h1>
                <form action="">
                    <label for="">UserName</label>
                    <input type="" id="" name="" placeholder="Enter username" class="input"></input>
                    <input type="submit" value="Log In" class="btn-primary"></input>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="col-lg-8 col background-img">
</div>

CSS file

.container {
    display: block;
    padding: 0;
    margin: 0;
}
.flex-container {
    display: flex;
    flex-direction: column;
}
input, textarea {
    display: block;
}
.right {
    float: right;
}
.left {
    float: left;
}
.clear {
    clear: both;
}
label {
    font-weight: 700;
    margin-bottom: .75rem;
}
.btn-primary {
    background-color: #1F7AAB;
    border-radius: 4px;
    border-color: #1F7AAB;
    padding: .5rem 1.5rem;
    width: 100%;
    box-shadow: none;
    color: #fff;
}
.background-img {
    background-image: url('../img/pexels-vlada-karpovich-4050312.jpg');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    margin-top: -1.25rem;
}
.input {
    margin-bottom: 1.5rem;
    max-height: 5rem;
    padding: .5rem .5rem .5rem .75rem;
    border: 1px solid #767676;
    box-sizing: border-box;
    border-radius: 4px;
    width: 100%;
}
.log-in h1 {
    margin: 3rem 0;
}
.index-top {
    z-index: 999;
}
@media (min-width: 801px) {
    .container {
        width: 100% !important;
    }
    .flex-container {
        padding-right: 80px;
        flex-direction: row;
    }
    .index-top {
        margin: 0 80px;
    }

Answer №1

If you want to layer elements on top of one another, try using position : absolute

You can achieve this by applying the code to .background-img within @media queries. Additionally, don't forget to utilize the z-index CSS property to control the stacking order of elements

Answer №2

It seems that you are interested in displaying the background image on the right side for larger screens and behind the form for smaller screens.

An easy way to achieve this is by adding a CSS class called .bg-sometimes to the small column on the left side. This class will be set to display a background image. Then, using @media (min-width: 801px), you can set background-image: none; to prevent the image from showing on larger screens.

The following code example illustrates this implementation effectively:

/* CSS Code Here */ 
<link href="Link to Bootstrap CSS File" rel="stylesheet"/>
<div class="flex-container">
    <div class="bg-sometimes col-lg-4 index-top">
        <div class="row">
            <div class="col log-in">
                <div class="col no-padding">
                    <h1>
                        <img src="URL to Logo Image"
                             alt="Logo Description" class="logo-login"/>
                        <span class="sr-only hidden">Hidden Text</span>
                    </h1>
                    <form action="">
                        <label for="">UserName</label>
                        <input type="" id="" name="" placeholder="Enter Username" class="input"></input>
                        <input type="submit" value="Log In" class="btn-primary"></input>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="col-lg-8 col background-img">
    </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

Starting a div programmatically and then running into trouble when trying to close it, an error was encountered with an end tag for "div" without a corresponding start tag

I am looking to create the following HTML structure: <div id="my-grid" class="isotope"> <div class="myProject-item">....</div> <div class="myProject-item">....</div> <div class="myProject-item">....</div> ...

The absence of a scroll bar on the web application is preventing me from scrolling properly

The vertical scroll bar on my Angular app seems to have disappeared mysteriously. I haven't made any changes to the code recently, and I'm struggling to figure out why it's missing. I've spent days trying to troubleshoot this issue with ...

"Text that appears on a clear background when you hover over it

I'm attempting to have hidden text display inside a table cell upon hovering. I managed to achieve the hidden-until-hovered effect, but I am struggling to make the text appear solid in color (it currently decreases in opacity when hovered over). Is th ...

What is the best way to trigger an AJAX function by clicking a submit button?

On my website, I am experimenting with a form and JavaScript function. This is just a test to see if it's possible for me to achieve what I want. What I'm trying to accomplish is to make a form send an AJAX request to the server so that the data ...

In React, the entire component refreshes every time the modal is opened

<ThemeProvider theme={theme}> <GlobalStyle /> {componentName !== 'questionaire' && componentName !== 'activityResult' && <CardWrapper />} <ErrorModal ...

Tips for styling a central menu using CSS

I am having trouble centering my menu on the website. While other elements like images are centered, the menu seems to be off-center. Below is a snippet of the CSS code related to the menu: @charset "UTF-8"; /* CSS Document */ #nav { width:975p ...

PHP encounters a Parse error due to a syntax error, where an unexpected character is present

In my new system, employees have the ability to check their leave status. I am currently working on a feature where this leave status will only be visible for logged-in users. One issue I encountered is that when user John Doe is logged in, I can still se ...

How can I make the Box div bigger or smaller?

My goal is to expand and collapse the slider div only for the box where the user clicks. I have achieved this functionality, but a problem arises when I click "read more" - all the boxes expand, which is not the desired behavior. I want only the specific b ...

Error in Google Tag Manager: Expecting primary expression

I am encountering an issue that reads: Error at line 5, character 2: Parse error. primary expression expected This is the format of the custom HTML code: <script type="text/javascript"> //insert your Tawk embed code here, without Script tags < ...

Adjust the Highcharts semi-pie design by eliminating the gap between the pie and the legend

I'm having trouble adjusting the spacing between the bottom of a semi circle donut chart in Highcharts and the legend below it. Despite my efforts, I have not been successful in reducing this gap. Here is the basic chart I am currently working on: h ...

How wide can we make the Outerbounds in the Chrome app?

My setup includes a chrome box that can accommodate two monitors. I am interested in creating a single chrome app with dimensions of 3840x1080 (width =3840, height =1080) to cover both screens. I attempted this but was unsuccessful. Are there any alterna ...

Utilizing CSS for customizing selectors in a Moodle form

In my Moodle 3.0 form (using formlib.php in Moodle), I have created a selector that I would like to customize with different colors. Here is an example of the selector code: $mform->addElement('header', 'ChartOptions', get_string(&a ...

Develop a custom chat feature in HTML with the powerful VueJs framework

Currently, I've been developing a chat plugin for HTML using VueJs. My dilemma lies in creating a versatile plugin that can seamlessly integrate into any website. My ultimate goal is to design a plugin that can be easily deployed on various websites ...

What is the best approach to bring a button into focus after it has been enabled in a React.js application

I'm a beginner in react js and I'm attempting to set the focus on a button after filling out all input fields. However, despite programmatically enabling the button with autoFocus implemented, I am unable to focus on it. return ( < ...

Fade effect on content in Bootstrap carousel

I am currently making some updates to the website mcelroymotors.com. One issue I have encountered while working on the homepage carousel is that the caption only pops up on the first slide, and does not appear on any of the subsequent slides. I would lik ...

Empty input fields in Javascript calculations will result in a NaN output

I need to perform a calculation using values entered into form fields and JavaScript. The formula I'll be using is as follows: totalEarnings = income1 + income2 * 0.7 + income3 / 48 + (income4 * 0.7) / 48; The variables income1, income2, income3, an ...

What is the process for adding a 3D object to a webpage and making it interactive with movement?

Hello, I am new to web development and apologize for my limited English skills. I have a specific challenge that I need help with: How can I create a 3D plane on a web page using HTML5 and make it interactive, such as flying or moving within a designated ...

jQuery is unable to retrieve the parent element of a dynamically generated element as it returns as undefined

I have created login and registration forms using ajax calls to send data. The server side of the application is built with Flask, and any errors are returned in JSON format. In the success function of the ajax call, I create an <li> element that dis ...

Tips for triggering a method when clicking instead of using v-for in Vue.js

I need help arranging an array of objects based on their ratings. Currently, I am able to display the items from highest to lowest rating using the v-for method. But, I would like to first display the objects in their original order and then have a button ...

The click event will only be triggered when a specific div is clicked within the

Here is some code I am working with: document.onclick = function () { console.log("Hello"); } <div class="label-search">Click me</div> I am trying to make it so that the console.log only executes when I click on the div class="label-sear ...