The menu bar ought to transition from the left side to the top on smaller screens

Currently, I am in the process of creating a technical documentation project through freecodecamp. Here is the code that I have been working on:

#main-doc {
    margin-left: 270px;
}


.heading {
    font-size: 1.7rem;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}

li {
    padding-bottom: 5px;;
}


.para, li {
    font-size: 1.1rem;
    margin-left: 20px;
}

code {
    font-size: 1.05rem;
    font-family: sans-serif;
    padding-left: 60px;
    padding-top: 10px;
    padding-bottom: 10px;
    background-color: rgba(0, 0, 0, 0.05);
    display: block;
}

#navbar {
    height: 100%; /* Full-height: remove this if you want "auto" height */
    width: 250px; /* Set the width of the sidebar */
    position: fixed; /* Fixed Sidebar (stay in place on scroll) */
    z-index: 1; /* Stay on top */
    top: 0; /* Stay at the top */
    left: 0;
    background-color: #f6f3f3; /* Black */
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 20px;
}

.nav-link {
    display: block;
    padding: 12px 0 12px 8px;
    font-size: 1.05rem;
    text-decoration: none;
    border-bottom: 2px solid rgba(0, 0 ,0 ,0.5);
    width: 250px;
}

nav header {
    padding: 10px 0 10px 8px;
    font-size: 1.5rem;
    background-color: blueviolet;
    color: aliceblue;
}

@media (max-width: 600px) {
    #navbar {
        overflow: hidden;
        background-color: white;
        position: fixed; /* Set the navbar to fixed position */
        top: 0; /* Position the navbar at the top of the page */
        right: 0;
        left: 0;
        width: 100%; /* Full width */
    }   

    .nav-link {
        display: block;
        padding: 12px 0 12px 8px;
        font-size: 1.05rem;
        text-decoration: none;
        border-bottom: 2px solid rgba(0, 0 ,0 ,0.5);
        width: 250px;
    }

    nav header {
        padding: 10px 0 10px 8px;
        font-size: 1.5rem;
        background-color: blueviolet;
        color: aliceblue;
    }
}
<!DOCTYPE html>
<html lang="en-us">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Page</title>
    <link rel="stylesheet" href="test.css">
  </head>
  <body>
      <main id="main-doc">

        <section class="main-section" id="Introduction">
          <header class="heading">Introduction</header>
          [...]
            ...
        
        </section>

        [...]

  
      </main>      

      
      <nav id="navbar">
        <header>JS Documentation</header>

          [...] 

      </nav>
  </body>
</html>

I have a concern about the media query located at the end of the CSS file. When the screen size is reduced, my intention is for the navigation bar on the left to remain at the top. However, it seems like it's not functioning as expected. Can someone advise on what could be causing this issue?

Many thanks!

Answer №1

Feel free to utilize this customized CSS code with updated media query syntax

#main-doc {
    margin-left: 270px;
}

.heading {
    font-size: 1.7rem;
    font-family: Verdana, Geneva, Tahoma, sans-serif;
}

li {
    padding-bottom: 5px;;
}

.para, li {
    font-size: 1.1rem;
    margin-left: 20px;
}

code {
    font-size: 1.05rem;
    font-family: sans-serif;
    padding-left: 60px;
    padding-top: 10px;
    padding-bottom: 10px;
    background-color: rgba(0, 0, 0, 0.05);
    display: block;
}

#navbar {
    height: 100%; /* Full-height: remove this if you want "auto" height */
    width: 250px; /* Set the width of the sidebar */
    position: fixed; /* Fixed Sidebar (stay in place on scroll) */
    z-index: 1; /* Stay on top */
    top: 0; /* Stay at the top */
    left: 0;
    background-color: #f6f3f3; /* Black */
    overflow-x: hidden; /* Disable horizontal scroll */
    padding-top: 20px;
}

.nav-link {
    display: block;
    padding: 12px 0 12px 8px;
    font-size: 1.05rem;
    text-decoration: none;
    border-bottom: 2px solid rgba(0, 0 ,0 ,0.5);
    width: 250px;
}

nav header {
    padding: 10px 0 10px 8px;
    font-size: 1.5rem;
    background-color: blueviolet;
    color: aliceblue;
}

@media (max-width: 600px) {
    #navbar {
        overflow: hidden;
        background-color: white;
        position: fixed; /* Set the navbar to fixed position */
        top: 0; /* Position the navbar at the top of the page */
        right: 0;
        left: 0;
        width: 100%; /* Full width */
    }

    .nav-link {
        display: block;
        padding: 12px 0 12px 8px;
        font-size: 1.05rem;
        text-decoration: none;
        border-bottom: 2px solid rgba(0, 0 ,0 ,0.5);
        width: 250px;
    }

    nav header {
        padding: 10px 0 10px 8px;
        font-size: 1.5rem;
        background-color: blueviolet;
        color: aliceblue;
    }
    
   /* Additional CSS for adjusting small device layout */
    #main-doc {
        margin-left: 0; /*margin left 0 */
        padding-left: 15px;
        padding-right: 15px;
    }
    code {
        padding: 15px;
        white-space: normal;
    }
}

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

When looking for a selection, the drop-down list unexpectedly shifts upwards

When using the ngx-intl-tel-input library in my Angular application, I noticed that when searching for a country in the dropdown list, it moves to the top. I am looking to fix the position of the dropdown menu while searching. Check out the demo: Demo Lin ...

