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:

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

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

I'm keen on creating a marquee animation using Tailwind and Next.js

I'm working on creating a marquee animation using Tailwind CSS and Next.js, and I've made some progress. However, the issue I'm facing is that the items are not displaying one after the other smoothly; there seems to be a delay when the seco ...

What is preventing this Node JS code from successfully serving a static PNG file?

To the administrators, I have spent hours scouring various resources for answers related to Node Js, Express, and serving static files. Despite my efforts on stackoverflow and other platforms, I have yet to find any solution that works for me. If my questi ...

Manipulate a table using Jquery's find() method to insert a cell populated with information from an array using before()

My current challenge involves inserting a column of cells with data from an array. Despite attempting to use a for loop, all the cells end up displaying the same data from the array. What I really want is for each new cell to show 'row_header1', ...

Having trouble with the Bootstrap float right class? Your buttons are refusing to respond?

Currently, I am experimenting with ExpressJS and EJS rendering. I have noticed that the Bootstrap float-right class is not working properly on the navbar. I even attempted using d-flex, but the issue persists. I am unsure if I am missing something in my co ...

Using AngularJS to incorporate ng-include with ng-click functionality

I am trying to figure out a way to insert HTML that is specifically optimized for the controller into an alert div. Unfortunately, I have been unsuccessful so far... <script type="text/ng-include" id="login.html"> <form data-select="exepti ...

Vue.js transition-group does not apply the *-move class

As I dive into learning Vue, I find myself wondering if I may have overlooked something fundamental or stumbled upon a bug. Despite multiple readings of the documentation at https://v2.vuejs.org/v2/guide/transitions.html#List-Move-Transitions, I still can& ...

What is the best way to dynamically shift the position of an image on a page while keeping it in place in real-time?

A group of friends and I are currently collaborating on an experimental project for a presentation. Our goal is to have multiple elements (such as images, text, gifs) displayed on a page that can be dragged around in real-time using a draggable script whi ...

a container holding two floating divs

I have been attempting to create two divs positioned side by side, with one containing content and the other acting as a sidebar. Both of these divs are contained within another larger container div. Despite my efforts, I have not been successful in achiev ...

What's the best way to vertically center a div with a 100% width and a set padding-bottom on the screen?

I am struggling with positioning the following div on my webpage. .div { width:100%; padding-bottom:20%; background-color:blue; } <div class="div"></div> I have been searching for a solution to vertically center this responsive div on my web ...

Using PHP and JavaScript to enhance functionality around a hyperlink

I am trying to incorporate a small piece of Javascript on my website to ensure user confirmation. While I have successfully used the 'onclick' function with buttons, I am facing difficulty implementing it on a link. Here is the link in question: ...

Attempting to fill a collection of JSON entities through a GET call?

When handling a GET request that contains a list of JSON objects, I want to display the data in an input field on the screen using ng-model for data binding. The structure of the JSON get request is as follows: [{"make":"Mahindra","vin":"1987","model":"XU ...

Uncover a section of text from HTML using the Beautiful Soup module

I have an HTML snippet like this: <span id="lbldiv" class="lbl" style="color:Blue;"> Division : First; Grand Total: 3861; Grand Max Total: 4600 </span> By using the get_text method on the span element, I can extract the text: Division : ...

The alignment of the text seem to be malfunctioning

The text-align:center property isn't working as expected. Can someone please assist me in figuring out why it's not functioning correctly? Here is the HTML code snippet: <!DOCTYPE html> <html> <head> <title>Wheat and ...

Unable to view sidebar navigation on the screen

I've been experimenting with the sidebar navigation from w3 schools, specifically trying to create a side-nav that opens from one div. You can see an example here: http://www.w3schools.com/w3css/tryit.aspfilename=tryw3css_sidenav_left_right&stack ...

Tips for customizing the color scheme of background, rows, row selection, and headers in Angular 4 using Bootstrap 4 data tables

I've integrated Bootstrap 4 data table in my Angular 4 project, but I'm struggling to customize row colors, row selection colors, and header colors. You can check out the example of the data table I'm using at this link: https://github.com/ ...

Stop the infiltration of emotions into your style

Utilizing the JsonForms React Component to dynamically generate an HTML form in my web application. The framework I am using handles all view rendering on the server side. To integrate this component, I compiled a small react component by running npm run b ...

Changing the Date Display format of a new Date() instance

Just starting out with the MEAN Stack I'm currently utilizing the new date() function to retrieve the date, but I prefer not to display the time offset. ...

What is the best method for validating multiple fields in a form with Javascript?

I am currently working on validating multiple fields within a form. Although I lack experience in JavaScript, I have managed to piece together a code that is functional for the most part. If all fields are left blank, error messages prompt correctly. Howe ...

How can an HTML5 application be configured to enable access to intranet and local files?

It's a known fact that accessing the local path of a file added using a file input field or drag-and-drop is not possible even with the new FileAPI. Whether this limitation is good, bad, or ugly is not up for debate. The FileAPI specs clearly state th ...

What is the best way to ensure that text fields remain hidden upon page load until the appropriate drop down option is chosen?

Is it possible to initially hide text fields and only reveal them when a specific drop down option is selected? The current JavaScript code somewhat achieves this, but I would like the input fields to remain hidden by default. <script language=" ...