the toggle feature is not functioning properly on smartphones and tablets

I have embarked on the journey of creating a responsive website. The @media tag is new territory for me, and I'm unsure if I've implemented it correctly.

My goal is to have a slidetoggle menu for the nav when the window size is less than 550px.

While this functionality works as intended by resizing the browser window, it seems to be non-responsive on my iPhone. My desired outcome is for the nav to transition to toggle mode at 550px with the header height adjusting accordingly to 2em.

Your assistance in resolving this would be greatly appreciated.

Here's the HTML code:

<meta name="viewport" content"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">


<div id="header">
    <section id="menubar">
        <ul>
            <li><a class="menubutton" href="#menu"><img src="images/menu.png" /></a></li>
        </ul>
    </section>
        <nav class="nav">
            <ul>
                <li><a href="test.html">test</a></li>
                <li><a href="test.html">test</a></li>
                <li><a href="test.html">test</a></li>
                <li><a href="test.html">test</a></li>
                <li><a href="test.html">test</a></li>
            </ul>
        </nav>
</div>

And here's the CSS:

ul {
margin:0px;
padding:0px; }

li {
list-style:square;
font-weight:100;
color:#000000;
line-height:1em;
padding:0em; }

a {text-decoration: none; }

div#header {
position: fixed;
height: 6.250em;
width: 100%;
background-color: #fff;
top: 0;
z-index: 999; }

#menubar {
display:block;
background:#ffffff; }

#menubar ul {
display:block;
width:2em;
padding:0.9em; }

#menubar ul li {
display:inline; }

#menubar ul li a.menubutton {
display:none; }

#menubar img {
width:90%;
height:auto;
max-width:100%; }

nav ul {
display:block;
position: absolute;
left: 15%;
bottom: 0.625em;
font-size: 0.875em; }

nav ul li {
display:inline;
margin:0em 0.625em 0em 0em; }

