Tips for fixed positioning of a div on a webpage without being affected by the Windows logo shortcut keys + Left/Right arrow

Whenever I utilize the keyboard shortcuts to move a window from one side of the screen to another and then minimize it either upwards or downwards, I find myself faced with an issue. I can accomplish this action by using the Windows key in combination with the Left/Right arrow keys, followed by the Up/Down arrow keys. Alternatively, when employing the mouse and positioning the cursor at any edge or corner of the window until a double-headed arrow appears, allowing for custom resizing.

I desire the white-container box (div) to always remain centered on the page.

To begin, I am attempting to design a login page that mirrors the example shown in the provided image, with the exception of the background:

As my current screen resolution is 1920x1080p, I am uncertain whether my coding choices involving the div element or classes will function correctly across other resolutions.

Edit: The background picture I am utilizing is also 1920x1080p.

body {
    background-image: url(../images/website-login-background.jpg);
    background-size: initial;
    background-repeat: no-repeat;
    resize: initial;
    font-family: Arial;
}
.white-container {
    margin-top: 25%;
    margin-left: 36%;
    /* width: max-content; */
    width: 28em;
    height: 28em;
    background-color: white;
    text-align: center;  
}
h1 {
    padding-top: 2em;
    font-size: 1.8em;
    font-weight: normal;
  }
 .form-menu {
    font-size: 1em;
    height: 2em;
    width: 100%;
    text-align: center;  
 }  
.input {
    font-size: 1em;
    height: 2em;
    width: 80%;
}
.linkaAttr {
    overflow: hidden;
    color: blue;
    padding-left: 50%;
}
<body>
    <div class="white-container">
        <header>
            <h1>Log In to Your Account</h1><br>
        </header>
        <form class="form-menu" action="#">
            <input class="input" type="text" name="iD" placeholder="&emsp;Email or phone or username"><br><br>
            <input class="input" type="password" name="pass" placeholder="&emsp;Password"><br><br>
            <div class="linkaAttr">
                <a href="#">Forgot password?</a><br><br><br>
            </div>
            <input class="input" type="submit" style="background-color: rgb(30, 151, 213); color: white" value="Log In"><br><br><br>
            <p style="color: gray">Need an account?&emsp;<a href="#">Sign Up</a></p>
        </form>  
    </div>
</body>

In my current setup, when I resize the window using keyboard shortcuts to manipulate its position, the option to scroll within the window becomes available, which is unnecessary. The white div is not fully visible, necessitating scrolling to view its entirety. Additionally, it fails to maintain its central alignment upon resizing the window in this manner.

In the desired outcome, the white container should occupy the minimum size possible on the page, remaining centered even during resizing done using the mouse. When utilizing the keyboard for resizing purposes, the div must be prominently displayed and centered regardless of the window size.

Answer №1

To simplify and improve accuracy, consider utilizing flexbox. The following code snippet can serve as a starting point for you :)

body {
  background-image: url('http://placehold.it/600x400/fff000');
  background-size: cover;
  background-repeat: no-repeat;
  resize: initial;
  font-family: Arial;
  /* Implementing Display Flex*/
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  margin: 0;
  padding: 0;
}

.white-container {
  width: 28em;
  height: 28em;
  background-color: white;
}

h1 {
  padding-top: 2em;
  text-align: center;
  font-size: 1.8em;
  font-weight: normal;
}

.form-menu {
  font-size: 1em;
  height: 2em;
  width: 100%;
  text-align: center;
}

.input {
  font-size: 1em;
  height: 2em;
  width: 80%;
}

.linkaAttr {
  overflow: hidden;
  color: blue;
  padding-left: 50%;
}
<div class="white-container">
  <header>
    <h1>Log In to Your Account</h1><br>
  </header>
  <form class="form-menu" action="#">
    <input class="input" type="text" name="iD" placeholder="&emsp;Email or phone or username"><br><br>
    <input class="input" type="password" name="pass" placeholder="&emsp;Password"><br><br>
    <div class="linkaAttr">
      <a href="#">Forgot password?</a><br><br><br>
    </div>
    <input class="input" type="submit" style="background-color: rgb(30, 151, 213); color: white" value="Log In"><br><br><br>
    <p style="color: gray">Need an account?&emsp;<a href="#">Sign Up</a></p>
  </form>
</div>

Answer №2

To center the div in the white-container, you can utilize margin: 0 auto regardless of the screen size.

body {
    background-image: url(../images/website-login-background.jpg);
    background-size: initial;
    background-repeat: no-repeat;
    resize: initial;
    font-family: Arial;
}
.white-container {
    margin: 0 auto;
    /* width: max-content; */
    width: 28em;
    height: 28em;
    background-color: white;
    text-align: center;  
}
h1 {
    padding-top: 2em;
    font-size: 1.8em;
    font-weight: normal;
  }
 .form-menu {
    font-size: 1em;
    height: 2em;
    width: 100%;
    text-align: center;  
 }  
