Conceal a portion of the navigation menu while viewing on mobile devices and ensure proper functioning of the mobile stylesheets

I'm facing an issue with my website's navigation bar. It has five sections on desktop, but I need only four visible on mobile devices. However, I can't seem to get my mobile style sheets to work properly. Specifically, I am struggling to hide the last section of the navigation bar along with its child elements.

In each page, I have included three style sheets:

<link rel="stylesheet" type="text/css" media="only screen and (max-width: 767px)" href="css/small_device.css"/>
<link rel="stylesheet" type="text/css" media="only screen and (min-width: 768px) and (max-width: 959px)" href="css/medium_device.css"/>
<link rel="stylesheet" type="text/css" href="css/style.css"/>

Within these style sheets, I attempted to hide the specific navigation I wanted by using this code snippet:

.vendors {
display: none;}

This was in place of the original styling for the navigation which included dropdown menus and submenu interactions.

The problematic part in the navigation structure is as follows:

<div class="drop">
<ul class="drop_menu">    
    <li>. . . </li>
    <li>. . . </li>
    <li>. . . </li>
    <li>. . . </li>
    <li><a href="vendors.html" class="vendors">Vendors</a>
        <ul>
            <li><a href="register.html" class="vendors">Register</a></li>
        </ul>
    </li>
</ul>
</div>

I've searched extensively for a solution, but haven't found much help. Most suggestions point towards using @media queries within the style sheets. However, despite trying to implement them, I couldn't achieve the desired outcome. Can someone guide me on where to properly insert the @media queries or provide any other assistance?

Answer №1

To streamline your stylesheets, you can use the @media rule in the following way:

@media screen and (min-width: 768px) and (max-width: 767px) {
  .vendors {
    display: none;
  }

  /* Styles for both max-width 767px and min-width 768px */

}

@media screen and (max-width: 767px) {

  /* Styles for max-width 767px */

}

@media screen and (min-width: 768px) {

  /* Styles for min-width 768px */

}

If you need to hide all <li> elements for a specific screen size, make sure the vendors class is applied to the li tag rather than the a tag.

Answer №2

I've typically never come across a situation where a stylesheet is included in the manner you've demonstrated, but it very well could be correct.

One possibility is that you might have overlooked adding the following meta tag in your

<head>
   <meta name="viewport" content="width=device-width">
</head>

On the other hand, my approach (which may not necessarily be superior) involves simply placing:

@media screen and (max-width: 300px) {
      /*code*/
}

either within your main style.css file (after all previous CSS rules), or integrating a separate stylesheet (e.g. responsive.css) below your primary desktop stylesheet.

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

challenges surrounding the use of getElementByTagName

Within my webpage, I have implemented two select elements, both containing multiple options. However, I am facing an issue where I can only access the options from the first select box using getElementByTagName("options"), and unable to retrieve the option ...

The alignment of hyperlinks with display block cannot be maintained in a horizontal position

I am struggling to align a group of hyperlinks horizontally within a td element. Currently, they are displaying vertically due to my use of display : block; While I understand that using ul and li elements would be the proper way to achieve this, I am ...

Innovative dropdown menu featuring images and informative text snippets

I have a question about creating a menu similar to the one on http://www.resellerclub.com that includes images and text details. Are there any ideas on which technologies were used or if there are any commercial solutions available for this? Thank you. ...

Issues with SVG Image Mask in Firefox and IE: How to Fix Them

Creating a mask with a PNG (black circle, transparent background) and using -webkit-mask-image:url(images/mask.png) has been easy for browsers like Chrome. However, I've been encountering significant difficulties in getting the mask to display properl ...

Minimize or conceal iframe

This iframe contains a Google form that cannot be edited. I am looking for a way to close or hide this iframe, either through a button, a popup window button, or without any button at all. The $gLink variable holds the Google form link through a PHP sessio ...