nav ul li a {
color:#000; }

nav ul li a:hover {
color:#cc9900; }

nav ul li a.active {
color:#cc9900; }

@media screen and (min-width:600px) {
nav.nav {
    display:block !important;
}
}

@media screen and (max-width:550px) {
#menubar ul li a.menubutton {
    display:block;
}   
nav {
    display:none;
    height:auto;
}
nav ul li {
    display:block;
    margin:0.2em 0em 0.2em 0em;
}
}

@media screen and (max-width:550px) {
div#header {
height: 2em !important;
}

@media screen and (max-width:550px) {
div#content {
top: 2em !important;
}

Answer №1

One of my techniques involves adding a heavy-colored element after each media query to easily visualize the changes taking place.

@media screen and (max-width: 320px) {
  header { background-color: red; }
}

In my case - 320px corresponds to red, 480px to orange, and 760px to green.

Best regards;

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

Use Vue.js class bindings to create blank spaces in between CSS classes

I'm utilizing a v-bind:class binding on a component in order to toggle a css class based on the truthiness of a boolean within my Vue.js component. When I specify this in my template: <aside v-bind:class="{'--opened': sidebarVisible}" ...

Set up a jquery code that ensures a loading effect will only be displayed one time

After clicking on a specific icon, I dynamically add a loading message to the DOM. The issue arises when the user clicks twice, resulting in two instances of the loading message appearing simultaneously. How can I ensure that only one "loading..." message ...

Incorporating text box input into a data table

When I click the "add game" button, I want the value of the input named "game-name" to appear in the "Name of the game" column of a table. Additionally, I am experiencing issues with the delete button functionality. Below is the code snippet I am working ...

Exploring jQuery selectors with a looping mechanism to trigger click events

Trying to figure out how to loop through numerical selector values in JQuery while utilizing an onClick event handler. Is this a chicken-or-egg situation or perhaps a closure issue? Any guidance would be appreciated. $("#q01").click(function() { cle ...

Implementing jQuery/JavaScript to efficiently iterate through JSON data

I have implemented a form that allows users to select an item from a multi-select dropdown (A). If the desired item is not listed, users can manually add it using another text input box (B). Once added, an AJAX call saves the item to the database. After su ...

What is the best way to modify a React icon that has been imported using styled components?

Using the styled component library to customize my website's style. I want to make adjustments to my imported react icon component. <i class="fab fa-facebook"></i> It is simple to modify this using normal CSS by targeting the &l ...

Optimal ffmpeg configurations for encoding videos into mp4 and ogg formats for seamless playback on HTML5 platforms

Despite the buzz surrounding it, the HTML5 video tag is facing a minor issue. To ensure cross-browser compatibility, multiple video formats - like mp4 and ogg - need to be included for its use. Unfortunately, I couldn't find optimal settings for each ...

I'm wondering why myDivId.toggle() is functioning properly but myDivClass.toggle() is not working as expected

Using JQuery's toggle() function, I have been able to hide and show some DIVs successfully. Recently, I discovered relationships between certain DIVs that allowed me to group them into a class. I decided to try toggling the entire class rather than ...

How can I import XML files containing image links for embedding in a 2D JavaScript Array?

For a few months now, I have been dedicating my free time to working on a personal project - an open-source version of SimTower with updated graphics that I have created myself. In the initial stages, I developed a webpage that displayed a collection of i ...

"Use jQuery to select all the cells in a row except for the

I found a visually appealing table layout that looks like this : https://i.stack.imgur.com/oRxYP.png What caught my attention is how clicking on a row selects the entire row. Take the example in the image above, where the second row is highlighted upon s ...

Tips for placing a background color *behind* a bootstrap button

When a button is clicked, I want to display an input with a background surrounding both the button and the input. Currently, my markup renders like this: https://i.sstatic.net/rxaPt.png So when the button is clicked, I need a yellow (alert-warning) backg ...

Selenium - pausing for scroll completion

I am currently working on automating downloads from a webpage using the selenium tool. My approach involves creating a firefox driver that opens the page and clicks the download button. However, I have encountered an issue where the button needs to be vis ...

Countdown Widget - Transform "0 Days" to "Today" with jQuery

I am currently working on a countdown page using the Keith Woods Countdown jQuery plugin which can be found at . Here is the code I have implemented so far: $(document).ready(function () { var segera = new Date(); segera = new Date(segera.getFullYear(), 2 ...

Leveraging variables within the rel attribute when using jQuery selectors

Currently, I am utilizing the rel attribute to associate a div with a button. Each button's id is used in the corresponding div's rel field. With multiple buttons available, my goal is to display the corresponding div when a button is clicked usi ...

Refreshing the webpage upon submitting with Angular2 and Firebase technology

Yesterday, I came across an Admin HTML template that I wanted to integrate with Firebase. However, when I tried to register and clicked on Sign in, the page would reload instead of carrying out the Firebase createUserWithEmailAndPass process. Here is a s ...

Django: creating a custom dropdown input field for the receiver that is tailored to the sender

I am facing an issue with creating a dropdown list for the receiver without including the sender's id/name. This is different from a chained dropdown which has already been addressed in previous discussions. I believe that using ajax might be the solu ...

The left border is failing to appear on the Td element

When attempting to add border styling to td elements, the left border is not displaying correctly. This issue seems to vary across different browsers. Here is the HTML code: <table class="table-bordered"> <thead> <tr> ...

Using the HTML5 time element to include milliseconds in a form

If we take a look at this website, we can see various examples of HTML5 form options, one being the "time" element. Can we customize the time element to include milliseconds as well? I'm not interested in using a plain text box as a fallback option. ...

methods to locate the parent element of an element with selenium

<button class="wpO6b ZQScA" type="button"> <div class="QBdPU "> <svg aria-label="New Message" class="_8-yf5 " fill="#262626" height="24" viewBox="0 0 44 44" widt ...

How come adjusting the margin of a div doesn't impact the placement of its child elements?

I'm trying to wrap my head around how css margins interact with divs and their child elements. For instance, when I set it up like this... <div style="clear: both; margin-top: 2em;"> <input type="submit" value="Save" /> </div> ...