The CSS div gradually descends as I increase the width of the browser

I'm in need of assistance with creating a website specifically for mobile devices and tablets. The issue I am facing is that when I expand my browser width to a tablet size, the "loginD" div shifts downwards - view this gif

Below is my HTML code:

<body>

<div id="bodyD">
    <div id="headD">
        <h1><App Name</h1>
    </div>
    <div id="loginD">
        <form runat="server" name="form1">
            <h2>Login</h2><br />
            <asp:Label ID="lblUsername" runat="server" Text="Account No" CssClass="aspLabel"></asp:Label><br />
            <asp:TextBox ID="edtUsername" runat="server" CssClass="aspText"></asp:TextBox><br />
            <asp:Label ID="lblPassword" runat="server" Text="Password" CssClass="aspLabel"></asp:Label><br />
            <asp:TextBox ID="edtPassword" runat="server" CssClass="aspText"></asp:TextBox><br />
            <asp:Button ID="btnSubmit" runat="server" Text="Login" CssClass="aspText" />
        </form>
    </div>
</div>

And here is my CSS code:

\* {
    margin: 0;
    padding: 0; }

body {
    width: 100%;
    height: 100vh; }

#bodyD {
    background-color: #fff;
    width: 100%;
    height: 100%; }

#headD {
    background-color: #414344;
    height: 15%;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px; }

#headD h1 {
    position: absolute;
    color: #dedfe0;
    font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
    font-size: 35px;
    margin-left: 5%;
    margin-right: 5%;
    padding-top: 5% }

#loginD {
    padding-top: 75%;
    margin-left: 5%;
    margin-right: 5%;
    position: relative; }

    #loginD h2 {
        color: #afafaf;
        font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        font-size: 30px;
    }

    #loginD .aspLabel {
        color: #afafaf;
        font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        font-size: 20px;
    }

    #loginD .aspText {
        font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
        font-size: 20px;
        width: 100%;
        border-radius: 5px;
        border: 1px grey solid;
        /*background: none;*/
        -webkit-appearance: none;
    }

#btnSubmit {
    color: #afafaf;
    margin-top: 10px;
    border: 1px grey solid;
    background: none;
    -webkit-appearance: none; }

Apologies for the formatting issue with the block code, I aim to keep the elements at equal heights while only expanding the width, which seems to be functioning correctly.

Answer №1

Take a look at this code snippet in your local environment.

\* {
  margin: 0;
  padding: 0;
}

body {
  width: 100%;
  height: 100vh;
}

#bodyD {
  background-color: #fff;
  width: 100%;
  height: 100%;
}

#headD {
  background-color: #414344;
  height: 15%;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

#headD h1 {
  position: absolute;
  color: #dedfe0;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  font-size: 35px;
  margin-left: 5%;
  margin-right: 5%;
  padding-top: 5%
}

#loginD {
  padding-top: 5rem;
  margin-left: 5%;
  margin-right: 5%;
  position: relative;
}

#loginD h2 {
  color: #afafaf;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  font-size: 30px;
}

#loginD .aspLabel {
  color: #afafaf;
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  font-size: 20px;
}

#loginD .aspText {
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  font-size: 20px;
  width: 100%;
  border-radius: 5px;
  border: 1px grey solid;
  /*background: none;*/
  -webkit-appearance: none;
}

#btnSubmit {
  color: #afafaf;
  margin-top: 10px;
  border: 1px grey solid;
  background: none;
  -webkit-appearance: none;
}
<body>

  <div id="bodyD">
    <div id="headD">
      <h1>
        <App Name</h1>
    </div>
    <div id="loginD">
      <form runat="server" name="form1">
        <h2>Login</h2><br />
        <asp:Label ID="lblUsername" runat="server" Text="Account No" CssClass="aspLabel"></asp:Label><br />
        <asp:TextBox ID="edtUsername" runat="server" CssClass="aspText"></asp:TextBox><br />
        <asp:Label ID="lblPassword" runat="server" Text="Password" CssClass="aspLabel"></asp:Label><br />
        <asp:TextBox ID="edtPassword" runat="server" CssClass="aspText"></asp:TextBox><br />
        <asp:Button ID="btnSubmit" runat="server" Text="Login" CssClass="aspText" />
      </form>
    </div>
  </div>

Answer №2

Convert the height option from percentage to pixels for better results. Using a fixed pixel value is recommended over percentage. Percentage values are dependent on the viewport of the device, so switching to pixels is a good idea.

#headD {
    background-color: #414344;
    height: 25px;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px; }

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

Setting a layout from the controller in .NET Core 3: A step-by-step guide

At the moment, I am in the process of upgrading from .NET MVC to .NET Core MVC. Within our current MVC framework, we have a method that is widely utilized and crucial to maintain. Can anyone assist me in figuring out how to set the Layout page from a .NET ...

I seem to have mistakenly duplicated some classes in my scss/css code

