Making adjustments to the font size does not have an impact on the entire header

I've been working on implementing a sticky header for my current webpage, and I've set all margins in "rem". However, when I adjust the font size for the main header that contains all the header content, only the ul list part seems to be affected while the other margins remain unchanged. Can anyone offer some advice on what might be causing this issue?

My goal is to make the header appear slimmer as I scroll down.

JQuery code:

$(window).scroll(function() {

    if ($(this).scrollTop() > 10) {
        $('.mheader').addClass("sticky_header");
    }
    else {
        $('.mheader ').removeClass("sticky_header");
    }

})

CSS header code:

.mheader {
    width: 100%;
    height: 4.75rem;
    box-shadow: 1px 1px 1px #ccc;
    background: #eee;
}

.sticky_header {
    position: fixed;
    z-index: 999;
    font-size: 0.8rem !important;
    transition: all 1s ease;
}

.mheader__logo img {
    position: relative;
    width: 10.1%;
    float: left;
    height: 2.3rem;
    margin: 1.225rem 0.9375rem;
}

... (CSS code continues)

HTML code

        <header class="mheader">
                <div class="mheader__logo">
                    <a href="/index.php"><img src="/assets/img/logo.png" alt=""></a>
                </div>
                ... (HTML code continues)
        </header>

Thank you

Answer №1

Ensure to utilize EM instead of REM if you prefer it to be relative to a parent element. This means that all the sizes defined with REM are based on the <html> tag.

If you use em,

$(window).scroll(function() {

    if ($(this).scrollTop() > 10) {
        $('.mheader').addClass("sticky_header");
    }
    else {
        $('.mheader ').removeClass("sticky_header");
    }

})
body{
height:4000px;
}
.mheader {
    width: 100%;
    height: 4.75rem;
    box-shadow: 1px 1px 1px #ccc;
    background: #eee;
}

.sticky_header {
    position: fixed;
    z-index: 999;
    font-size: 0.8em !important;
    transition: all 1s ease;
}

/* The remaining CSS code is not altered for brevity */

</script>
<header class="mheader">
                <div class="mheader__logo">

<!-- More HTML code follows -->

        </header>

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 universal method for indexing in jQuery other than using .first()? I am familiar with the .first() method, but do .second() or .third() exist as

I'm facing a simple yet challenging issue that I can't seem to find an answer to. When a button is pressed, three forms appear on my website and I want the cursor to be automatically focused on the form that opens up. However, since all the forms ...

What could be the reason for PHP mysqli failing to insert data into the database in Xampp?

I attempted to use the code below to insert data into a database named sample, where the table is also named sample. The table consists of four fields: first_name, last_name, bio, and created. However, when I try using this code with an HTML form for inpu ...

What are some effective strategies for keeping content from shrinking in a drawer menu?

I am currently using a tutorial from https://www.w3schools.com/howto/howto_js_sidenav.asp to create a drawer sidebar menu. However, in my scenario, I need to include a wall of text instead of <a> links. The issue I am facing is that the text expands ...

Managing CSS classes in Vue js - Best practices

My challenge is to dynamically add and remove classes in response to input validation using the textfield component from Google Material. If the text input fails validation, I need to display a red border around the input field along with a warning message ...

Elevated CSS: Convert submenu to vertical dropdown layout rather than horizontal

My website features a superfish menu here, and I am seeking a way for the submenu to drop down vertically. Currently, I can achieve this by applying the following CSS: .sf-menu.sf-style-white.sf-navbar li ul { width: 150px; left: 100px; } However, th ...

The width specified for the table is not being applied

I've been struggling to adjust the width of my table in order to display data from a database. I've tried using inline width, !important tag, id, and class but none have worked. Interestingly, when I apply a fixed width without dynamic data, it w ...

Create a unique custom design for your Mapbox GL control

When developing the website, we utilized Angular 8, Typescript, and SCSS. We are using mgl-map to display a map, and I wanted to create a custom control for it with unique styles. I added the custom control to the map using: const centerOnCoordinatesC ...

Achieve a centered content with a stretched background using Bootstrap 5

Having some trouble with aligning items in a div using align-items-stretch to stretch the background and align-items-center to vertically center the content. It seems that the alignment issue occurs when there's a very long title present. https://i.s ...

Slide your cursor over to reveal a picture

I'm looking to create an interactive image gallery where the user can hover over an image to reveal text below it. I've been trying to achieve this by setting up my images in a specific way: echo "<div class=textimage style=background-image:u ...

Tips for displaying diverse content in a DIV container when users click on various sections of an image

Apologies for the unclear title, but I'm struggling to explain my technical goal using jargon. The basic concept is this: there will be an image on the webpage, and when a user clicks on a specific area of the image, relevant information will appear ...

What is the method for establishing an interval, removing it, and then reinstating the interval with the identical ID?

I'm wanting something along these lines: Inter = setInterval(Function, 1000); clearInerval(Inter); Inter = setInterval(Function, 1000); I've tried something similar without success. It's hard to explain all the details in a tidy way. Can a ...

The items in the Bootstrap dropdown are not displaying

I am currently working on a project using Angular 12, and I encountered an issue with my Bootstrap dropdown menu not displaying any items. Below is the HTML code snippet causing the problem: <nav class="navbar navbar-expand navbar-dark"> ...

Maximizing the Potential of Icons and Colors in the Native User Interface for WebApps

Recently, I've started working on a WebApp project with the goal of mimicking the functionality of a native application. To achieve this, I've decided to utilize the theme of the user interface (such as Unity [Ubuntu], Explorer [Windows], Gnome [ ...

AngularJS application is throwing an error indicating provider $q is not recognized

Could someone please advise on what might be the issue with my code snippet below: var app = angular.module('app', [ 'angular-cache', 'angular-loading-bar', 'ngAnimate', 'ngCookies', &a ...

Curious about altering the way Microsoft ASP.NET Controls display HTML tags?

My current setup involves Microsoft .NET Framework Version 4.0 SP1Rel and Visual STudio 2010 Version 10 SP1Rel. In the Web application that my team is working on, we are utilizing tags such as <asp:Login/>, <asp:TemplateField/>, <asp:GridVie ...

What is the method for configuring automatic text color in CKEditor?

https://i.sstatic.net/yEM3p.png Is there a way to change the default text color of CKEditor from #333333 to #000000? I have attempted to modify the contents.css in the plugin folder: body { /* Font */ font-family: sans-serif, Arial, Verdana, "Tr ...

Steps for deactivating a button based on the list's size

I am trying to implement a feature where the user can select only one tag. Once the user has added a tag to the list, I want the button to be disabled. My approach was to disable the button if the length of the list is greater than 0, but it doesn't s ...

"Safari is not displaying the element's height correctly when set to 100

I am facing an issue where I have a child div vertically centered under a parent div with a specific height. The child div is assigned the height:100% property, but it seems to be not working correctly on Safari only. To see more about this problem, you ca ...

Shifting the background image as we reach its limit

I'm creating a website for my company, but I struggle with HTML. One feature I want is to have a background image that stays static while reading the site, but then follows the user when they reach the end of the image. I know how to make an image f ...

The automatic redirection feature on a webpage is not functioning correctly on mobile devices

There's a peculiar issue on our website that I'll do my best to explain, and I'll provide photo links for more clarity. In our WooCommerce site, the process of paying for the cart goes as follows: Click "place order" button pic: Page for o ...