Setting the vertical navbar height to match the footer in a HTML layout

When the screen size is larger than 768px, my layout looks like this: https://i.sstatic.net/nE4Qp.png

However, I want the vertical navbar height to extend to the footer even when resizing the screen. This is the desired layout: https://i.sstatic.net/z98Uf.jpg

including the background color.

Here are the HTML and CSS files:

article {
text-align: left;
}

header {
background: black; 
color: white;
padding: 10px;
text-align: center;
}

nav {
background: #eee;
padding: 10px;
text-align: center;
}

ul {
list-style-type: none;
padding: 0;/*Remove padding from ul*/
}

li a{
display: block;/*Separate padding by rows*/
padding: 8px 16px;
color: #000;/*Remove default link color*/
text-decoration: none;/*Remove link underline*/

}

li a:hover {/*Hover effect*/
background-color: #555;
color: white;
}

footer{
background: #aaa;
color: white;
padding: 0px;
}

img{
padding: 10px;
  height: 505px;
  width: 829px;
}

/*Reposition elements when width is >=768px for all devices*/
@media all and (min-width: 768px){

nav {
text-align: left;
max-width: 200px;
float: left;/*Move content to the right*/
}

article {
margin-left: 250px;
}


}
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<link rel="stylesheet" href="Index.css">
</head>

<body>
<header>
<h1 id="T">Index</h1>
</header>

<nav>
<ul>
<li><a>Topologies</a></li>
<li><a>Classification</a></li>
<li><a>Terminology Dictionary</a></li>
<li><a href="Pages\Domains.html">Domains</a></li>
<li><a>Devices</a></li>
</ul>
</nav>

<article>
<h2>Definition of Network</h2>
A telecommunications network is a collection of devices and their connections (physical or logical) that allow the transmission and reception of information of any kind between two or more users located in geographically distant locations, transferring it through cables, radio systems, or other electromagnetic or optical systems.

<br><br><img src="Images/NetworkImage.png">

</article>

<footer>
<p>Last updated: Saturday, May 19th</p>
<p><a href="#T">Back to Top</a></p>
</footer>

</body>
</html>

I am seeking a layout similar to: https://www.w3schools.com/html/tryit.asp?filename=tryhtml_layout_flexbox

In the provided example, the navbar height expands to the footer.

Answer №1

My approach involves enclosing the nav and article within a main tag, applying display: flex to it to ensure it takes the maximum height, and eliminating the need for float on the nav when using display:flex. By default, they will align next to each other in a row.

<main>
 <nav></nav>
 <article></article>
</main>

 
p { margin: 0; }

article {
    text-align: left;
  }

  header {
    background: black; 
    color: white;
    padding: 10px;
    text-align: center;
  }

  nav {
    background: #eee;
    padding: 10px;
    text-align: center;
  }

  ul {
    list-style-type: none;
    padding: 0;/*Remove padding from ul*/
  }

  li a{
    display: block;/* Separate by row with padding*/
    padding: 8px 16px;
    color: #000;/*Remove default link color*/
    text-decoration: none;/*Remove link underline*/

  }

  li a:hover {/* Hover effect*/
    background-color: #555;
    color: white;
  }

  footer{
    background: #aaa;
    color: white;
    padding: 0px;
  }

  img{
    padding: 10px;
    height: 505px;
    width: 829px;
  }

  /*Adjust elements if width is >=768px for all devices*/
  @media all and (min-width: 768px){

      main {
         display: flex;
      }

    nav {
      text-align: left;
      max-width: 200px;
      margin-right: 50px;
    }
  }
    

    <header>
    <h1 id="T">Index</h1>
    </header>
    
    <main>
          <nav>
    <ul>
    <li><a>Topologies</a></li>
    <li><a>Classification</a></li>
    <li><a>Terminology Dictionary</a></li>
    <li><a href="Pages\Domains.html">Domains</a></li>
    <li><a>Devices</a></li>
    </ul>
    </nav>
    
    <article>
    <h2>Definition of Network</h2>
    A telecommunications network is a collection of devices and their connections 
    (physical or logical) that enable the transmission and reception of information 
    of any type between two or more users located in geographically distant positions, 
    transferring them through cables, radio systems, or other electromagnetic 
    or optical systems.

    <br><br><img src="Images\NetworkImage.png">

    </article>
        </main>

    <footer>
    <p>Last Updated: Saturday, May 19</p>
    <p><a href="#T">Back to Top</a></p>
    </footer>
    
    </body>
    </html>

Answer №2

To make your navigation bar the same height as the screen size, simply set the height property to 100vh. This should effectively adjust the height according to the current screen size.

nav {
background: #eee;
padding: 10px;
text-align: center;
height: 100vh;
}

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

Is there a way to remove the ring shadow in TailwindCSS?