I need some assistance. I'm experiencing an issue where my SCSS/CSS classes are being repeated, causing my browser to slow down. My tech stack includes: ReactJS, Webpack, and a Sass structure with an Assets folder. https://i.sstatic.net/obmIJ.png ...

Switch Button Hyperlink in HTML/CSS

I have the following code: document.addEventListener("DOMContentLoaded", function(event) { (function() { requestAnimationFrame(function() { var banner; banner = document.querySelector('.exponea-banner3'); banner.classList ...

"Exploring the Dynamic Combination of ASP.NET Core 5.0 and Bootstrap 5.0:

I have been attempting for the last 6 hours to design a static non-collapsible sidebar using Bootstrap 5.0, but unfortunately, I have been unsuccessful so far. <!DOCTYPE html> <html lang="en"> <head> <meta charset="u ...

What could be causing the issue with the focus not being activated when clicking on the input field in Vue?

I am facing an issue where I have to click twice in order to focus on a specific input field, and I'm having trouble setting the cursor at the end of the input. I attempted to use $refs, but it seems like there may be a deeper underlying problem. Any ...

Adjust and position any svg element to fit the entire viewport

Forgive me for being just another person to ask this question. Despite my efforts, I have yet to find a solution. I am trying to resize "any" svg to fit the entire viewport, centered. Take for example this svg element: <svg baseProfile="full& ...

Preventing Content Jumping When Concealing Elements: Tips and Tricks

I've been working on a project at , where you can click on a small map to expand a larger map below it. However, I noticed that when you scroll down to the large map and then try to close it using the button at the bottom, the content on the page jum ...

How to enhance your jQuery Gallery with clickable images?

I have recently integrated a jQuery Gallery into my website. While everything is functioning properly, I am looking to transform the gallery images into clickable links that lead to higher quality versions of the images. Below is the code snippet for the g ...

How can I stack a div on top of two columns in Bootstrap?

My goal is to design something like this: I want to have a single-color strip that extends over three columns: https://i.sstatic.net/1XfAu.png What I am aiming for is a layout where the grey line overlaps columns 2 and 3. /* added by editor for demo p ...

Tips for creating a button-like anchor in Bootstrap 4

After using a button in Bootstrap 4, it appears as follows: https://i.sstatic.net/laGLo.png <button type="button" class="btn btn-primary" target="_blank">Download</button> On the other hand, when I substitute an anchor with the same button s ...

Here's a guide on how to retrieve the element type or tag type in Selenium using C#

Let's say we have a tag like this: <a class = "fp-anchor fp-forgot-password pull-right" href = "/Account/ForgotPassword">Forgot Password?</a> == $0 In order to determine the type of element, we need to identify if it is a hyperlink. For ...

Is there a way to open Internet Explorer using a specific URL from a different browser?

Imagine a scenario where a visitor lands on www.mysite.com using MS Edge. Instead of staying in Edge, I would like the page to recognize that Edge is being used and automatically launch Internet Explorer with the same URL. Is there a way to achieve this? ...

Lost in a sea of confusion with ember-cli-postcss and autoprefixer

I'm currently working on an ember build that incorporates autoprefixer. My issue arises from the fact that the output location for 'assets/application-name.css' has shifted from its normal path to 'app/styles/app.css', and I would ...

Guide to optimizing the display of a responsive iframe across various devices such as mobile and desktop

I have implemented the following CSS in an iframe to make it responsive. It works well on desktop browsers, but on mobile browsers, the iframe only displays half of the screen. Can you please review the code below and provide guidance on how to fix this is ...

Challenges with Implementing Background Images on my Website with HTML and CSS

Being new to the world of coding, I recently created a website for a college presentation. However, after uploading the website onto the internet, I noticed that the background images from my files are not displaying on the website. It's likely that I ...

What could be causing my update panel to malfunction?

My update panel currently contains a checkbox and a panel. The checkbox's auto postback property is set to true, and my goal is to make the panel visible when the checkbox is checked. However, whenever I click on the checkbox, the page gets refreshed. ...

Scrolling the inner container in a CSS flexbox layout: tips and tricks

I'm currently working on designing a flex box based HTML layout like the one shown in the image link provided below. https://i.stack.imgur.com/nBl6N.png The layout should consist of 3 rows within the viewport with the following structure: - top: " ...

Is there a way to modify the CSS display property upon clicking a link or button?

I have a ul with the id of "menu-list". The display property is set to "none" in my CSS file, but I want it to switch to "flex" when a link is clicked. I am trying to use the click event on the link to change the display prop ...

Automatically populate the next dropdown menu depending on the answer provided in the previous field

Can you help guide me in the right direction with 2 questions I have? If the answer to the first question is 1, then I would like the following answer to automatically be populated as Yes. Please assist me! <div class="field"> <!-- Number of Em ...

Creating a disabled HTML button that reacts to the :active CSS pseudo class

CSS: button:active { /* active css */ } button:disabled { opacity: 0.5; } HTML: <button disabled="disabled">Ok</button> After clicking the button, the browser applies the button:active state to give the appearance of a click, despite the ...