0

I am trying to hide an add when the screen is smaller than a certain size.

the relevant html section is:

<div id="content">
  <div id="articles">
    <h2>Article</h2>
    <p>Some article text.  Yadda yadda yadda yadda yadda.</p>
    <h2>Another Article</h2>
    <p>Some more article text.  Yadda yadda yadda yadda yadda...</p>
    <img src="ad.jpg" class="bannerad">
  </div>

the css I have now is:

@media screen and (max-width:480px)
 {
    #menu 
      {
       background-color: green;
      }
    #menu li
      {
       display:block;
       padding:15px;
       margin:0px;
      }
    #header 
      {
       color:green;
       font-style:italic;
       text-transform: uppercase;
      }
    #content h2{color:green};
    .bannerad {display:none};
}

how do i format the bannerad section to hide the ad?

3
  • You can always use javascript/jquery to add/remove/append css classes on any element, depending on various conditions, for your page. Commented Jan 11, 2018 at 21:24
  • how is this done? I am trying to hide the ad Commented Jan 11, 2018 at 21:32
  • Something like: if ($(window).width() < 960) { document.getElementById('elementId').style.display = 'none'; } in jquery. Here is some links for your reference: stackoverflow.com/questions/4396983/hide-or-display-none-jquery, stackoverflow.com/questions/7715124/… Commented Jan 11, 2018 at 21:37

1 Answer 1

1
@media screen and (max-width:480px) {
    #menu {
        background-color: green;
    }

    #menu li {
        display:block;
        padding:15px;
        margin:0px;
    }

    #header {
        color:green;
        font-style:italic;
        text-transform: uppercase;
    }

    #content h2 {
        color: green;
    }

    .bannerad {
        display: none;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

this works well, i did not know the semicolons worked this way as I am new. thanks!
Btw don't forget to accept the answer if it's the correct one so the question gets closed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.