No outcome visible from several CSS media queries

Inside my head tag, I have the following script. The min-width:500 is functioning correctly, however the immediate subsequent query for max-width:499px doesn't seem to be working. I've tried with and without screen and, as well as adding it to the styles.css stylesheet but nothing seems to work. This is specifically targeted for my screen and should be operational. Can anyone identify what mistake I might be making?

<meta name="viewport" content="width=device-width, initial-scale=1">
        <style>
            h2 {
                color: orangered;
                text-align: center;
            }
            
            @media screen and (min-width: 500px) {
                body{
                    color:greenyellow;
                    background-color: black;
                }
            }

            @media screen and (max-width: 499px) {
                body {
                    color:pink;
                    background-color: navy;
                }
            }
        </style>
        <link rel = "stylesheet" href = "styles.css">

Why does my VSCode not recognize mid-width or max-width but accepts it during coding?

Answer №1

After reviewing your code in VS Code, I noticed that the background color is working correctly but the text color (H2 tag) is not changing. This issue may not be related to VS Code itself, as you can make adjustments to change the text color.

When creating media queries, ensure that you are targeting both the background color of the body and the text color within the h2 tag specifically. Writing specific code for the H2 tag will help resolve this issue.

Consider using the following code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style>
        h2 {
            color: orangered;
            text-align: center;
        }
        @media screen and (min-width: 500px) {
            h2 {
                color: green;
            }
            body {
                background-color: black;
            }
        }
        @media screen and (max-width: 499px) {
            h2 {
                color: pink;
            }
            body {
                background-color: navy;
            }
        }
    </style>
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <h2>TechWithVP</h2>
    Some other text
</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

Tips for utilizing identical properties across numerous styled elements:

Utilizing the styled-components library, I have enhanced the header components from the Blueprintjs library. The current template for the H6 component appears as follows: export const DH6 = styled(H6)` color: ${(props) => (props.white ? "white&qu ...

CSS: Aligning lines across different columns

For my HTML web page, I have organized content into three vertical columns. Each column contains different elements, including form elements like selects. I want the text in all three columns to align properly, creating a straight line across all of them. ...

Is it feasible to create rows within columns using Bootstrap framework?

Is it possible to achieve this layout using rows within columns with Bootstrap: https://i.sstatic.net/DC0f4.png I attempted the following without success: <div className="col-lg-3 col-12"> <div className="row"> ...

The table is not being queried for alphabet letters

I'm having an issue with my table that has a column called BarcodeID. The numerical values work fine and I get the correct output, but when it comes to alphabet letters, it's not working as expected. I keep getting an error message: Unknown co ...

Creating an Excel spreadsheet from an HTML table with compatibility across different web browsers

Does anyone know of a JavaScript function that can save an HTML table as an Excel file, meeting the criteria of being A. Developed in pure JavaScript and B. Compatible with browsers as far back as IE8? I've dedicated 2 full days to finding a solution ...

The node version in VS Code is outdated compared to the node version installed on my computer

While working on a TypeScript project, I encountered an issue when running "tsc fileName.ts" which resulted in the error message "Accessors are only available when targeting ECMAScript 5 and higher." To resolve this, I found that using "tsc -t es5 fileName ...

Could Google Adsense be causing issues with my website's navigation bar?

There seems to be an irritating bug that I've come across. While navigating my website, [the menu (located in the top right corner) functions correctly]. However, when you land on a page with a Google AdSense ad, the menu suddenly appears distorted ...

Tips for adding global styles to the html and body elements in SCSS without utilizing the @import rule

Many experts recommend avoiding the use of @import in SASS due to its deprecation in the future. However, when it comes to applying global styling in SCSS, what alternative methods can be used? ...

Look into HTML and JavaScript problems specific to IOS devices

I have encountered some HTML markup and JavaScript functionality issues on my web-app that seem to only occur on iPad and iPhone. Unfortunately, I do not have access to any iOS devices to debug these problems. How can I replicate and troubleshoot these i ...

Unable to implement the bootstrap panel class as expected

It seems like the bootstrap panel class is not being applied in this code snippet: <div class="container main-content"> <div class="row"> <div class="col-sm-3"> <div class="panel panel-primary"> ...

Importing FontFace elements within the _document.tsx file

I have a collection of FontFace objects stored in a file called fonts/myFonts.js: const fontFaces = [ new FontFace('MyFont', "url('local/location.woff2') format('woff2')", { weight: '400', style: ...

Tips for implementing a fully responsive left-side menu using Twitter Bootstrap 4.2

I'm attempting to design a layout featuring a top navbar and a collapsible left menu. On medium-sized screens or smaller, the left menu should remain hidden. However, it needs to occupy the full height of the page at all times, regardless of its actu ...

I'm currently attempting to create a dynamic object using code, but it doesn't seem to be functioning as expected. I'm curious about what might be causing the issue

I am brand new to exploring JavaScript, HTML, and CSS. I've gone through my code several times but can't quite pinpoint what's causing it not to function properly. While there are no apparent errors being returned, the expected behavior is n ...

select specific region within image

I'm currently working on cropping an image and sending the cropped data to the server side. To achieve this, I am utilizing the imgareaselect plugin. While I am able to obtain the coordinates of the selection, I am facing challenges in actually croppi ...

Expanding the navigation bar is causing a hindrance to clicking on input fields

Upon clicking the navbar to extend it, I encountered an issue where I couldn't interact with inputs and buttons on my website. Upon further investigation, I discovered that this problem was linked to the navbar itself. Removing the navbar resolved the ...

What is the proper way to add process.env.PORT to the script declarations string within my package.json file?

I am facing an issue while trying to upload my file on Heroku that requires including the PORT specification. Unlike my previous projects, this project consists of only html, js, and css files instead of an index.js file. To run it, I am using "live-server ...

`Center Google My Map Location - Embedded in the Middle of the Page`

Recently, I transitioned to using an embedded My Map for a business with 2 locations. However, I encountered some challenges in customizing the map's height, width, and centering on the page. Is there a way to resolve this issue? New HTML code which ...

Generate a variety of HTML ordered lists

Can anyone assist me in determining the type of ordered list shown below? What is the method to achieve an ordered list like this: (a) (b) (c) in HTML? ...

How do I center align 2 td's in HTML?

I have a code snippet below for Submit and Cancel buttons. When I had 3 buttons, I aligned the middle one in the center which looked good. But now with only 2 buttons, they appear slightly to the left. How can I align them in the center of tr tag? Any su ...

Attempting to showcase a button element within a popover, although it is failing to appear

I have implemented a feature where a popover appears when hovering over an inbox icon (font-awesome). However, I am facing an issue with displaying a button on the second row within the popover. The title is showing up fine, but the button is not appearing ...