hide div tag on mobile view only?











up vote
47
down vote

favorite
18












I'm creating a fluid layout for a site. I'm trying to hide the contents of a <div> or the whole <div> itself in the mobile view, but not the tablet and desktop view.



Here's what I've got so far...



#title_message {
clear: both;
float: left;
margin: 10px auto 5px 20px;
width: 28%;
display: none;
}


I have the display set to 'none' for the mobile layout and set as block on the tablet/desktop layouts... Is there an easier way to do that, or is that it?










share|improve this question




























    up vote
    47
    down vote

    favorite
    18












    I'm creating a fluid layout for a site. I'm trying to hide the contents of a <div> or the whole <div> itself in the mobile view, but not the tablet and desktop view.



    Here's what I've got so far...



    #title_message {
    clear: both;
    float: left;
    margin: 10px auto 5px 20px;
    width: 28%;
    display: none;
    }


    I have the display set to 'none' for the mobile layout and set as block on the tablet/desktop layouts... Is there an easier way to do that, or is that it?










    share|improve this question


























      up vote
      47
      down vote

      favorite
      18









      up vote
      47
      down vote

      favorite
      18






      18





      I'm creating a fluid layout for a site. I'm trying to hide the contents of a <div> or the whole <div> itself in the mobile view, but not the tablet and desktop view.



      Here's what I've got so far...



      #title_message {
      clear: both;
      float: left;
      margin: 10px auto 5px 20px;
      width: 28%;
      display: none;
      }


      I have the display set to 'none' for the mobile layout and set as block on the tablet/desktop layouts... Is there an easier way to do that, or is that it?










      share|improve this question















      I'm creating a fluid layout for a site. I'm trying to hide the contents of a <div> or the whole <div> itself in the mobile view, but not the tablet and desktop view.



      Here's what I've got so far...



      #title_message {
      clear: both;
      float: left;
      margin: 10px auto 5px 20px;
      width: 28%;
      display: none;
      }


      I have the display set to 'none' for the mobile layout and set as block on the tablet/desktop layouts... Is there an easier way to do that, or is that it?







      css fluid-layout






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 6 '13 at 16:04









      Brad Christie

      86.5k13119175




      86.5k13119175










      asked May 14 '13 at 18:43









      KoldTurkee

      362149




      362149
























          7 Answers
          7






          active

          oldest

          votes

















          up vote
          112
          down vote



          accepted










          You will need two things. The first is @media screen to activate the specific code at a certain screen size, used for responsive design. The second is the use of the visibility: hidden attribute. Once the browser/screen reaches 600pixels then #title_message will become hidden.



          @media screen and (max-width: 600px) {
          #title_message {
          visibility: hidden;
          clear: both;
          float: left;
          margin: 10px auto 5px 20px;
          width: 28%;
          display: none;
          }
          }


          EDIT: if you are using another CSS for mobile then just add the visibility: hidden; to #title_message. Hope this helps you!






          share|improve this answer























          • That fixed it. Thanks Matt!
            – KoldTurkee
            May 15 '13 at 23:40










          • I'm glad that worked! Thanks for marking the answer as correct.
            – Matt
            May 16 '13 at 13:18










          • When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
            – josh.thomson
            Sep 4 '14 at 15:20










          • It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
            – gnganpath
            Jan 23 '16 at 12:32




















          up vote
          3
          down vote













          @media only screen 
          and (min-device-width : 320px)
          and (max-device-width : 480px) { #title_message { display: none; }}


          This would be for a responsive design with a single page for an iphone screen specifically. Are you actually routing to a different mobile page?






          share|improve this answer























          • That didn't work. It wiped out all the CSS for the mobile layout.
            – KoldTurkee
            May 14 '13 at 18:51










          • Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
            – Scarecrow
            May 14 '13 at 19:16










          • This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
            – Angel
            Aug 3 '15 at 14:41




















          up vote
          2
          down vote













          Set the display property to none as the default, then use a media query to apply the desired styles to the div when the browser reaches a certain width. Replace 768px in the media query with whatever the minimum px value is where your div should be visible.



          #title_message {
          display: none;
          }

          @media screen and (min-width: 768px) {
          #title_message {
          clear: both;
          display: block;
          float: left;
          margin: 10px auto 5px 20px;
          width: 28%;
          }
          }





          share|improve this answer





















          • That's the wrong way round. The div won't display on browsers that don't support media queries.
            – MMM
            May 14 '13 at 20:43










          • respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
            – Phil Sinatra
            May 15 '13 at 0:05








          • 1




            Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
            – MMM
            May 15 '13 at 9:08






          • 2




            I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
            – Phil Sinatra
            May 15 '13 at 11:44










          • @MMM That's actually how mobile-first design is: from the bottom up.
            – SepehrM
            Apr 19 '16 at 19:18


















          up vote
          1
          down vote













          You can be guided by this example. On your css file:



          .deskContent {
          background-image: url(../img/big-pic.png);
          width: 100%;
          height: 400px;
          background-repeat: no-repeat;
          background-size: contain;
          }

          .phoneContent {
          background-image: url(../img/small-pic.png);
          width: 100%;
          height: 100px;
          background-repeat: no-repeat;
          background-size: contain;
          }

          @media all and (max-width: 959px) {
          .deskContent {display:block;}
          .phoneContent {display:none;}
          }

          @media all and (max-width: 479px) {
          .deskContent {display:none;}
          .phoneContent {display:block;}
          }


          On your html file:



          <div class="deskContent">Content for desktop</div>
          <div class="phoneContent">Content for mobile</div>





          share|improve this answer




























            up vote
            1
            down vote













            The solution given didn't work for me on the desktop, it just showed both divs, although the mobile only showed the mobile div. So I did a little search and found the min-width option. I updated my code to the following and it works fine now :)



            CSS:



                @media all and (min-width: 480px) {
            .deskContent {display:block;}
            .phoneContent {display:none;}
            }

            @media all and (max-width: 479px) {
            .deskContent {display:none;}
            .phoneContent {display:block;}
            }


            HTML:



            <div class="deskContent">Content for desktop</div>
            <div class="phoneContent">Content for mobile</div>





            share|improve this answer




























              up vote
              0
              down vote













              try this



              @media handheld{
              #title_message { display: none; }
              }





              share|improve this answer




























                up vote
                0
                down vote













                i just switched positions and worked for me (showing only mobile )






                <style>
                .MobileContent {

                display: none;
                text-align:center;

                }

                @media screen and (max-width: 768px) {

                .MobileContent {

                display:block;

                }

                }
                </style>
                <div class="MobileContent"> Something </div>








                share|improve this answer





















                  Your Answer






                  StackExchange.ifUsing("editor", function () {
                  StackExchange.using("externalEditor", function () {
                  StackExchange.using("snippets", function () {
                  StackExchange.snippets.init();
                  });
                  });
                  }, "code-snippets");

                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "1"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  convertImagesToLinks: true,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: 10,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16550485%2fhide-div-tag-on-mobile-view-only%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  7 Answers
                  7






                  active

                  oldest

                  votes








                  7 Answers
                  7






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes








                  up vote
                  112
                  down vote



                  accepted










                  You will need two things. The first is @media screen to activate the specific code at a certain screen size, used for responsive design. The second is the use of the visibility: hidden attribute. Once the browser/screen reaches 600pixels then #title_message will become hidden.



                  @media screen and (max-width: 600px) {
                  #title_message {
                  visibility: hidden;
                  clear: both;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  display: none;
                  }
                  }


                  EDIT: if you are using another CSS for mobile then just add the visibility: hidden; to #title_message. Hope this helps you!






                  share|improve this answer























                  • That fixed it. Thanks Matt!
                    – KoldTurkee
                    May 15 '13 at 23:40










                  • I'm glad that worked! Thanks for marking the answer as correct.
                    – Matt
                    May 16 '13 at 13:18










                  • When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
                    – josh.thomson
                    Sep 4 '14 at 15:20










                  • It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
                    – gnganpath
                    Jan 23 '16 at 12:32

















                  up vote
                  112
                  down vote



                  accepted










                  You will need two things. The first is @media screen to activate the specific code at a certain screen size, used for responsive design. The second is the use of the visibility: hidden attribute. Once the browser/screen reaches 600pixels then #title_message will become hidden.



                  @media screen and (max-width: 600px) {
                  #title_message {
                  visibility: hidden;
                  clear: both;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  display: none;
                  }
                  }


                  EDIT: if you are using another CSS for mobile then just add the visibility: hidden; to #title_message. Hope this helps you!






                  share|improve this answer























                  • That fixed it. Thanks Matt!
                    – KoldTurkee
                    May 15 '13 at 23:40










                  • I'm glad that worked! Thanks for marking the answer as correct.
                    – Matt
                    May 16 '13 at 13:18










                  • When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
                    – josh.thomson
                    Sep 4 '14 at 15:20










                  • It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
                    – gnganpath
                    Jan 23 '16 at 12:32















                  up vote
                  112
                  down vote



                  accepted







                  up vote
                  112
                  down vote



                  accepted






                  You will need two things. The first is @media screen to activate the specific code at a certain screen size, used for responsive design. The second is the use of the visibility: hidden attribute. Once the browser/screen reaches 600pixels then #title_message will become hidden.



                  @media screen and (max-width: 600px) {
                  #title_message {
                  visibility: hidden;
                  clear: both;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  display: none;
                  }
                  }


                  EDIT: if you are using another CSS for mobile then just add the visibility: hidden; to #title_message. Hope this helps you!






                  share|improve this answer














                  You will need two things. The first is @media screen to activate the specific code at a certain screen size, used for responsive design. The second is the use of the visibility: hidden attribute. Once the browser/screen reaches 600pixels then #title_message will become hidden.



                  @media screen and (max-width: 600px) {
                  #title_message {
                  visibility: hidden;
                  clear: both;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  display: none;
                  }
                  }


                  EDIT: if you are using another CSS for mobile then just add the visibility: hidden; to #title_message. Hope this helps you!







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Feb 1 at 5:22









                  Jason Aller

                  3,04192831




                  3,04192831










                  answered May 14 '13 at 21:28









                  Matt

                  1,5231920




                  1,5231920












                  • That fixed it. Thanks Matt!
                    – KoldTurkee
                    May 15 '13 at 23:40










                  • I'm glad that worked! Thanks for marking the answer as correct.
                    – Matt
                    May 16 '13 at 13:18










                  • When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
                    – josh.thomson
                    Sep 4 '14 at 15:20










                  • It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
                    – gnganpath
                    Jan 23 '16 at 12:32




















                  • That fixed it. Thanks Matt!
                    – KoldTurkee
                    May 15 '13 at 23:40










                  • I'm glad that worked! Thanks for marking the answer as correct.
                    – Matt
                    May 16 '13 at 13:18










                  • When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
                    – josh.thomson
                    Sep 4 '14 at 15:20










                  • It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
                    – gnganpath
                    Jan 23 '16 at 12:32


















                  That fixed it. Thanks Matt!
                  – KoldTurkee
                  May 15 '13 at 23:40




                  That fixed it. Thanks Matt!
                  – KoldTurkee
                  May 15 '13 at 23:40












                  I'm glad that worked! Thanks for marking the answer as correct.
                  – Matt
                  May 16 '13 at 13:18




                  I'm glad that worked! Thanks for marking the answer as correct.
                  – Matt
                  May 16 '13 at 13:18












                  When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
                  – josh.thomson
                  Sep 4 '14 at 15:20




                  When you come to StackOverflow... there's always going to be a solution to your query..... Except, most of the time I seem to come across slight alternatives. ...This answer is exactly what I was looking for! ...Thank you Dude. (p.s. used for a custom mobile menu on my site amazewebs.com ...mobile menu will show when width<768px
                  – josh.thomson
                  Sep 4 '14 at 15:20












                  It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
                  – gnganpath
                  Jan 23 '16 at 12:32






                  It's working for me. Have to display only mobile pages@media screen and (min-width: 700px) { .mobile-title { visibility: hidden; } } div.mobile-title h1 { text-align: center !important; font-size: 20px; font-weight: bold; padding: 5px; }
                  – gnganpath
                  Jan 23 '16 at 12:32














                  up vote
                  3
                  down vote













                  @media only screen 
                  and (min-device-width : 320px)
                  and (max-device-width : 480px) { #title_message { display: none; }}


                  This would be for a responsive design with a single page for an iphone screen specifically. Are you actually routing to a different mobile page?






                  share|improve this answer























                  • That didn't work. It wiped out all the CSS for the mobile layout.
                    – KoldTurkee
                    May 14 '13 at 18:51










                  • Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
                    – Scarecrow
                    May 14 '13 at 19:16










                  • This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
                    – Angel
                    Aug 3 '15 at 14:41

















                  up vote
                  3
                  down vote













                  @media only screen 
                  and (min-device-width : 320px)
                  and (max-device-width : 480px) { #title_message { display: none; }}


                  This would be for a responsive design with a single page for an iphone screen specifically. Are you actually routing to a different mobile page?






                  share|improve this answer























                  • That didn't work. It wiped out all the CSS for the mobile layout.
                    – KoldTurkee
                    May 14 '13 at 18:51










                  • Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
                    – Scarecrow
                    May 14 '13 at 19:16










                  • This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
                    – Angel
                    Aug 3 '15 at 14:41















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  @media only screen 
                  and (min-device-width : 320px)
                  and (max-device-width : 480px) { #title_message { display: none; }}


                  This would be for a responsive design with a single page for an iphone screen specifically. Are you actually routing to a different mobile page?






                  share|improve this answer














                  @media only screen 
                  and (min-device-width : 320px)
                  and (max-device-width : 480px) { #title_message { display: none; }}


                  This would be for a responsive design with a single page for an iphone screen specifically. Are you actually routing to a different mobile page?







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 13 '16 at 5:10









                  Munawir

                  2,80782237




                  2,80782237










                  answered May 14 '13 at 18:46









                  Scarecrow

                  1257




                  1257












                  • That didn't work. It wiped out all the CSS for the mobile layout.
                    – KoldTurkee
                    May 14 '13 at 18:51










                  • Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
                    – Scarecrow
                    May 14 '13 at 19:16










                  • This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
                    – Angel
                    Aug 3 '15 at 14:41




















                  • That didn't work. It wiped out all the CSS for the mobile layout.
                    – KoldTurkee
                    May 14 '13 at 18:51










                  • Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
                    – Scarecrow
                    May 14 '13 at 19:16










                  • This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
                    – Angel
                    Aug 3 '15 at 14:41


















                  That didn't work. It wiped out all the CSS for the mobile layout.
                  – KoldTurkee
                  May 14 '13 at 18:51




                  That didn't work. It wiped out all the CSS for the mobile layout.
                  – KoldTurkee
                  May 14 '13 at 18:51












                  Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
                  – Scarecrow
                  May 14 '13 at 19:16




                  Can you provide a small sample of your css then? I'm not seeing the whole picture here but that shouldn't have wiped out your layout
                  – Scarecrow
                  May 14 '13 at 19:16












                  This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
                  – Angel
                  Aug 3 '15 at 14:41






                  This work better, because visibility: hidden only hide the element but still there (the place remains). Instead display: none; really hide it and completely removing it.
                  – Angel
                  Aug 3 '15 at 14:41












                  up vote
                  2
                  down vote













                  Set the display property to none as the default, then use a media query to apply the desired styles to the div when the browser reaches a certain width. Replace 768px in the media query with whatever the minimum px value is where your div should be visible.



                  #title_message {
                  display: none;
                  }

                  @media screen and (min-width: 768px) {
                  #title_message {
                  clear: both;
                  display: block;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  }
                  }





                  share|improve this answer





















                  • That's the wrong way round. The div won't display on browsers that don't support media queries.
                    – MMM
                    May 14 '13 at 20:43










                  • respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
                    – Phil Sinatra
                    May 15 '13 at 0:05








                  • 1




                    Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
                    – MMM
                    May 15 '13 at 9:08






                  • 2




                    I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
                    – Phil Sinatra
                    May 15 '13 at 11:44










                  • @MMM That's actually how mobile-first design is: from the bottom up.
                    – SepehrM
                    Apr 19 '16 at 19:18















                  up vote
                  2
                  down vote













                  Set the display property to none as the default, then use a media query to apply the desired styles to the div when the browser reaches a certain width. Replace 768px in the media query with whatever the minimum px value is where your div should be visible.



                  #title_message {
                  display: none;
                  }

                  @media screen and (min-width: 768px) {
                  #title_message {
                  clear: both;
                  display: block;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  }
                  }





                  share|improve this answer





















                  • That's the wrong way round. The div won't display on browsers that don't support media queries.
                    – MMM
                    May 14 '13 at 20:43










                  • respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
                    – Phil Sinatra
                    May 15 '13 at 0:05








                  • 1




                    Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
                    – MMM
                    May 15 '13 at 9:08






                  • 2




                    I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
                    – Phil Sinatra
                    May 15 '13 at 11:44










                  • @MMM That's actually how mobile-first design is: from the bottom up.
                    – SepehrM
                    Apr 19 '16 at 19:18













                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Set the display property to none as the default, then use a media query to apply the desired styles to the div when the browser reaches a certain width. Replace 768px in the media query with whatever the minimum px value is where your div should be visible.



                  #title_message {
                  display: none;
                  }

                  @media screen and (min-width: 768px) {
                  #title_message {
                  clear: both;
                  display: block;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  }
                  }





                  share|improve this answer












                  Set the display property to none as the default, then use a media query to apply the desired styles to the div when the browser reaches a certain width. Replace 768px in the media query with whatever the minimum px value is where your div should be visible.



                  #title_message {
                  display: none;
                  }

                  @media screen and (min-width: 768px) {
                  #title_message {
                  clear: both;
                  display: block;
                  float: left;
                  margin: 10px auto 5px 20px;
                  width: 28%;
                  }
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 14 '13 at 20:27









                  Phil Sinatra

                  199111




                  199111












                  • That's the wrong way round. The div won't display on browsers that don't support media queries.
                    – MMM
                    May 14 '13 at 20:43










                  • respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
                    – Phil Sinatra
                    May 15 '13 at 0:05








                  • 1




                    Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
                    – MMM
                    May 15 '13 at 9:08






                  • 2




                    I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
                    – Phil Sinatra
                    May 15 '13 at 11:44










                  • @MMM That's actually how mobile-first design is: from the bottom up.
                    – SepehrM
                    Apr 19 '16 at 19:18


















                  • That's the wrong way round. The div won't display on browsers that don't support media queries.
                    – MMM
                    May 14 '13 at 20:43










                  • respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
                    – Phil Sinatra
                    May 15 '13 at 0:05








                  • 1




                    Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
                    – MMM
                    May 15 '13 at 9:08






                  • 2




                    I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
                    – Phil Sinatra
                    May 15 '13 at 11:44










                  • @MMM That's actually how mobile-first design is: from the bottom up.
                    – SepehrM
                    Apr 19 '16 at 19:18
















                  That's the wrong way round. The div won't display on browsers that don't support media queries.
                  – MMM
                  May 14 '13 at 20:43




                  That's the wrong way round. The div won't display on browsers that don't support media queries.
                  – MMM
                  May 14 '13 at 20:43












                  respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
                  – Phil Sinatra
                  May 15 '13 at 0:05






                  respond.js github.com/scottjehl/Respond will solve this on older browsers that don't support media queries. Media queries are the solution for responsive sites.
                  – Phil Sinatra
                  May 15 '13 at 0:05






                  1




                  1




                  Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
                  – MMM
                  May 15 '13 at 9:08




                  Of course they are the solution, but you're doing this the wrong way round. Unless your website is mostly used for mobile, you never build your css from the bottom up.
                  – MMM
                  May 15 '13 at 9:08




                  2




                  2




                  I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
                  – Phil Sinatra
                  May 15 '13 at 11:44




                  I don't consider mobile and desktop as separate websites. It is much easier to scale a project up as the browser gets bigger than it is to trim down as the browser gets smaller. In this case, KT is building responsive site, regardless of if it is "mostly" used for mobile or simply optimized for all browsers. A mobile first approach saves the mobile browsers from having to load additional CSS styles that never are actually applied. This approach is not the wrong way, it's simply not the way you suggest building your css.
                  – Phil Sinatra
                  May 15 '13 at 11:44












                  @MMM That's actually how mobile-first design is: from the bottom up.
                  – SepehrM
                  Apr 19 '16 at 19:18




                  @MMM That's actually how mobile-first design is: from the bottom up.
                  – SepehrM
                  Apr 19 '16 at 19:18










                  up vote
                  1
                  down vote













                  You can be guided by this example. On your css file:



                  .deskContent {
                  background-image: url(../img/big-pic.png);
                  width: 100%;
                  height: 400px;
                  background-repeat: no-repeat;
                  background-size: contain;
                  }

                  .phoneContent {
                  background-image: url(../img/small-pic.png);
                  width: 100%;
                  height: 100px;
                  background-repeat: no-repeat;
                  background-size: contain;
                  }

                  @media all and (max-width: 959px) {
                  .deskContent {display:block;}
                  .phoneContent {display:none;}
                  }

                  @media all and (max-width: 479px) {
                  .deskContent {display:none;}
                  .phoneContent {display:block;}
                  }


                  On your html file:



                  <div class="deskContent">Content for desktop</div>
                  <div class="phoneContent">Content for mobile</div>





                  share|improve this answer

























                    up vote
                    1
                    down vote













                    You can be guided by this example. On your css file:



                    .deskContent {
                    background-image: url(../img/big-pic.png);
                    width: 100%;
                    height: 400px;
                    background-repeat: no-repeat;
                    background-size: contain;
                    }

                    .phoneContent {
                    background-image: url(../img/small-pic.png);
                    width: 100%;
                    height: 100px;
                    background-repeat: no-repeat;
                    background-size: contain;
                    }

                    @media all and (max-width: 959px) {
                    .deskContent {display:block;}
                    .phoneContent {display:none;}
                    }

                    @media all and (max-width: 479px) {
                    .deskContent {display:none;}
                    .phoneContent {display:block;}
                    }


                    On your html file:



                    <div class="deskContent">Content for desktop</div>
                    <div class="phoneContent">Content for mobile</div>





                    share|improve this answer























                      up vote
                      1
                      down vote










                      up vote
                      1
                      down vote









                      You can be guided by this example. On your css file:



                      .deskContent {
                      background-image: url(../img/big-pic.png);
                      width: 100%;
                      height: 400px;
                      background-repeat: no-repeat;
                      background-size: contain;
                      }

                      .phoneContent {
                      background-image: url(../img/small-pic.png);
                      width: 100%;
                      height: 100px;
                      background-repeat: no-repeat;
                      background-size: contain;
                      }

                      @media all and (max-width: 959px) {
                      .deskContent {display:block;}
                      .phoneContent {display:none;}
                      }

                      @media all and (max-width: 479px) {
                      .deskContent {display:none;}
                      .phoneContent {display:block;}
                      }


                      On your html file:



                      <div class="deskContent">Content for desktop</div>
                      <div class="phoneContent">Content for mobile</div>





                      share|improve this answer












                      You can be guided by this example. On your css file:



                      .deskContent {
                      background-image: url(../img/big-pic.png);
                      width: 100%;
                      height: 400px;
                      background-repeat: no-repeat;
                      background-size: contain;
                      }

                      .phoneContent {
                      background-image: url(../img/small-pic.png);
                      width: 100%;
                      height: 100px;
                      background-repeat: no-repeat;
                      background-size: contain;
                      }

                      @media all and (max-width: 959px) {
                      .deskContent {display:block;}
                      .phoneContent {display:none;}
                      }

                      @media all and (max-width: 479px) {
                      .deskContent {display:none;}
                      .phoneContent {display:block;}
                      }


                      On your html file:



                      <div class="deskContent">Content for desktop</div>
                      <div class="phoneContent">Content for mobile</div>






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Apr 19 '17 at 21:20









                      gras

                      1,2821217




                      1,2821217






















                          up vote
                          1
                          down vote













                          The solution given didn't work for me on the desktop, it just showed both divs, although the mobile only showed the mobile div. So I did a little search and found the min-width option. I updated my code to the following and it works fine now :)



                          CSS:



                              @media all and (min-width: 480px) {
                          .deskContent {display:block;}
                          .phoneContent {display:none;}
                          }

                          @media all and (max-width: 479px) {
                          .deskContent {display:none;}
                          .phoneContent {display:block;}
                          }


                          HTML:



                          <div class="deskContent">Content for desktop</div>
                          <div class="phoneContent">Content for mobile</div>





                          share|improve this answer

























                            up vote
                            1
                            down vote













                            The solution given didn't work for me on the desktop, it just showed both divs, although the mobile only showed the mobile div. So I did a little search and found the min-width option. I updated my code to the following and it works fine now :)



                            CSS:



                                @media all and (min-width: 480px) {
                            .deskContent {display:block;}
                            .phoneContent {display:none;}
                            }

                            @media all and (max-width: 479px) {
                            .deskContent {display:none;}
                            .phoneContent {display:block;}
                            }


                            HTML:



                            <div class="deskContent">Content for desktop</div>
                            <div class="phoneContent">Content for mobile</div>





                            share|improve this answer























                              up vote
                              1
                              down vote










                              up vote
                              1
                              down vote









                              The solution given didn't work for me on the desktop, it just showed both divs, although the mobile only showed the mobile div. So I did a little search and found the min-width option. I updated my code to the following and it works fine now :)



                              CSS:



                                  @media all and (min-width: 480px) {
                              .deskContent {display:block;}
                              .phoneContent {display:none;}
                              }

                              @media all and (max-width: 479px) {
                              .deskContent {display:none;}
                              .phoneContent {display:block;}
                              }


                              HTML:



                              <div class="deskContent">Content for desktop</div>
                              <div class="phoneContent">Content for mobile</div>





                              share|improve this answer












                              The solution given didn't work for me on the desktop, it just showed both divs, although the mobile only showed the mobile div. So I did a little search and found the min-width option. I updated my code to the following and it works fine now :)



                              CSS:



                                  @media all and (min-width: 480px) {
                              .deskContent {display:block;}
                              .phoneContent {display:none;}
                              }

                              @media all and (max-width: 479px) {
                              .deskContent {display:none;}
                              .phoneContent {display:block;}
                              }


                              HTML:



                              <div class="deskContent">Content for desktop</div>
                              <div class="phoneContent">Content for mobile</div>






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 2 '17 at 22:15









                              Steve Hall

                              135




                              135






















                                  up vote
                                  0
                                  down vote













                                  try this



                                  @media handheld{
                                  #title_message { display: none; }
                                  }





                                  share|improve this answer

























                                    up vote
                                    0
                                    down vote













                                    try this



                                    @media handheld{
                                    #title_message { display: none; }
                                    }





                                    share|improve this answer























                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      try this



                                      @media handheld{
                                      #title_message { display: none; }
                                      }





                                      share|improve this answer












                                      try this



                                      @media handheld{
                                      #title_message { display: none; }
                                      }






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered May 14 '13 at 21:20









                                      Alejandro Ruiz Arias

                                      121111




                                      121111






















                                          up vote
                                          0
                                          down vote













                                          i just switched positions and worked for me (showing only mobile )






                                          <style>
                                          .MobileContent {

                                          display: none;
                                          text-align:center;

                                          }

                                          @media screen and (max-width: 768px) {

                                          .MobileContent {

                                          display:block;

                                          }

                                          }
                                          </style>
                                          <div class="MobileContent"> Something </div>








                                          share|improve this answer

























                                            up vote
                                            0
                                            down vote













                                            i just switched positions and worked for me (showing only mobile )






                                            <style>
                                            .MobileContent {

                                            display: none;
                                            text-align:center;

                                            }

                                            @media screen and (max-width: 768px) {

                                            .MobileContent {

                                            display:block;

                                            }

                                            }
                                            </style>
                                            <div class="MobileContent"> Something </div>








                                            share|improve this answer























                                              up vote
                                              0
                                              down vote










                                              up vote
                                              0
                                              down vote









                                              i just switched positions and worked for me (showing only mobile )






                                              <style>
                                              .MobileContent {

                                              display: none;
                                              text-align:center;

                                              }

                                              @media screen and (max-width: 768px) {

                                              .MobileContent {

                                              display:block;

                                              }

                                              }
                                              </style>
                                              <div class="MobileContent"> Something </div>








                                              share|improve this answer












                                              i just switched positions and worked for me (showing only mobile )






                                              <style>
                                              .MobileContent {

                                              display: none;
                                              text-align:center;

                                              }

                                              @media screen and (max-width: 768px) {

                                              .MobileContent {

                                              display:block;

                                              }

                                              }
                                              </style>
                                              <div class="MobileContent"> Something </div>








                                              <style>
                                              .MobileContent {

                                              display: none;
                                              text-align:center;

                                              }

                                              @media screen and (max-width: 768px) {

                                              .MobileContent {

                                              display:block;

                                              }

                                              }
                                              </style>
                                              <div class="MobileContent"> Something </div>





                                              <style>
                                              .MobileContent {

                                              display: none;
                                              text-align:center;

                                              }

                                              @media screen and (max-width: 768px) {

                                              .MobileContent {

                                              display:block;

                                              }

                                              }
                                              </style>
                                              <div class="MobileContent"> Something </div>






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Mar 15 at 23:07









                                              Carlos franco

                                              1




                                              1






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to Stack Overflow!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.





                                                  Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                                  Please pay close attention to the following guidance:


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f16550485%2fhide-div-tag-on-mobile-view-only%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  How to pass form data using jquery Ajax to insert data in database?

                                                  National Museum of Racing and Hall of Fame

                                                  Guess what letter conforming each word