Disappearing Div Dilemma: The Mystery of the Responsive Design

I am currently facing an issue where two div elements (`.left` and `.right`) are not displayed vertically when the width value is less than 800px. Strangely, the `.left` div disappears when I try to adjust the width. I have shortened the code for clarity.

Does anyone have any insights into why this is happening and how I can resolve it?

Here is the code snippet:

* {
            box-sizing: border-box;
        }
        
        body {
            color: white;
        }
        
        .split {
            height: 100%;
            width: 50%;
            position: fixed;
            z-index: 1;
            top: 0;
            overflow-x: hidden;
            padding-top: 20px;
        }
        
        .left {
            left: 0;
            background-color: #282C34;
        }
        
        .right {
            right: 0;
            background-color: #616161;
        }
        
        .centered {
            position: absolute;
            width: 100;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        
        .container {
            position: relative;
            border-style: solid;
            border-color: #92a8d1;
            background-color: #92a8d1;
        }
        
        @media screen and (max-width:800px) {
            .left,
            .right {
                width: 100%;
                /* The width is 100%, when the viewport is 800px or smaller */
            }
        }
<div class="split left">
        <div class="centered">
            <center>
                <div class="container">
                    <div class="middle">
                        <div class="text">
                            <a></a>
                        </div>
                    </div>
                    <div class="information">
                        <h2>asd</h2>
                    </div>
                </div>
            </center>
        </div>
    </div>

    <div class="split right">
        <div class="centered">
            <center>
                <div class="container">
                    <div class="middle">
                        <div class="text">
                            <a></a>
                        </div>
                    </div>
                    <div class="information">
                        <h2>fgh</h2>
                    </div>
                </div>
            </center>
        </div>
    </div>

Any help or suggestions would be greatly appreciated!

Answer №1

* {
            box-sizing: border-box;
        }
        
        body {
            color: white;
            margin: 0;
        }
        
        .split {
            height: 100%;
            width: 50%;
            position: fixed;
            z-index: 1;
            top: 0;
            overflow-x: hidden;
            padding-top: 20px;
        }
        
        .left {
            left: 0;
            background-color: #282C34;
        }
        
        .right {
            right: 0;
            background-color: #616161;
        }
        
        .centered {
            position: absolute;
            width: 100;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }
        
        .container {
            position: relative;
            border-style: solid;
            border-color: #92a8d1;
            background-color: #92a8d1;
        }
        
        @media screen and (max-width:800px) {
            .left,
            .right {
                width: 100%;
                height: 50%;
                /* The width is 100%, when the viewport is 800px or smaller */
            }
            
            .split {
               position: relative;
            }
            
            body {
              height: 100vh;
            }
        }
<div class="split left">
  <div class="centered">
    <center>
      <div class="container">
        <div class="middle">
          <div class="text">
            <a></a>
          </div>
        </div>
        <div class="information">
          <h2>asd</h2>
        </div>
      </div>
    </center>
  </div>
</div>

<div class="split right">
  <div class="centered">
    <center>
      <div class="container">
        <div class="middle">
          <div class="text">
            <a></a>
          </div>
        </div>
        <div class="information">
          <h2>fgh</h2>
        </div>
      </div>
    </center>
  </div>
</div>

Answer №2

Enclose the pair of divs within a wrapper div and utilize media queries along with the flex property. For instance...

HTML:

<div class="wrapper">
    <div class="left">
        ...
    </div>
    <div class="right">
        ...
    </div>
</div>

CSS/SCSS

@media(max-width: 800px) {
    .wrapper {
        display: flex;
        flex-direction: column;
        ...
    }
}

Alternatively:

<ul class="flex-container column">
  <li class="flex-item">1</li>
  <li class="flex-item">2</li>
  <li class="flex-item">3</li>
  <li class="flex-item">4</li>
  <li class="flex-item">5</li>
</ul>


.flex-container {
  padding: 0;
  margin: 0;
  list-style: none;

  -ms-box-orient: horizontal;
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -moz-flex;
  display: -webkit-flex;
  display: flex;
}

.column { 
  -webkit-flex-direction: column; 
  flex-direction: column; 
  float: left;
}

.column li {
  background: deepskyblue;
}

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

Page design ruined as a result of oversized fonts in IE9 for <h2> elements

Everything looks great on various browsers, except for the notorious IE9. We've implemented a block-style layout with a width of 660px, centered on the page. Despite setting the h2 width to 660px to match the layout, IE9 displays the font size much ...

Disable the ability to select text when double-clicking

Is there a way to prevent text selection on double click while still allowing selection on mouse drag? Whenever I try to remove selection on dblclick or mouseup, it flashes, which is not the desired outcome as shown in this jsfiddle. UPD: I am not lookin ...

Achieve the sticky effect for text in a HTML div using CSS to keep it anchored to the

Seeking advice on how to create a floating box that remains in the bottom right corner of a div using CSS. Any tips or suggestions are appreciated! (Here's an example of what I'm aiming for: https://i.stack.imgur.com/DkD5C.png) ...

Elements not following percentage in top positioning

I am facing an issue with resizing containers on my webpage. Despite using position: relative for everything, I am unable to properly adjust the size of the top containers using percentages. Any assistance would be greatly appreciated! ...

Achieve an overlapping effect between absolutely positioned sibling divs without the need to specify a background color

Exploring the development of a swipe-to-action list component. <div class="list-container"> <div class="row"> <div class="content"> Sample Content 1 </div> <div class="action"> ...

When BeautifulSoup is utilized, HTML tags are stripped of their opening and closing components

Encountered a problem while using BeautifulSoup to scrape data from the website www.basketball-reference.com. Although I have used BeautifulSoup successfully on Bballreference before, I am puzzled by what is happening this time around (admittedly, I am sti ...

The carousel functionality in Firefox and Opera is currently experiencing issues and is not functioning properly

I have implemented a horizontal carousel at the bottom of my website www.woody.my. The carousel functions properly in Chrome, but is not visible in Firefox, Opera, and IE. Here is how it appears in Chrome: And this is how it looks in Firefox: ...

What is the best way to retrieve a PDF file from another website and showcase it on our own site without any redirection?

Is there a way to display a pdf from another website without having to redirect to that site? I'm looking for a solution that involves using the URL directly. ...

Apply an image as the background for the body using Bootstrap 5 styling

I'm wondering how I can set the background of the whole webpage (the body) to an image. I'd like to add a subtle fade effect to avoid it being too overpowering. <style> body { background-image:url("{% static 'portfolio ...

What is the best way to adjust a component to display varying content based on the scenario?

I am looking for a way to reuse a component on my website that displays messages. The challenge is that in one section, the content consists of only a title and paragraph, while in another section, there are multiple titles and content pieces. I have imple ...

The process of how screen readers interpret HTML elements

It is important to understand that screen readers not only read the content within elements and tags, but also the elements or tags themselves. For example: <button class="class-of-the-button">Text inside</button> When read by a screen reader ...

Attempting to consistently place an element at the bottom of my div container

I am attempting to align my <span class="fechar_fancy">Back/span> at the bottom of my div, regardless of the height of my content. I want this element to always be positioned at the bottom. Therefore, I tried using position:absolute and bottom:0 ...

"Styling a form input with YAML and implementing a jQuery date picker field

Seeking help with a CSS question related to YAML. I've been struggling all day trying to position a jQuery date field next to a YAML CSS field, but so far I can only manage to have it display underneath the input field... Is there a way for the date ...

Updating inner text content dynamically can be accomplished without relying on the use of the eval() function

I am faced with a situation where I have multiple batches of code structured like this: 1 <div id="backgrounds" class="centery">Backgrounds 2 <div id="bk1" class="attr">Background 1 3 <div class="container"> 4 ...

AngularJS creates a new window in your application

I have created two html pages named web.html and addroute.html. Both pages are built with bootstrap. The angularjs script includes two controllers: webctrl and addctrl. In web.html, there is a button that, when clicked, opens the addroute.html page. I am ...

Updating the table row by extracting data and populating it into a form

As part of my project, I am implementing a feature where I can input 'Actors' into a table using a Form. This functionality allows me to select a row in the table and retrieve the data of the chosen Actor back into the form for updating or deleti ...

rotate a game embedded in a website by 90 degrees

Need assistance in rotating this embed code by 90 degrees. Can you provide some guidance? <div class="miniclip-game-embed" data-game-name="8-ball-pool-multiplayer" data-theme="0" data-width="750" data-height="520" data-language="en"><a href="http ...

Mix up the colors randomly

After searching extensively, I have been unable to find exactly what I am looking for. The closest matches only cover a portion of my needs which include: I am seeking a randomly selected color scheme that I have created but not yet implemented in code. T ...

What could be causing the issue with my code where the canvas is not showing boxes beyond a y-coordinate of 8 along the x-axis?

I've been working on creating a 64 square checkerboard using the html canvas element in javascript, but I'm encountering an issue. The boxes aren't rendering properly after the first 8 squares on the y-axis, and I can't figure out where ...

Is it possible to determine which child element is currently in view within a scrollable parent div?

In an attempt to replicate a "current page" feature using divs, similar to a PDF reader. document.addEventListener("DOMContentLoaded", function(event) { var container = document.getElementById("container"); container.onscroll = function() { let ...