Divs are being obstructed by the navigation bar

I am seeking a solution to prevent div elements from being positioned below my navigation/information bar when the screen width is minimized. The information bar has a height of 1200px and I would like it to stay on the left side without any overlapping from other code or divs when the browser window is made smaller.

Alternatively, I would appreciate guidance on how to reduce the height of the "information bar" when the browser window is resized while allowing the divs to move underneath it smoothly.

<!DOCTYPE html>
<html lang="">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel='stylesheet' href=o>
    <link href="https://fonts.googleapis.com/css?family=Abel|Abril+Fatface|Amaranth|Arapey|Armata|Asap+Condensed|Bellefair|Cabin+Condensed|Cormorant+Unicase|Cormorant+Upright|Dancing+Script|EB+Garamond|Economica|Frank+Ruhl+Libre|Great+Vibes|Gruppo|Gudea|Halant|Heebo|Hind+Guntur|IM+Fell+Great+Primer+SC|Italianno|Karla|Kreon|Kristi|Kurale|Molengo|Old+Standard+TT|Open+Sans+Condensed:300|Ovo|Parisienne|Pinyon+Script|Poiret+One|Pontano+Sans|Prata|Quattrocento|Rouge+Script|Share|Spectral|Tangerine|Tenali+Ramakrishna|Trirong|Voces|Yantramanav|Yrsa" rel="stylesheet">
    <title></title>
</head>

<body>
    <h1>Site</h1>
        <nav>
    <ul class="menu">
        <li>Information</li>
        <li>Wanting</li>
        <li>To</li>
        <li>Stay</li>
        <li>Undisruptive</li>
        <li>To</li>
        <li>Div's</li>
    </ul>
        </nav>

<div>
    <div class=red>
    </div>
    <div class=red>
    </div>
    <div class=red>
    </div>
    </div>
</body>
</html>

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

body{
    text-align:center;
    font-family
}

h1{
    background-color:black;
    color:white;
    padding:1em;
    font-size:2em;
}

.menu{
    background-color:gray;
    width:200px;
    height:1200px;
    position:relative;
    float:left;

}

.red{
    position:relative;
    border:1px solid red;
    float:left;
    width:350px;
    height:350px;
}

@media screen and (min-width:600px){
    .red{

    }
}

Answer №1

Here is a helpful tip:

If you want to adjust the width of an element, you can use "%" as the unit.

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  text-align: center;
  font-family
}

h1 {
  background-color: black;
  color: white;
  padding: 1em;
  font-size: 2em;
}

.menu {
  background-color: gray;
  width: 25%;
  height: 1200px;
  position: relative;
  float: left;
}

.right {
  float: left;
  width: 75%;
}

.red {
  position: relative;
  border: 1px solid red;
  float: left;
  width: 100%;
  height: 350px;
}

@media (max-width:600px) {
.menu {
  width: 35%;
}
.right {
  width: 65%;
}
}
<h1>Site</h1>
<nav>
  <ul class="menu">
    <li>Information</li>
    <li>Wanting</li>
    <li>To</li>
    <li>Stay</li>
    <li>Undisruptive</li>
    <li>To</li>
    <li>Div's</li>
  </ul>
</nav>

<div class="right">
  <div class=red>
  </div>
  <div class=red>
  </div>
  <div class=red>
  </div>
</div>

Answer №2

The code provided seems to be at a beginner level, but I have made some modifications to meet the requirements.

<div class="site-name">
  <h1>Site</h1>
  <div class="hamburger" id="hamClick">
   <span></span>
   <span></span>
   <span></span>
  </div>
</div>
<nav>
  <ul class="menu" id="menu">
    <li>Information</li>
    <li>Wanting</li>
    <li>To</li>
    <li>Stay</li>
    <li>Undisruptive</li>
    <li>To</li>
    <li>Div's</li>
  </ul>
</nav>

<div>
 <div class=red></div>
 <div class=red></div>
 <div class=red></div>
</div>

Custom CSS:

*{
  margin:0;
  padding:0;
  box-sizing:border-box;
}

body{
  text-align:center;
}

.site-name {
  padding: 1em;
  position: relative;
  background-color:black;
}
.site-name h1{
  color:white;
  font-size:2em;
}

.menu{
  background-color:gray;
  width:200px;
  height:1200px;
  position:relative;
  float:left;
}

.red{
  position:relative;
  border:1px solid red;
  float:left;
  width:350px;
  height:350px;
}
.hamburger {
  display: none;
  position: absolute;
  border: 1px solid #fff;
  border-radius: 4px;
  padding: 4px;
  top: 20px;
  cursor: pointer;
}
.hamburger span {
  width: 20px;
  height: 2px;
  background: #fff;
  margin-top: 2px;
  display: block;
}
.hamburger span:first-child {
  margin-top: 0px;
}

@media only screen and (max-width:600px){
  .hamburger {
    display: block;
  }
  .menu {
    height: 0px;
    transition: all .3s ease-in-out;
    position: absolute;
    overflow: hidden;
  }
  .menu.active {
    height: 150px;
    transition: all .3s ease-in-out;
    z-index: 999;
  }
  .red {
    width: 100%;
  }
}

Javascript Functionality:

