Developing a dynamic menu with media queries: Struggling to make the menu resize accordingly

I've been working on adjusting my menu for different screen resolutions using media queries. However, I'm facing some issues specifically between 1025 and 1441 pixels (or higher) where the font size is not changing as expected when I resize the browser window.

If you'd like to see what I mean, here's a screenshot: (I know images aren't always preferred, but just in case it helps)

To take a look at my code, you can visit this link: http://codepen.io/anon/pen/dPVzaW

HTML

<div id="cssmenu">
        <ul>
            <li class='active'><a href='/book/<?php echo $url; ?>'><span>Page details</span></a></li>
            <li><a href='/details/<?php echo $url; ?>'><span>Book details</span></a></li>
            <li><a href='/comments/<?php echo $url; ?>'><span>Comments</span></a></li>
            <li><a href='/suggestions/<?php echo $url; ?>'><span>Suggestions</span></a></li>
            <li><a href='/lists/<?php echo $url; ?>'><span>Lists</span></a></li>
            <li><a href='/inculture/<?php echo $url; ?>'><span>In culture</span></a></li>
            <li><a href='/cover-images/<?php echo $url; ?>'><span>Cover images</span></a></li>
        </ul>
    </div>

CSS

#cssmenu {
    width: 55%;
}

#cssmenu ul {
    width: 100%;
    border-radius: 3px;
    padding: 0;
    list-style-type: none;
    position: relative;
    display: block;
    font-size: 0.8em;
    font-weight: bold;
    background-color: #6A5546;
    font-family: Arial, Helvetica, sans-serif;
    border-bottom: 1px solid #353535;
    zoom: 1;
}

#cssmenu ul:before {
    content: '';
    display: block;
}

#cssmenu ul:after {
    content: '';
    display: table;
    clear: both;
}

#cssmenu li {
    display: block;
    float: left;
    margin: 0;
    padding: 0 4px;
}

#cssmenu li a {
    display: block;
    float: left;
    color: #b4aaa2;
    text-decoration: none;
    font-weight: bold;
    padding: 10px 20px 7px 10px;
    border-bottom: 3px solid transparent;
}

#cssmenu li a:hover {
    color: #FFFFFF;
    border-bottom: 3px solid #00b8fd;
}

#cssmenu li.active a {
    display: inline;
    border-bottom: 3px solid #00b8fd;
    float: left;
    margin-left: 1px;
}

@media screen and (min-width: 1025px) and (max-width: 1441px) {
    #cssmenu {
        width: 57%;
    }

    #cssmenu ul {
        width: 100%;
        border-radius: 3px;
        padding: 0;
        list-style-type: none;
        position: relative;
        display: block;
        font-size: 0.8em;
        font-weight: bold;
        background-color: #6A5546;
        font-family: Arial, Helvetica, sans-serif;
        border-bottom: 1px solid #353535;
        zoom: 1;
    }

    #cssmenu ul li a {
    }

}

Answer №1

Your problem may be due to using an incorrect CSS selector to define the font size.

UL and OL have special behavior because, by default, the font size is inherited from the LI element rather than the UL itself.

If you set the font size on the UL but there is already a size specified on the LI, it will not have any effect. You should set the font size on the LI element instead.

For example:

#cssmenu li {
    display: block;
    float: left;
    margin: 0;
    padding: 0 4px;
    font-size: 1em;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif;
}

@media screen and (min-width: 1025px) and (max-width: 1441px) {
    #cssmenu ul li {
      font-size: 0.8em;
    }
}

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

if the checkbox is selected, navigate to the displayed section

In my scenario, I have a total of 5 checkboxes and corresponding to each checkbox, there are 5 div elements. The functionality that I need is that when a checkbox is checked, the associated div should be displayed; otherwise, it should be hidden. The check ...

Create a div in CSS that is square and relatively positioned

Is there a way to use CSS alone to ensure that a div with relative positioning remains perfectly square in all scenarios? I have a script that allows users to upload images, which are then applied as the background image. The challenge is that the system ...

Is there a way to turn off the ripple effect on Material UI Input components?

Is there a way to turn off the ripple effect or highlight color on the TextField component in React's Material UI? https://i.sstatic.net/qB2cm.png I've attempted to modify the theme: theme.props.MuiTab.disableRipple = true theme.props.MuiButto ...

The div in Bootstrap is not becoming scrollable despite using "overflow: auto"

