Home > Net >  Media query is not working even though the syntax is correct
Media query is not working even though the syntax is correct

Time:10-04

media query not working even though the syntax for media query is correct. adding more code to get over with the stack overflow error. lord save me* aur kya kya likhu bhai** don't know how long stackoverflow want me to write

             // html 
        <!DOCTYPE html>
             <html lang="en">
            <head>
             <meta charset="UTF-8" />
              <meta http-equiv="X-UA-Compatible" content="IE=edge" />
                <meta name="viewport" content="width=device-width, initial-scale=1.0" />
             <title>Color Flipper</title>
             <link rel="stylesheet" href="/code/style.css" />
            </head>
              <body>
                 <h2>Color Flipper</h2>
                <div >
              Background Color :<span >#775bd6</span>
                   </div>
        
                  <button >Click Me</button>
                  <!-- javascript  -->
              <script src="/code/script.js"></script>
             </html>
        
                // css

This is css for the above html

               // reset 
            * {
                 margin: 0%;
                 padding: 0%;
                  box-sizing: border-box;
               }
               //variable
             :root{
                   --bgCOlor: #775bd6;
                    }
            body {
                  background-color: var(--bgCOlor);
                }
            h2 {
              width: 100vw;
              background-color: antiquewhite;
              text-align: center;
              font-size: 2.5em;
              padding: 15px;
              box-shadow: rgba(0, 0, 0, 0.25) 0px 54px 55px,
                rgba(0, 0, 0, 0.12) 0px -12px 30px, rgba(0, 0, 0, 0.12) 0px 4px 6px,
                rgba(0, 0, 0, 0.17) 0px 12px 13px, rgba(0, 0, 0, 0.09) 0px -3px 5px;
            }
              .bg-color {
                  background-color: #252525;
                  color: whitesmoke;
                  text-align: center;
                  display: inline-block;
                  transform: translate(14em, 6em);
                  width: 530px;
                  font-size: 2em;
                  padding: 20px;
                  border-radius: 14px;
                }
        
            .btn {
              color: #252525;
              text-align: center;
              transform: translate(6rem, 19rem);
              font-size: 1em;
              padding: 20px 45px;
              border: 2px solid #252525;
              border-radius: 10px;
              font-weight: 800;
              background-color: transparent;
            }
            .color {
              margin-left: 18px;
              color: dodgerblue;
              font-size: 1.4em;
                }

Media query code lie below Dhjdjdnejdhdhnejdjxhxhdh

                // media query 
            @media screen and (max-width: 480px) 
               {  
                  span .color{
                    color: red;
                   }
                } 
              
      

CodePudding user response:

Wrong:

@media screen and (max-width: 480px) {
  span .color {
    color: red;
  }
}

Correct:

@media screen and (max-width: 480px) {
  span.color {
    color: red;
  }
}

CodePudding user response:

You are telling Css to style a .color class that its inside a <span>

But in your html you have

<span >hey</span>

You need to change the css to

@media screen and (max-width: 480px) {  
    span.color {
        color: red;
    }
} 

OR change the HTML to:

<span> 
    <div > hey </div> 
</span>
  • Related