Media querie in order to change the image does not work

Asked

Viewed 16 times

0

I put a media querie for when width reaches 600px, change the image to a smaller.

@media only screen and(max-width: 600px) {
.header-container {
    background-image: url(//i.imgur.com/obpnQqo.png);
    background-size: cover;
background-repeat: no-repeat;
}
}

but it doesn’t seem to work, I took the only screen and thinking it was the problem and also did not work...

Replica of the code: https://codepen.io/utamo/pen/gqYada

* {
    margin: 0;
    padding: 0;
}
body {
    font-family: 'Rubik', sans-serif;
    background-color: #4a4190;
}

/* Menu fixado */
.menu {
    position: fixed;
  
}
.menu ul {
    display:flex;
    text-decoration: none;
    list-style: none;
    padding: 5px;
    cursor: pointer;
    color: #e0e0e0;
    
    
}
.menu li {
    justify-content: center;
    padding: 5px 10px 5px 10px;
    border-radius: 2px;
    font-weight: 500;
}
.menu li:hover {
    transition: all .5s;
    background: rgba(58, 50, 123, 0.38);
    color: #f3f3f3;
}

/* Texto e waifu*/
.header-container {
    display: flex;
    
    background-image: url(//i.imgur.com/T4ZzHIV.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    
    height: 100vh;
    align-items: center;
    justify-content: center;
}

.header-text-container {
    padding: 10px;
    background-color: rgba(240, 240, 240, 0.14);
    color: #f3f3f3;
    border-left: 3px solid white;
    border-radius: 2px;
}
.loung {
    color: #ffdb9a;
}
.loung:hover {
    color: #ffe4b2;
    transition: all 2s;
}
.header-text {
    padding-left:  10px;
    font-size: 4em;
    font-weight: 700;
        
}
.header-sub-text {
    font-weight: 600;
    padding-left: 20px;
    padding-bottom: 10px;
}

@media only screen and(max-width: 600px) {
    .header-container {
        background-image: url(//i.imgur.com/obpnQqo.png);
        background-size: cover;
    background-repeat: no-repeat;
    }
}
/* Começo do grid */
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="https://fonts.googleapis.com/css?family=Rubik" rel="stylesheet">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/styles.css">
</head>
<body>
   <nav class="menu">
       <ul>
           <li>Home</li>
       </ul>
   </nav>
    <header class="header-container">
       <div class="header-text-container">
            <h1 class="header-text">waifu<span class="loung">Lounge</span></h1>
            <h2 class="header-sub-text">the perfect place to find yours.</h2>
        </div>
    </header>
    
    <section class="pagebox">
        <div class="main-box">e</div>
    </section>
    
    
    
</body>
</html>

  • 1

    Missed a spot after the and.

1 answer

2


The lack of space after the and makes the rule invalid:

@media only screen and (max-width: 600px) {
                      ↑

Working:

* {
    margin: 0;
    padding: 0;
}
body {
    font-family: 'Rubik', sans-serif;
    background-color: #4a4190;
}

/* Menu fixado */
.menu {
    position: fixed;
  
}
.menu ul {
    display:flex;
    text-decoration: none;
    list-style: none;
    padding: 5px;
    cursor: pointer;
    color: #e0e0e0;
    
    
}
.menu li {
    justify-content: center;
    padding: 5px 10px 5px 10px;
    border-radius: 2px;
    font-weight: 500;
}
.menu li:hover {
    transition: all .5s;
    background: rgba(58, 50, 123, 0.38);
    color: #f3f3f3;
}

/* Texto e waifu*/
.header-container {
    display: flex;
    
    background-image: url(//i.imgur.com/T4ZzHIV.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    
    height: 100vh;
    align-items: center;
    justify-content: center;
}

.header-text-container {
    padding: 10px;
    background-color: rgba(240, 240, 240, 0.14);
    color: #f3f3f3;
    border-left: 3px solid white;
    border-radius: 2px;
}
.loung {
    color: #ffdb9a;
}
.loung:hover {
    color: #ffe4b2;
    transition: all 2s;
}
.header-text {
    padding-left:  10px;
    font-size: 4em;
    font-weight: 700;
        
}
.header-sub-text {
    font-weight: 600;
    padding-left: 20px;
    padding-bottom: 10px;
}

@media only screen and (max-width: 600px) {
    .header-container {
        background-image: url(//i.imgur.com/obpnQqo.png);
        background-size: cover;
    background-repeat: no-repeat;
    }
}
/* Começo do grid */
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link href="https://fonts.googleapis.com/css?family=Rubik" rel="stylesheet">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/styles.css">
</head>
<body>
   <nav class="menu">
       <ul>
           <li>Home</li>
       </ul>
   </nav>
    <header class="header-container">
       <div class="header-text-container">
            <h1 class="header-text">waifu<span class="loung">Lounge</span></h1>
            <h2 class="header-sub-text">the perfect place to find yours.</h2>
        </div>
    </header>
    
    <section class="pagebox">
        <div class="main-box">e</div>
    </section>
    
    
    
</body>
</html>

  • Valeu <3 had not noticed this detail and also did not know that the space there was important...

  • 1

    Phallus! In CSS space is required in several things.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.