.input {
    font-size: 1em;
    height: 2em;
    width: 80%;
}
.linkaAttr {
    overflow: hidden;
    color: blue;
    padding-left: 50%;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="js_formname_formelementname.css">
</head>

<body>
    <div class="white-container">
        <header>
            <h1>Log In to Your Account</h1><br>
        </header>
        <form class="form-menu" action="#">
            <input class="input" type="text" name="iD" placeholder="&emsp;Email or phone or username"><br><br>
            <input class="input" type="password" name="pass" placeholder="&emsp;Password"><br><br>
            <div class="linkaAttr">
                <a href="#">Forgot password?</a><br><br><br>
            </div>
            <input class="input" type="submit" style="background-color: rgb(30, 151, 213); color: white"
                value="Log In"><br><br><br>
            <p style="color: gray">Need an account?&emsp;<a href="#">Sign Up</a></p>
        </form>
    </div>
</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

Solving the Angular form glitch: error message not displaying

I am facing an issue with my simple form where I am not able to display errors related to the fields. <html lang="en" ng-app="MyApp"> <head></head> <body ng-controller="AppCtrl"> <form name="myForm" id="myForm"& ...

Bringing together embedded chat and stream seamlessly with CSS styling

I'm in the process of integrating a chat feature with my Twitch stream on a Xenforo forum page. I aim for the stream to be displayed in 16:9 aspect ratio to ensure high definition quality, and I want it to adapt to the user's screen resolution. B ...

Utilize Bootstrap to switch between 'collapse' and 'collapse in' depending on the device being used

I have a collapsible panel set to default "expand" (collapse in) and it is working well. However, I would like to make it "collapse" (shrink) for mobile and tablet devices. Is there any built-in feature in Bootstrap that can help me achieve this? <div ...

What is the correct way to link an image path to my PHP script?

I am currently working on a project as a student where we created a MySQL database named Video_Game_Shop. Our task is to connect this database to a website using PHP and HTML, and display all the games listed in our database on one page. To achieve this, ...

When scrolling, the text or logo inside the navbar seems to dance with a slight wiggling or

I recently implemented a code to create a logo animation inside my navigation bar that expands and contracts as I scroll, inspired by the functionality of the Wall Street Journal website. However, this implementation has caused some unintended side effects ...

Text within the div element causes the displacement of other adjacent div elements

When the text in mondaySpecial extends to a second line, it pushes tuesdaySpecial-saturdaySpecial further down on the page, disrupting the layout of the divs. The same issue occurs with other specials as well. Is there a way to prevent this from happening? ...

Is there a way for me to display a gif similar to 9GAG on my

I'm looking to implement a feature on my website that allows me to pause and play a gif, similar to the functionality on 9gag. Can anyone provide guidance on how I can achieve this? I understand that I need to use both .jpg and .gif files, but my at ...

What separates $(document).ready() from embedding a script at the end of the body tag?

Can you explain the distinction between running a JavaScript function during jQuery's $(document).ready() and embedding it in the HTML within script tags at the bottom of the body? Appreciate your insights, DLiKS ...

Managing the intersection of div elements

Can someone help me make the inner part of the red circle white, overlapping with the blue circle and transparent for the rest to reveal the green color underneath? If anyone has a solution, I would greatly appreciate it. #bigCircle { display: flex ...

Display or conceal various objects using a single button in HTML

I've been working on creating a chatbot widget for my website, but I've run into an issue. The "Chat with us" button only shows the bot and not the close button as well. Here's what I've attempted: <input id="chat" type="button" on ...

How come my image is not aligned to the right of the header in my HTML code?

My attempt to align an image to the right side of my heading using code was unsuccessful. Here is the HTML snippet I used: /* Aligning with CSS */ #colorlib-logo img { display: flex; align-items: center; width: 30px; height: 30px; } #colorli ...

Conceal a list of items within a div that has a particular class

This is a sample of my HTML code: <div class="row"> <div class="col-md-12"> <div class="scrollbox list"> <ul class="list-unstyled"> <li id="articulate.flute">articulate flut ...

Is it possible to drag the div container in HTML to resize its width from both left to right and right to left?

After posing my initial inquiry, I have devised a resizing function that allows for the expansion of a div's width. When pulling the right edge of the div to resize its width from left to right, is it possible to adjust the direction or how to resize ...

Ways to improve the quality of a blurred photo

I've recently put together a test landing page using bootstrap: Upon visiting the site and viewing the iPhone screenshot, it's clear that the text on the screen is quite blurry. Interestingly, by simply resizing the browser window and then maxi ...

Why isn't the Full Calendar loading automatically within a Bootstrap Tab?

I have been working on a travel website and incorporated a bootstrap tab feature. In the first tab, I have some content, while in the second tab, I've added a full calendar with JavaScript. Everything seems to be functioning correctly when the full ca ...

conceal the mustard-colored dots within the overlay

Whenever I trigger the link, a modal window pops up, but it comes with an unwanted black background color and yellow dots. How can I prevent the yellow dots from showing up on the overlay? http://jsfiddle.net/y88WX/18/embedded/result/ <nav class="da-d ...

Send form data without reloading the page and connect it to a JavaScript script

I've designed a system that reveals values based on a specific input selection. Below is the main form where users can enter model numbers and press enter: <form> <input type="text" name="ModNum" id="ModelNumber" pattern="^PIV13RT[23]?$" ...

What steps can I take to troubleshoot and repair my accordion feature within an Angular project?

As a newcomer to Angular, I recently attempted to create an accordion component but encountered unexpected behavior. Here is the HTML code for my attempt: <div class="faq-item-container"> <h1 class="mt-1 mb-5"><strong>Frequently A ...

What is the best method for converting a variable with HTML content into a printable string?

In an attempt to display user-entered data from a text box to an HTML div, there seems to be an issue when the data contains HTML content. Instead of displaying the content as a string, it shows it as HTML elements. For example: let text = "<h1>Worl ...

Tips for managing three select menus in AngularJS

Assistance needed for creating a series of interconnected dropdown menus in AngularJS. The functionality should allow the second dropdown to open upon selecting a value in the first dropdown, and the third dropdown to open upon selecting a value in the sec ...