Adapting the top margin dynamically for different screen sizes

I am attempting to style an HTML DIV so that the margin-top is adjusted responsively based on the height of the div: jsfiddle

Within the wrapper, there is another div that is initially set to display: none, but this may change if the user enters an incorrect password. The issue is that there is a div below it that gets pushed down when display: content is applied to the second div. I would like the page content to move upwards responsively instead of downwards.

Current view: https://i.sstatic.net/ycWLG.png

Desired view: https://i.sstatic.net/VFIJh.png

Answer №1

Based on the example provided, your objective, and your preference to avoid using flexbox for compatibility with IE10, I suggest utilizing display: table for the container in question.

By employing this approach, you can utilize the vertical-align properties within the "table-cell".

Feel free to explore the demonstration below. I have included a toggle button for showcasing the visibility of your captcha. For the best experience, you may want to view it in full screen.

$("#toggle").on('click', function() {
  $(".captcha").toggle();
});
html,body {
  height: 100%;
}
.outer-wrapper {
  height: 100%;
  width: 100%;
  background: #eeeeee;
  display: table;
}

.inner-wrapper {
  height: 100%;
  width: 100%;
  display: table-cell;
  vertical-align: middle;
  height: inherit;
}

.login-wrapper {
  background-color: #172238;
  color: white;
  width: 200px;
  text-align: center;
  height: auto;
  display: block;
  margin: 0 auto;
}

.captcha{
  margin-top: 250px;
  display: content; // This one changes
}

.homologation-line {
  min-width: 200px;
  background-color: #ffd800;
  color: black;
  text-align: center;
  height: 30px;
}

#toggle {
 position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="toggle">toggle captcha</button>
<div class="outer-wrapper">
  <div class="inner-wrapper">
      <div class="login-wrapper">
        <p>Login</p>
        <div class="captcha">
          ENTER THE DIGITS:
        </div>
    </div>
    <div class="homologation-line">
       HOMOLOGATION
    </div>
  </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

Adjustment of Image Placement

I'm describing my desired outcome briefly - I want the inputs in the code to appear in the top left corner of a large image. Despite trying multiple approaches, I have been unable to achieve this layout. When considering 2 columns, the inputs should b ...

Difficulty with alignment in the process of generating a vertical stepper using HTML and CSS

I'm currently working on developing a vertical stepper component using html & css with inspiration from this design. However, I've encountered some alignment issues in the css that I'm struggling to resolve. CSS .steps-container .step::b ...

Hero Sticky Transition with 100vhDivElement

My code is giving me some trouble. I want the div with text to stay at the bottom of the hero section with a transparent background. When that div reaches the top, it should stick with a black background. The issue is that I have set it in the javascript v ...

Is there a way to recycle an image and ensure that the web browser only needs to download it once?

Is there a way to effectively reuse the same image multiple times on my website without inefficiently downloading it each time? ...

The animation did not cause a transition to occur

After creating a search modal triggered by jQuery to add the class -open to the main parent div #search-box, I encountered an issue where the #search-box would fade in but the input did not transform as expected. I am currently investigating why this is ha ...

What is the best way to make an element disappear 5 seconds after the mouse has stopped hovering

#section1 { display: block; } #section2 { display: none; } #container:hover > #section2 { display: block; } <div id="container"> <div id="section1">Section1</div> <div id="section2">Section2</div> </div> ...

In landscape mode on Safari for iOS, the final item in a vertical flexbox may be cut off

Describing my app: It is structured as a 3-row flexbox column. <div class="app" style="display: -webkit-flex; -webkit-flex-direction: column; -webkit-justify-content: space-around;"> <div class="question-header" style="-webkit-flex: 0 0 0;"&g ...

Issue with Django app: Bootstrap 4 modal hidden behind background

Having exhaustively researched this issue, I am still unable to resolve it with the outdated Bootstrap solutions available. The problem arises when I click on the button - the modal appears behind the background instead of in front. Most suggestions indica ...

What is preventing me from adding any style to this specific element?

Currently, I am in the process of creating a stopwatch for solving Rubik's cube. Within this project, there is a div element named "records" that is meant to display the time after a button is clicked. However, I am facing an issue where I am unable t ...

How to align radio buttons in the center of a div horizontally

I am struggling to center a group of three radio buttons horizontally and have not been successful. Below is the code I am using: HTML <div class="section-wrap section-flavors"> <input id="r11" name="radio3" type="radio" value="radio_bt ...

Strange behaviors when using setinterval with classes

Currently working on enhancing a slider functionality, and I have observed that everything is functioning smoothly - function Slider(element) { this.i = 0; this.element = element; var self = this; this.timer = window.setInterval(functi ...

I am facing issues with utilizing if endif for my Internet Explorer stylesheet in HTML/CSS

<!--[if IE]> <link rel="stylesheet" type="text/css" href="ie.css" /> <![endif]--> <link rel="StyleSheet" href="style.css" /> Whenever I apply this code, the content in Internet Explorer is being influenced by both style.css and ie. ...

Printing from a Windows computer may sometimes result in a blank page

Looking to incorporate a print button into an HTML page, I'm facing an issue. The majority of the content on the page should not be included in the printed version, so my approach involves hiding everything in print and then showing only the designate ...

What causes the odd gaps at the bottom of boxes in a Pure CSS Masonry layout?

Issue with implementing Pure CSS Masonry layout. Using position: relative for the boxes and position: absolute for the content inside each box is causing gaps below each box. Struggling to find a solution, view the code on this codepen: http://codepen.io/k ...

Adding a horizontal scrollbar to an iframe: A step-by-step guide

My issue involves embedding this iframe element <iframe src="https://opendsa-server.cs.vt.edu/OpenDSA/Books/Everything/html/Write.html#recurWriteStepsCON" scrolling="no" id='frameid1' width=100% height=330px></iframe& ...

Display the remainder of an image's height within a div container

Here is the code snippet I am working with: HTML: <div id="mapWrapper" style="height: 624px;"> <div class="box" id="map"> <h1>Campus</h1> <p>Description Campus Map.</p> <img src="abc.png" ...

How to Create a Bootstrap 4 Fixed Bottom Navigation with a Dropup Feature?

After thoroughly researching the site, I have not found a solution that works with this particular approach. In order to create the following template, I utilized Pingendo. .dropup .dropdown-menu { top: auto; bottom: 100%; margin-bottom: .125rem; ...

Changing the color of a div's text based on its content with CSS

I am facing a challenge in styling the text inside a “div” element using a Javascript function. Initially, when the page loads, these “divs” contain no value. The values of the "divs" will change between "Open" and "Closed" twice a day when the Jav ...

Differences in CSS between IE10 and Chrome are causing compatibility issues

Website in question: What is causing the difference in display between IE 10 and other browsers? The website appears to function correctly on Chrome: IE 10: ...

Utilize jQuery to toggle the visibility of one specific div among others with the same class

I'm currently working on a comment and like system similar to Facebook. However, I am struggling to select the specific div element! Here is a snippet of my current HTML: <div class='activoptions'><a href='#'>Like< ...