Here is a visual representation of the issue I'm facing (refer to the image): Check out the Image After inspecting with Chrome, it seems like the problem is connected to --tw-ring-shadow. I attempted to use classes like ring-0 and ring-offset-0 (men ...

How can we effectively transform an HTML opening and closing tag into a function?

Dealing with a complex HTML tag can be challenging, especially when it appears in various parts of the code. For instance: <div class="blabla" data-test="blablabla" ... data-another-attribute="blabla" > <some complex html code ... > </ ...

Troubleshooting Full Screen Problems with Three.js

Despite my efforts to troubleshoot, I am still encountering a frustrating issue with the Three.js API. Even after thoroughly studying the API documentation, browsing through StackOverflow questions, and using debugging tools like firebug and chrome's ...

Struggling with converting my menu design into a dropdown menu

Recently completed creating my initial menu with a left navigation bar design. Wondering if it is achievable to implement a dropdown effect on hover without the use of javascript? I have come across several solutions but they do not seem to work for me, po ...

Do overlay elements have to be positioned at the bottom of the HTML body every time?

As I delve into the world of JavaScript frameworks, one common trend I've noticed is that elements like dialogs, tooltips, and alerts usually appear at the end of the body tag. With my own implementation of these UI elements, I am determined to make ...

Automatically populate a div with content from a file

As I am completely new to the world of HTML, I find myself in need of quickly putting together something for work just as a proof of concept. I apologize if this question has been answered previously, but honestly, I wouldn't even know how to start se ...

Challenges with implementing emotion in Material UI 5

Recently, I upgraded my react app from Material UI 4 to 5 Beta. After consulting the documentation on the docs style library, I learned that the new version allows the use of emotion. However, when I attempted to implement it, I encountered an issue with t ...

Choose Your Preferences When the Page Loads

I have a dropdown menu where I can select multiple options at once without checkboxes. When the page loads, I want all of the options to be pre-selected by default. I am aware that I can use $(document).ready() to trigger actions after the page has load ...

I need the PHP code to ensure that only checkboxes can

I keep encountering what seems like a simple issue in my html form with checkbox groups. I am trying to ensure that at least one checkbox is selected from each group, and if not, display an error message using PHP code. However, despite multiple attempts, ...

Can you explain the distinction between max-width and min-width in media queries for HTML and CSS?

Could you explain the distinction between max-width and min-width in media queries in HTML and CSS? @media (min-width:480px) { /* styles for smartphones, Android phones, and landscape iPhone */ } @media (min-width:600px) { /* styles for portrait tabl ...

Updating part of a page while also changing the navigation

Apologies in advance, as this is my first attempt at coding a website. I have a specific need where I want to update only one div on my web page when a link in the navigation bar is clicked. <body> <div id="wrapper"> <header id= ...

Troubleshooting: Difficulty with jQuery script to change images

I am trying to modify the src attribute of an img tag using the code below, but it doesn't seem to be working. Can anyone help me figure out what's wrong? <img id='logo_image'/> <span onclick='$(logo_image).attr("src", "i ...

Identifying Flash content in a unique way

In my dynamic page (let's call it myFlashContainer.jsp), the Flash content changes based on the link that is clicked. The code responsible for rendering the Flash looks like this: <object height="100%" align="l" width="100%" id="player" codebase= ...

Navigating with Express while incorporating React

I am struggling to set up the routes for my web application using Express, as well as incorporating React for the front end. The issue lies in properly routing things when React components are involved. My index.html contains: <script> document.get ...

Having trouble finding elements with Selenium's Multiple Selectors

Attempting to interact with a button that Selenium/Nightwatch.js is unable to locate. The button is not nested within a different iframe. I have tested multiple selectors, but none of them are effective. The elements are visible and can be manually clicke ...

The filter is displaying incorrect categories

I am facing an issue with creating a work filter based on the last column which represents categories. When I select an option from the dropdown, I want to display only that specific category and hide the others. Currently, when I try clicking on an option ...

React Sticky sidebar implementation throughout the various components

My goal is to implement a sticky sidebar that moves smoothly across specific components on my webpage. The challenge I am facing is that the CSS 'sticky' property only allows movement within the component it was created in. So, my question is - w ...

Incorporate the AngularJS controller into your JavaScript code

I am facing an issue with my jQuery UI dialog that contains a dynamic <select> populated with Angular and AJAX. The problem is that the AngularJS script still runs even when the dialog is not visible. To solve this, I added a condition to stop the s ...

How to wrap a narrower column around a shorter column using Bootstrap 4

Incorporating Bootstrap 4 into my website design, I have created a simple two column layout. The right column houses a table of contents while the left column is filled with various markup elements such as paragraphs, lists, and images. My goal is to have ...

Javascript - When I preview my file, it automatically deletes the input file

My form initially looked like this : <form action="assets/php/test.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> ...