Can't understand why media query isn't working (SOLVED)

I have no idea why my media query isn’t working. I’m just trying to test it at the moment by turning .topHeader green at 768px wide. Here’s my code.

(SOLVED) Just incase anyone else has a problem with @media query not having an effect in Chrome dev tools. Instead of

I used

which is now working.

html

www.waterproofed.com
<header>
  <div class="topHeader">
    <div class="phone">
      <p>Ph: 0497 660 008</p>
    </div>
    <div class="email">
      <p>email: michaelanthony@gmail.com</p>
    </div>
  </div>

  <div class="header">
    <h1 class="title">Waterproofed</h1>
  </div>

  <div class="navBar">
    <ul>
      <li>Home</li>
      <li>About us</li>
      <li>Waterproofing systems</li>
      <li>Contact</li>
    </ul>
  </div>

</header>
<div class="mainSection">
  <img class="image" src="img/TorchOnMembrane.jpg" alt="Tourch on Waterproofing">
  <div class="centered">Tourch-on membrane
  </div>
  <input type="button" name="rollon" value="Learn more" class="button">
</div>
<div class="ourServicesh1">
  <h2>Our services</h2>
</div>

<div class="container">
  <div class="flex1">
    <div class="section1">
      <h4 class="ourServicesh4">Torch-on membraine</h4>
      <ul class="ourServicesul">
        <li>Last 20 years</li>
        <li>Highly durable</li>
        <li>UV resistant</li>
        <li>Great for commercial works</li>
      </ul>
    </div>
    <div class="section2">
      <h4 class="ourServicesh4">Polyurethane</h4>
      <ul class="ourServicesul">
        <li>Dynamic product</li>
        <li>10 year warrenty</li>
        <li>Liquid application</li>
        <li>Easy repair</li>
      </ul>
    </div>
  </div>

  <div class="flex2">
    <div class="section3">
      <h4  class="ourServicesh4">Volclay</h4>
      <ul class="ourServicesul">
        <li>Great under water table</li>
        <li>Quick application</li>
        <li>25 year warrenty</li>
        <li>No chemicals</li>
      </ul>
    </div>
    <div class="section4">
      <h4  class="ourServicesh4">Peal and stick</h4>
      <ul class="ourServicesul">
        <li>Easy to use</li>
        <li>Inexpensive</li>
        <li>Best suited vertical jobs</li>
        <li>Quick application</li>
      </ul>
    </div>
  </div>

  <div class="flex3">
    <div class="section5">
      <h4  class="ourServicesh4">Epoxy</h4>
      <ul class="ourServicesul">
        <li>Highly durable</li>
        <li>Liquid application</li>
        <li>Heat and cold resistant</li>
        <li class="bottom">Lifetime warrenty</li>
      </ul>
    </div>
    <div class="section6">
      <h4  class="ourServicesh4">Corking</h4>
      <ul class="ourServicesul">
        <li>Polyurethane based</li>
        <li>non-toxic</li>
        <li>Tube application</li>
      </ul>
    </div>
  </div>
  </div>

css

  • {
    margin: 0;
    padding: 0;
    font-family: ‘Roboto’, sans-serif;
    }

p {
margin: 0;
padding: 0;
}

/=================================================== header =================/
/=================== phone/email ==================/

.topHeader {
width: 100%;
background-color: #0080ff;
height: 40px;
}

.phone {
display: flex;
justify-content: center;
}

.phone p {
color: white;
}

.email {
display: flex;
justify-content: center;
}

.email p {
color: white;
}

/=================== Main heading ==================/

header {
width: 100%;
position: fixed;
z-index: 1;
}

.header {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 60px;
background-color: white;
border-bottom: 1px solid #004d99;
}

.title {
font-family: ‘Staatliches’, cursive;
color: #0080ff;
font-size: 2.8em;
padding-left: 10px;
}

/======================= navbar ======================/

.navBar {
width: 100%;
background-color: #0080ff;
display: flex;
justify-content: space-around;
border-left: 1px solid #004d99;
border-bottom: 1px solid #004d99;
}