document.getElementById('hamClick').addEventListener('click', function() {
  var collapse = document.getElementById('menu');
  collapse.classList.toggle('active');
});

You can view the updated code on JSFiddle here: JSFiddle

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

Guide to creating a versatile navigation bar using Bootstrap and HTML

I am looking to create a navigation menu that can be easily reused across multiple pages on my bootstrap/html website. Instead of duplicating code, I want to implement a solution for creating a reusable navigation menu in bootstrap/html. How can this be ...

Personalized Owl Carousel - OWL.JS Hover Pause Feature

I have been working on a slider in Codepen that is functioning well, and now I am trying to tweak it for my website. My goal is to make the carousel pause when someone hovers over it. I've experimented with all the options available on the owl slider ...

Transforming a Multi-Dimensional Array into an HTML Table

Experimenting with a new idea. I hope the solution is straightforward; I just can't seem to figure it out. Imagine I have an array like this: var items = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; My goal is to rearrange the data so that it looks like t ...

The video header on my webpage refuses to start playing upon loading

I have a video displayed in the header of my website, but it only starts playing once the user clicks on the home link in the menu to navigate to /index.html. It does not play automatically when the page first loads. I have also tried manually entering /in ...

Transferring data from a table to another window

Currently, I am retrieving values from a database and displaying them in a table. I would like to add a button to each row that will allow users to view more details about that specific row. At the moment, only ThesisID, AuthorID, and Title are visible. ...

Loading HTML content in Electron using the renderer process JS

During the development phase, I found that the jquery load method for loading HTML views in Electron was functioning smoothly: app.appContainer.load('html/homePage/homePage.html', () => { app.addListenerToHomePage(false) }); I have individua ...

The background image fails to display properly on the server in Next.js

Hello, I'm currently using NextJs and I have a challenge. I want to set a background image on the body element that is rendered server-side. Below you'll find my code snippets: First, here is my App.js: import BodyStyle from '@components/Bo ...

Guide for adding an OnClick event to a MatTable row:

I am looking to add functionality for clicking on a specific row to view details of that user. For instance, when I click on the row for "user1", I want to be able to see all the information related to "user1". Here is the HTML code snippet: <table ma ...

Implementing checkboxes for each API data in JavaScript

I am fairly new to this and I am currently working on a to-do list. I want to include a checkbox next to each item from the API to indicate whether it has been completed or not. <script type="text/javascript"> fetch('http://localhos ...

Using JQuery to Customize Navigation Menu Targeting

On my website, I am trying to make an href button and a menu fade in as the page loads. However, I am struggling to find the correct code due to its placement within multiple tags, especially since I am new to JS and JQuery. I have provided a fiddle with a ...

javascript: obtain the height of the pseudo :before element

Can someone help me figure out how to get the height of a pseudo :before element? I've tried using jQuery but it's not working as expected. Here's what I attempted: $('.test:before').height() // --> null If you want to take a ...

Exploring the depths of Cordova's capabilities: implementing a striking 3D front-to-back screen flip effect

Recently, I came across an interesting app that had a unique feature. By clicking on a button, the entire screen would flip from front to back with a 3D effect on iPhone. It was quite impressive to see in action. The developer mentioned that he achieved t ...

Move the location of the mouse click to a different spot

I recently received an unusual request for the app I'm developing. The requirement is to trigger a mouse click event 50 pixels to the right of the current cursor position when the user clicks. Is there a way to achieve this? ...

Is there a way to trigger validation with a disabled property?

My form element is set up like this: <input type="text" id="country" formControlName="Country" /> The form group looks like this: this.myForm = this.formbuilder.group({ 'Country': [{ value: this.user.Country, disabled: this.SomeProperty= ...

Tips for aligning numbers in a monospaced ordered list

Is there a way to align the numbers in a numbered list within a table using monospace font so that they are at the same level as bullets on a bullet list? Simplest example: ol { font-family: monospace; } ul, ol { margin-top: 10px; margin-bottom: ...

Code snippet in webpage body

Hey there, I could really use some assistance: I currently have the following: A) Login.html B) Documentation.html C) Base.html Within the login page, there is a form with fields for User and Password. In Documentation, there are links to various folder ...

Upon selecting the hamburger menu, the menu pops up; however, the homepage text is visible overlapping the menu

I'm in the process of developing a responsive portfolio page using ReactJS and Tailwind CSS. When the screen size is smaller than the medium breakpoint, a hamburger menu icon appears. However, when I click on the hamburger icon to view the menu items, ...

Uploading an image using ajax with multer

When using Multer to upload an image file to my Node server, I keep getting 'undefined' when trying to use ajax to send the image. Ajax : image = $("#input-file-img").val() const data = new FormData(); data.appe ...

Increase the thickness of the scrollbar track over the scrollbar thumb

I've come across several discussions on making the track thinner than the scrollbar thumb, but I'm looking to do the opposite. Is it possible to have a scrollbar track that is thicker than the scrollbar thumb? ...

Struggling with CSS on your website and need some help?

Working on a website project with my own design, I ran into an issue regarding the positioning of the menu style. Describing this problem can be challenging, so let's start by looking at some images. What it should look like: Current appearance ...