Adapting text size with Media Queries based on screen dimension

I am currently working on adjusting the size of navigation text depending on the size of the screen using media queries. The text is appearing as 30px on smaller screens, but even on larger screens it remains at 30px. Here is the code snippet:

HTML:

<div class="nav">
 <a class="logo" style="cursor: pointer">LIT</a>
 <div class="sidebar" id="active">
 <a style="cursor: pointer;" id="projectLink">samples &nbsp;</a>
 <a style="cursor: pointer;" id="aboutLink">services &nbsp;</a>
 <a style="cursor: pointer;" id="blogLink">tweets &nbsp;</a>
 <a style="cursor: pointer;" id="contactLink" class="mail" onclick="openForm()">contact</a>
 </div>

SCSS:

   .sidebar{
    z-index: 1;
    font-weight: bolder;
    margin-left: auto;
    margin-right: 0px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    font-family: 'Raleway', sans-serif;
    color: black;

    /* If the screen width is 601px or more, change the font-size of <div> to 80px */
    @media screen and (min-width: 601px) {
      .sidebar {
        font-size: 80px;
      }
    }

    /* If the screen width is 600px or less, adjust  afont-size of <div> to 30px */
    @media screen and (max-width: 600px) {
      .sidebar {
        font-size: 30px;
      }
    }

Answer №1

You have nested your .sidebar inside another .sidebar

To resolve this issue:

<!DOCTYPE html>
<html>
  <head>
    <style>
      .sidebar{
        z-index: 1;
        font-weight: bolder;
        margin-left: auto;
        margin-right: 0px;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        font-family: 'Raleway', sans-serif;
        color: black;
      }
      /* If the screen size is 601px wide or more, set the font-size of <div> to 80px */
      @media screen and (min-width: 601px) {
        .sidebar {
          font-size: 80px;
        }
      }
      /* If the screen size is 600px wide or less, set the font-size of <div> to 30px */
      @media screen and (max-width: 600px) {
        .sidebar {
          font-size: 30px;
      }
    </style>
  </head>
  <body>
    <p class="sidebar">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, 
    </p>
  </body>
</html>

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

Why is it that injecting javascript within innerHTML seems to work in this case?

According to the discussion on this thread, it is generally believed that injecting javascript in innerHTML is not supposed to function as expected. However, there are instances where this unconventional method seems to work: <BR> Below is an examp ...

Issue with React when attempting to add a secondary class to Toggle component

Is there a way to add a second class to my <div> with the class "button"? When I try to append 'toggle-button', the class doesn't seem to work. <CSSTransitionGroup transitionName="buttonAninmated" transitionEnterTimeout={30 ...

The formatting for C++ lnk2019 and lnk2020 is correct

Seeking assistance with my code and the errors I'm encountering - any guidance would be highly valued. Currently facing an issue with getNextAcountNumber. I attempted to assign the account ID value, but encountered a problem as it is a private member ...

Guide on getting PHP to display an error message in a designated area within a form

I need help creating a user registration system using PHP and HTML. How can I implement a feature that displays errors in red next to the input boxes if the user enters an invalid username, password, etc? I've been using the die() function, but it jus ...

Arranging several collapsible DIVs in the navbar using Bootstrap

Currently, my navbar design includes a search field placed before the menu items. These elements are contained in separate collapsible DIVs to allow for individual toggles. The issue I am facing is that there is a noticeable gap between the search bar an ...

Alternative solution to avoid conflicts with variable names in JavaScript, besides using an iframe

I am currently using the Classy library for object-oriented programming in JavaScript. In my code, I have implemented a class that handles canvas operations on a specific DIV element. However, due to some difficulties in certain parts of the code, I had t ...

Alter the app's entire background color in React.js with a button click

I am facing an issue with changing the background color of my entire React App when a button is clicked. Currently, I am able to change the color of the button itself but not the background. I have imported the App.css file into my project and I am looking ...

When using HTML5 input type number with 16 or more digits, Chrome automatically replaces any extra digits with zeroes

Has anyone else encountered an issue with Chrome related to using the input type number when the number of digits exceeds 16? I've noticed that in my case, any numbers beyond the 16th digit are automatically replaced with a zero when the field loses f ...

Could you guide me on how to utilize Sencha Touch for saving information in a JSON file?

I am in the process of creating a simple Sencha Touch application to become more comfortable with the platform. My goal is to have the store (currently set up as shown below) read and write data to/from a local JSON file. Additionally, I would like the sto ...

What is the ideal width for CSS div containers?

Feel free to take a look at our "About Us" and "Contact Us" pages here. I'm struggling with aligning my DIV containers properly. It's the first time I'm working with DIV containers - my last website was table-based and created using Golive! ...

Displaying values in form fields when a specific class is present

Whenever I input and submit the form fields correctly using #submit_btn, my values disappear. However, when they are not valid, this issue does not occur. I attempted to address this problem with jQuery: $('#submit_btn').click(function() { i ...

What is the best way to change CSS style for a button when clicked using JavaScript?

Is there a way to switch the background style of a CSS div when clicking the same button? function changeBg() { var divElem = document.getElementById("change-bg"); if (divElem.style.backgroundColor === "yellow") { divElem.style.backgroundColor ...

How to position elements within a content block in HTML with a CSS stylesheet

Looking for guidance on how to align text and image within a block in HTML using only a .css file. Specifically, I need the text to be on the left side and the image on the right. Since I am new to CSS, I could use some direction on where to start. Any t ...

Ways to link two PHP scripts

My code snippet below aims to select a location from a dropdown menu and generate a pie chart based on data fetched from a PostgreSQL database. However, I am facing an issue where the pie chart displays all column values instead of only the selected locati ...

The HTML and script tags are failing to connect

I recently started learning angularjs by watching the Egghead.io videos. However, I encountered an issue where I couldn't link my JavaScript page to my HTML page. my-index.html <!DOCTYPE html> <html> <head> <title>Angular ...

Obtaining a byte array using the file input method

var profileImage = fileInputInByteArray; $.ajax({ url: 'abc.com/', type: 'POST', dataType: 'json', data: { // Other data ProfileImage: profileimage // Other data }, success: { } }) // Code in Web ...

Adjustable backdrop with CSS

How can I create a resizable dynamic background image in CSS that adapts to the size of the browser window? #mainPage { width: 100%; height: 100%; font-size: 3vw; text-transform: uppercase; background: black; font-weight: bold; ...

Having trouble with my WordPress theme not recognizing my CSS file

My file path is displayed below: D:\web server\blog.dev.cc\wp-content\themes\ablog\css for java script file path D:\web server\blog.dev.cc\wp-content\themes\ablog\assets\js Despite checking ...

The concepts of width and min-width in CSS allow for controlling

I have a table with the following styles applied: width: auto; min-width: 98.5%; When viewing in Chrome, the table inside a div appears to only be about 50% of the width of the containing div. However, in IE9, the table occupies the full width. Checking ...

The JQuery UI draggable feature allows users to drag elements beyond the specified width limit

I am currently working with two draggable divs and I need to find a way to prevent them from being dragged to the right and down. Here is the CSS and JS code for each draggable div: #the-sheet { position: absolute; margin-left: auto; margin-right: a ...