.navBar ul {
list-style: none;

}

.navBar ul li {
width: 100%;
display: inline;
color: white;
border-right: 1px solid #004d99;
}

/=========================== main section ===============================/

.mainSection {

}

.image {
width: 100%;
height: 400px;
border-bottom: 10px solid #0080ff;
}

.centered {
width: 100%;
text-align: center;
position: relative;
bottom: 130px;
color: white;
font-size: 1.3em;
word-spacing:
}

.button {
padding: 15px 30px 15px 30px;
background-color: white;
border-radius: 20px;
cursor: pointer;
position: relative;
left: 50%;
bottom: 90px;
transform: translate(-50%, -50%);
font-size: 1em;
}

.button:hover {
animation-name: background-color;
animation-duration: 500ms;
animation-fill-mode: forwards;
}

@keyframes background-color {
100% {
background-color: #0080ff;
}
}

/=========================== our services ===============================/

.ourServicesh1 {
width: 100%;
text-align: center;
padding-bottom: 40px;
color: #0080ff;
}

.flex1 {
width: 100%;
display: flex;
justify-content: space-between;
}

.flex2 {
width: 100%;
display: flex;
justify-content: space-between;
}

.flex3 {
width: 100%;
display: flex;
justify-content: space-between;
}

.ourServicesh4 {
width: 180px;
text-align: center;
color: #0080ff;
padding-bottom: 10px;
padding-top: 10px;
}

.ourServicesul {
list-style: none;
width: 180px;
text-align: center;
}

.bottom {
padding-bottom: 20px;
}

</=================== ipad screen w:768px ==========================/>

@media only screen and (min-width 768px) {
.topHeader {
display: flex;
justify-content: evenly;
background-color: green;
}

}

Hi @Jamtax,

A colon is missing in your media query code. It should be like this:

@media only screen and (min-width: 768px)

also it is kicking in on any screen larger than 768 which is the opposite of what I think you want.
Try max-width that sets it to kick in on any screens smaller than 768px.

the other issue is that I don’t think evenly is a valid value for the justify-content property.
from: https://css-tricks.com/almanac/properties/j/justify-content/

The justify-content property accepts five different values:

  • flex-start ( default ): items are packed toward the start line
  • flex-end : items are packed toward to end line
  • center : items are centered along the line
  • space-between : items are evenly distributed in the line; first item is on the start line, last item on the end line
  • space-around : items are evenly distributed in the line with equal space around them
  • space-evenly : items are distributed so that the spacing between any two adjacent alignment subjects, before the first alignment subject, and after the last alignment subject is the same

Hello @Sunithack1 I have added the colon but still doesn’t seem to be working.

Hey @ChrisCline1138

Oh I think you’re right. I’m trying to design from mobile upwards, isn’t min-width used for mobile design first?

And yes you’re right with space-evenly.

Thank you for your help.

if your first css rules are for a mobile device and the rules in your media queries are for the next size up then yes min-width
I thought you where trying to set up rules for tablet or smaller.

one more issue that is throwing everything off is your comments are not comments

/*=======this is a comment========*/

/========this is not=======/

It works!!

https://codepen.io/chriscline1138/pen/REYawM?editors=1100

whenever you are having problems try the diagnostic tools in codepen they can keep you from ripping your hair out

Took me a while to get my head around which it should be…min-width or max-width. I found it easy to remember like this… max-width: 768px = from 0 up to 768px , min-width: 768px = for screen sizes of 768px or larger.

1 Like

Yeah its a bit counter intuitive

Yeah my first css rules are for mobile w: 375 and then go up from there.

With the comments I don’t know why but when I’ve copied the code /* hasn’t come through. All my comments on atom are /====== example =======/

Ahhh so it does, thank you! Would you typically use screen inspect to check the changes to your web page?

I’ve noticed with codepen when I copy and paste code from a text editor it will get 90% of it right but there will be a couple of bits and pieces which don’t line up with what I see on displaying it through Chrome.

My preferred work flow is with dreamwaver. I open a live preview window and use inspect element to check how everything responds as I go along.