Tips on displaying or hiding a div based on media query conditions without affecting nested divs

Is there a way to hide a specific div using a media query, but have it show up when that div is within another specific div? This is how the CSS currently looks: @media (min-width: 665px) { .mrbcircle-ipad:not(.link-inside.mrbcircle-ipad) { position:abso ...

Using the css function in JQuery may not always yield the desired results

These are the snippets of code I am working with: var topPix = $('#cc').css('top'); var leftPix = $('#cc').css('left'); $('#testFrame').css('top', topPix).css('left', leftPix); After ...

Having trouble formatting the Modal form in Bootstrap when using AngularJS

The code runs successfully, but I am struggling to get the desired output. You can find the code here. <div class="modal fade" id="signup" tabindex="-1" role="dialog"> <div class="modal-dialog modal-sm"> <div class="modal-content"> ...

Insert content into a designated DIV

Progress bars are essential for tracking certain metrics. Take a look at the progress bars below: <div id="lifeBar-holder"> <div id="lifeBar"></div> </div> <div id="discretionBar-holder"> <div id="discretionBar"&g ...

Getting the content inside a div tag with selenium in python

https://i.sstatic.net/OrWZ2.png Is there a way to retrieve the content within the specified div tag? I attempted copying and pasting the xpath, but when attempting to print the contents of the div, it did not work. div = driver.find_element_by_xpath(&apo ...

JQuery isn't functioning properly on dynamically generated divs from JavaScript

I'm currently tackling an assignment as part of my learning journey with The Odin Project. You can check it out here: Despite creating the divs using JavaScript or jQuery as specified in the project requirements, I am unable to get jQuery's .hov ...

"Styling a cover image in CSS without the need for readjustments

I found a cool idea for creating a Facebook-like cover image on this community. Check out this jsfiddle that I stumbled upon. .cover { width: 100%; height: 180px; overflow: hidden; background-color: black; } .cover > img { position: relative; width: 10 ...

The ">" CSS child selector does not seem to be functioning correctly with specific properties

While experimenting with applying CSS properties to direct child elements of a parent element using ">", I noticed that it works smoothly with certain properties like borders, but not so much with font-related properties such as color and font-weight. ...

When the sidebar is set to position: fixed, the icons magically vanish

This CSS is specifically for the side navigation bar. .side-nav { // position: sticky; top: 0; left: 0; height: 100vh; z-index: 100; width: calc(3.5vw + 3.5vh); // position: fixed; &.content { height: 100%; display: flex; fl ...

Troubleshooting WordPress 4.4 Image Issues: Understanding the Conflict between Srcset and Bxslider

We have several company websites that use Wordpress along with a Genesis installation, a custom Genesis child theme, and bxslider for image sliders. When we view the slider on Firefox, we notice a responsiveness issue that we believe is caused by the new ...

Bootstrap collapsible panel with unique off-center design

I am currently working on customizing a bootstrap collapsible panel that has an off-center indicator arrow. My goal is to center the indicator arrow with CSS. Here's the CSS code I have implemented: .panel-heading a:after { ...

What is the best way to create rounded thumbnails with the paperclip gem?

I noticed that the latest version of Basecamp is implementing this feature, you can check it out in this link. I am curious about how to replicate this in my Rails 3 application. ...

What is the best way to align a center column of a precise width that is responsive to different screen

As much as I hate to ask for help with a "how do I do this" question, I'm at my wit's end trying to figure it out on my own. I'm working on a page layout that requires a center column of exactly 960px width to be horizontally centered on th ...

Clicking on the label for Semantic UI Radio Buttons does not result in a check

Is anyone else experiencing difficulty with radio buttons not checking when the label is clicked? Oddly enough, this issue does not seem to be present on Semantic's website. For reference, here is Semantic UI Documentation where the radio buttons wor ...

Visibility of text compromised when placing transparent button inside input field

After adding a clear button inside the input box in Angular, I am facing an issue where the text in the input box is being overlapped and not fully visible. Below you will find detailed information on this problem. HTML Code <ng-template pTemplate=&quo ...

Cross Browser Compatibility for CSS Page Scrolling to the Right and Handling White Space/Margins

Currently in the process of developing a WordPress Theme at . Struggling with achieving equal left and right margins around the center container, resulting in the page displaying white space and allowing unnecessary scrolling. Seeking advice from anyone wh ...

Ensuring that two columns in Bootstrap 3 have equal heights while including padding

I would like to achieve this design without using JavaScript. Here is a screenshot for reference: This is what I have created so far using Bootstrap 3. The CSS is inline due to the use of less, which makes it easier :) HTML <section class="container ...

The Python Selenium Webdriver encountered an error when trying to select a dropdown, stating that the local variable element was

I encountered an error while attempting to select a drop-down element in my code. Error Traceback (most recent call last): File "C:\Webdriver\ClearCore\TestCases\OperationsPage_TestCase.py", line 59, in test_add_and_run_clean_process ...

Using Ionic framework alongside Ionic View to display a beautiful background image

How can I display a full background image in Ionic 1.2? -hooks -platfroms -plugins -resources -scss -www -css -img -js -lib -templates ... Currently, I have the following HTML structure: <ion-view id="login" hide-nav-bar="true"> ...