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?
i just switched positions and worked for me (showing only mobile )
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. Replace768px
in the media query with whatever the minimum px value is where your div should be visible.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?
You can be guided by this example. On your css file:
On your html file:
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:
HTML:
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 thevisibility: hidden
attribute. Once the browser/screen reaches 600pixels then#title_message
will become hidden.EDIT: if you are using another CSS for mobile then just add the
visibility: hidden;
to#title_message
. Hope this helps you!