What could be causing the divs to overlap? Without the use of floats or absolute positioning,

When resizing vertically on mobile, my date-time-container is overlapping the upper elements welcome and weather. Despite setting them as block level elements, adding clear: both, and not using absolute positioning or floats, the overlap issue persists. Any insights on why this is happening?

  @media screen and (max-width: 960px) {
  body {
    max-width: 100vw;
    max-height: 100%;
    overflow: hidden;
  }
  #weather {
    display: flex;
    position: relative;
    clear: both;
    justify-content: center;
    width: 100vw;
    height: auto;
    padding-right: 6%;
  }
  #loc-des {
    padding-right: 5%;
    display: block;
    height: auto;
  }
  #welcome {
    position: relative;
    height: auto;
    text-align: center;
    margin: 5% auto 0 auto;
    clear: both;
  }
  #main-container {
    max-width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  #date {
    position: relative;
    display: block;
    font-size: 1.3em;
    margin-bottom: 3%;
    clear: both;
  }
  #time {
    position: relative;
    display: block;
    clear: both;
  }
  #date-time-container {
    display: block;
    position: relative;
    clear: both;
    height: auto;
  }
  #time-container {
    display: block;
    position: relative;
    margin: 0 auto;
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    align-content: center;
    clear: both;
  }
<h1 id="welcome"></h1>
<div id="weather">
  <div id="loc-des">
    <div id="location"></div>
    <div id="description"></div>
  </div>
  <h1 id="temp"></h1>
</div>

<main id="main-container">
  <section id="time-container">
    <section id="date-time-container">
      <h2 id="time">00:00</h2>
      <span id="date"></span>
    </section>

    <form action="https://www.duckduckgo.com/" target="_blank" autocomplete="off">
      <input type="search" name='q' id='search-bar' placeholder="search with duckduckgo ...">
    </form>
  </section>

Answer №1

The reason for this is that the tags do not contain any content within them.
By inserting content between each tag (<h1> and <div>), they will occupy their own space.

If you wish to create elements with no content,
you can use non-breaking spaces &nbsp;, or apply padding or specify height.

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

What is the CSS selector for the top-level heading?

Is there a way to target the first occurrence of the highest heading element (h*) in a DOM structure? Perhaps something along the lines of (h1, h2, h3, h4, h5, h6):first-of-ordered-set For example, if the DOM contains h2, h3, h1, h2, h1, it should selec ...

Unable to execute any actions on object in JavaScript

I currently have two functions in my code: getRawData() and getBTRawData(). The purpose of getBTRawData() function is to retrieve data from Bluetooth connected to a mobile device. On the other hand, getRawData() function takes the return value from getB ...

divs aligned vertically on opposite edges of the webpage

Our web app is being embedded in a third party page as an iframe, but we need to add a bottom "toolbar" with 2 links. One link should be plain text and the other should display our company logo preceded by some text. We want the two links to be positioned ...

Implement a transition effect for the onClick event of a div element

I am looking to create a smoother transition effect when clicking on the section, causing it to expand and display the text underneath. I want to make this transition slower and more seamless. My current attempt at adding a transition to the "active" clas ...

Which Angular component, directive, or pipe would be best suited for creating dynamic HTML content similar to this?

(I am transitioning from React to Angular, so please bear with me if my question has a hint of React influence.) I am in need of developing an Angular component that can accept a string along with a list of terms within that string for displaying tooltips ...

Do you need to align images side by side and have clickable images positioned beneath each one?

After searching high and low, I couldn't find a similar question. My goal is to transform this from a vertical layout to a horizontal one: https://i.stack.imgur.com/4kZNM.png Check out the code snippet below: ghost<br class="newline"> <img ...

After clicking a button in AngularJS, how can you retrieve one of the two JSON files and store it in a $scope variable?

For instance, You have two JSON files: Json file #1: [{colorname:blue},{colorname:blue}] Json file #2: [{colorname:red},{colorname:red}] Within the controller, there exists a variable called $scope.color In the HTML code, there are two buttons named " ...

Retrieve and save files under a common directory

I have a specific route called payments/transactions that retrieves all relevant data. I'm interested in finding a way to generate a CSV file without the need to create new routes or add query parameters, so that my route appears as payments/transacti ...

Placing an absolutely positioned element on top of other elements

Currently, I am working on a frontendmentor website and encountering difficulty in positioning the shopping cart div above all the other elements. Initially, I attempted to use z-index for this purpose, but it seems that it does not work with elements havi ...

The compatibility between json_encode and JSON.parse is not seamless

I am encountering a situation on my PHP page where I am using json_encode and getting the following output: {"id":"761","user":"Moderator","message":"test"} {"id":"760","user":"Patrick","message":"test"} My goal is to parse these values using JSON.parse ...

Navigating shadow dom elements in HTML with Selenium WebDriver

public WebElement retrieveShadowRootElement(WebElement element) { WebElement shadowRoot = (WebElement) ((JavascriptExecutor)driver) .executeScript("return arguments[0].shadowRoot", element); return shadowRoot; } WebElement rootElement= dri ...

What specific files from the Kendo core are required for utilizing Mobile and Angular functionalities?

After browsing through similar questions, I couldn't find a solution. Currently, I am experimenting with Kendo (open source core for now) in a Visual Studio Cordova project. Initially, disregarding Cordova, I am focusing on setting up a basic view wit ...

Incorporating a CSS Module into a conditional statement

Consider the following HTML structure <div className={ `${style.cell} ${cell === Player.Black ? "black" : cell === Player.White ? "white" : ""}`} key={colIndex}/> Along with the associated CSS styles .cell { ...

Tips for ensuring all data is properly set before saving in mongoose

Struggling to update undefined or defined values in Mongoose due to the need to await their assignment. It seems like the code is not saving the data because USER.save() is executed before the values are set. How can I ensure that the data is updated/set ...

Passing information from a directive to a controller using AngularJS

I am looking to display the progress of a file upload using a file reader. Here is the HTML code snippet I have: <md-progress-linear id="file-progress-indicator" md-mode="determinate" value="{{progress}}"></md-progress-linear> and below is m ...

Is there a way to prevent a background video from automatically playing whenever the user navigates back to the home page?

Recently, I was given a design that requires a background video to load on the home page. Although I understand that this goes against best practices, the client has approved the design and now I need to come up with a solution. The video is already in pla ...

Is it possible to create a popup window that remains fixed at the top edge of the screen but scrolls along with the rest of the page if

In an attempt to organize my thoughts, I am facing a challenge with a search page similar to Google. The search results trigger a popup window when hovering over an icon, located to the right of the search results. Here is what I am looking to achieve with ...

Is there a way to modify the image source upon clicking a button?

I am currently working on implementing an image swap functionality on a webpage. I need the image to change when a user clicks a button, but for some reason, my logic isn't working. I am more interested in understanding why it's not working and w ...

Using TypeScript, implement a function that is called when a React checkbox's state changes to true

Currently, I am experimenting with the react feature called onChange. My goal is to update local data by adding a value when a checkbox is selected. Conversely, when the checkbox is unselected, I just want to display the original data. However, I find that ...

The AJAX call fails to refresh the secondary table in CodeIgniter

I have a situation where I need to display data from two tables - car producer and car model, pulled from a database. My goal is to filter the second table to only show cars from a specific producer when that producer is clicked in the first table. I attem ...