I have a unique setup with two divs nested inside another div. The first div contains a table, while the second div holds buttons. I'm trying to make the table div scrollable by using overflow-auto, but it's not working as expected. I suspect tha ...

The form-group nested within a form-horizontal is exceeding the boundaries of the preceding form-group

I am currently utilizing Bootstrap 3.3.6 and have a basic form enclosed in a panel: https://i.stack.imgur.com/UOFI6.png Although it is quite simple, the alignment of the "Post" button is not displaying properly. Here is the HTML code for the form: < ...

Achieving perfect alignment for images within a Bootstrap 4 carousel - both vertically and horizontally

Utilizing Bootstrap 4 carousel, I am attempting to center an image both vertically and horizontally. Below is my code along with the styling that I have applied: <div id="myCarousel" class="carousel slide" data-ride="carousel"> <ul class="car ...

Adjusting the size of a Checkbox with CSS

Adjust the width of the checkbox for the call field to 25 pixels, ensuring it is displayed only when the left margin is clear. I'm having trouble figuring this out, even though it's probably something simple again. I double-checked that my style ...

What is the best way to ensure that an input group expands to fill the entire horizontal space

I am currently utilizing bootstrap 4 and have a responsive navbar for smaller screens. On this navbar, I am trying to implement a search input group that spans the full width from left to right up until the menu bar icon on the right side. You can view my ...

Rearrange the characters within the variable before inserting them after

I'm currently dealing with an external system that generates outdated code, however, I do have access to css and javascript. The specific issue at hand involves working with a table that displays each item on a separate row, sometimes resulting in up ...

Tips for adjusting the hover size in a navigation bar

I'm currently learning how to use bootstrap and I'm attempting to create a navbar that shrinks when scrolled down, and I also want the hover effect on the links to be full-height. I've tried multiple approaches but haven't been successf ...

Chrome shows different height for various input types such as time and number

Having some trouble with input elements of different types and varying heights. For example, in Chrome the input type "time" appears taller than type "number." See the simplified illustration here: http://jsfiddle.net/4jteqy1f/ HTML <article class="se ...

Preventing Height Stretch in CSS Flex-Wrap: A Guide

Is there a way to eliminate the large gaps between box3, box1 and box4, box6? How can we ensure each box adjusts its height dynamically? .wrap { display: flex; align-items: baseline; align-content:flex-start; justify-content: space-between; fl ...

The issue of why padding left is not functioning correctly in Bootstrap version 5.3.1

</head> <body> <header class="bg-info "> <div class="container"> <div class="row text-white"> <div class="col-md-6 p-3 pl-6 "> ...

Assistance Needed with XPATH and CSS for Selenium Automation

Can anyone assist me in finding the appropriate XPATH/CSS locator to extract text from the structure below? <div class="page-header song-wrap"> <div class="art solo-art"> <div class="meta-info"> <h1 class="page-title"> Zehnaseeb I ...

Arranging my table

I've been trying to adjust the position of a table in my project that contains an image. Currently, it is aligned to the left and I want to move it to the right. Here is the code for my table: <TD> <IMG SRC='http://farm8.staticflickr.co ...

Is there a way to manipulate CSS to update automatically when new content is loaded via ajax?

I need help with customizing the CSS for 4 image links on my website. Each link is represented by a small image in its normal state and a larger image when hovered over. The content for each link is loaded using ajax. My question is how can I modify the C ...

What steps should I take to create a functional image scrolling effect similar to the one shown in this example?

Recently, I came across and was intrigued by the "image slide effect" featured on their homepage. The way the background image changes as you scroll up, leading you through different introductory slides before reaching the main content of the site caught ...

Is there a way to ensure that Google ads can be opened in a new tab when clicked, instead of opening within the current tab?

I recently created a Google ad and placed it on my website. However, I noticed that when users click on the ad, sometimes it opens in the same tab rather than a new one. This can lead to users losing track of my website. Can anyone explain why this incons ...

Tips for incorporating a tooltip into a disabled selectpicker option

A selectpicker I have is filled with various languages, listed as `li` tags within a `ul` tag. You can see an example in the image provided below. https://i.stack.imgur.com/dsg66.png It's noticeable that the `+ Add Language` option in the selectpick ...

Footer remains fixed to the bottom of the page even when there is not enough content to

It seems like there are already many discussions on this topic, so I apologize if this is a duplicate. I searched for it but couldn't find anything similar. I am currently working on an angular application using the Ionic framework for testing purpos ...