What is the best way to modify the height of an element that contains an SVG at the bottom in order to ensure it appears visually appealing across all screen widths?

Is there a way to adjust the height of an element with an SVG at the bottom so that it looks good on all screen widths? I'm attempting to create a 'wave' effect at the bottom of my element using a background-image in CSS. Although I managed ...

When vertical tabs are activated, they shift the page upwards

I recently utilized Bootstrap to create vertical tabs for my website. My goal was to display additional text below the tab title only when that specific tab is active. While I managed to achieve this, I encountered an issue where transitioning from one t ...

Hybrid Titanium app with HTML page enlarged on a Samsung Galaxy S7 device

We are currently facing an issue with our hybrid app developed in titanium. Everything seems to be working fine, except on certain new phones like the Galaxy S7 Active. The problem we are encountering is that the HTML page appears zoomed in despite having ...

Tips for deactivating dropdown values based on the selection of another dropdown

There are two dropdown menus known as minimum and maximum, each containing numbers from 1 to 25. If a value is selected from the minimum dropdown (e.g. 4), the maximum dropdown should only allow values that are equal to or greater than the selected value ...

Adding data into a JSON Array

I'm attempting to add values from an input textbox into a JSON array. Here's my current approach: Code: <!DOCTYPE html> <html> <body> <input id="studentnumber" placeholder="Student Number"></input> <input id="s ...

Embedding an iframe with vertical scrolling enabled

Could you explain why I am unable to scroll the full width of the website? Here is a link: http://codepen.io/anon/pen/EKPaao?editors=1100. Also, what do you think about using this solution for adjusting iframes on different screen sizes? My iframe seems to ...

Error in Angular 8: Property 'name' is undefined and cannot be read

Delving into the world of Angular, I encountered an interesting error: ERROR TypeError: Cannot read property 'name' of undefined. Here's the snippet of code: recipe-list.component.ts import { Component, OnInit } from '@angular/core&ap ...

Ways to optimize images for social media sharing on a website

I am in the process of building a new website using Elementor and Wordpress. My goal is to incorporate multiple GIFs and images that users can easily share on social media platforms. The challenge I'm facing is that the social icons in Elementor are ...

Is it possible to gather information by scraping after submitting a form?

I'm currently working on a project for my class and as a beginner, I might make mistakes with some of the technical terms. Please bear with me. My project involves creating an interactive journey planner specifically for my city's public transit ...

Design a Unique CSS Shape

Do you have any suggestions on how to create this shape using only CSS, without SVG paths? Thank you in advance! Check out the screenshot here ...

Creating a color-changing checkbox toggle in Bootstrap 5

Is it possible to customize the color of a Bootstrap 5 switch without changing it site-wide? I want some checkbox switches to have a unique color. Most tutorials online only cover how to change colors globally or use images, but I'm hoping to achieve ...

Issue with CSS min-height causing divs to not align properly

My CSS Code includes media queries to adjust the layout: .clearfloat { clear: both; font-size: 1px; height: 0; line-height: 0; } .box-container { width:100%; text-align:center; } .icon-box { width:32%; max-width:500px; ...

Are custom HTML tags in Angular 2 truly safe? Exploring the safety of custom tags compared to custom attributes

Here we delve into the realm of Angular 2 selectors, comparing Custom tags versus Custom attributes in relation to SEO and browser rendering. Upon embarking on my Angular 2 journey and altering the selector to '[my-component]' (attribute selecto ...

Troubleshooting the issue with generateStaticParams() in NextJs/TypeScript

My NextJs app has a products page that should render dynamic routes statically using generateStaticParams(). However, this functionality does not work as expected. When I run "npm run build," it only generates 3 static pages instead of the expected number. ...

Style the div element with CSS

Is there a way to style a div element within an HTML document using Sencha framework? I have specific CSS properties that I would like to apply to my div. #logo{ position:absolute; top:20%; left:0%; } Below is a snippet of my Sencha code: Ex ...