Paul just posted about this and pretty much sums it up:
Coding isnât that much different. It should be a fluid layout from the get-go and if something doesnât work well in smaller widths, make a change to keep it good looking. Nothing big.
I have found this Javascript code to detect small screens and it works! I am pretty sure you are going to tell me there are problem with using Javascript otherwise you would have suggested it to me?
I suppose one problem is I cannot redirect people to the FULL desktop site. Or is there a way to miss out this piece of Javascript if the user wishes to?
@media (max-width:575px)
{
/*this will affect 575px and down. Even on desktop (if you minimize your window enough). But this will mainlyaffect mobile and maybe some small tablets. Customize the pixel value!*/
}
That would not redirect. You could make your website responsive, which is the way to go when making websites. Ideally, you wonât need to change that much about your website to make it great in mobile. Maybe make a hamburger type menu for mobile to make it easier, but if you actually code your website to be fluid and shrink down and expand as the screen changes, then media queries will be minimal.
I have a fully fledged website for hte most part here
@media (max-width:575px)
{
.responsivefooter
{
width: 100%;
height: 200px;
} /*adsense*/
#container
{
max-width:95%;
min-width:initial;
padding:1px
}
#header>a
{
width: 100%;
min-width:initial;
max-width:none;
height: auto;
}
#header>a>img
{
max-height:none;
height:auto;
}
ul#navigation
{
float:none;
min-width:initial;
width:100%;
}
.portfolio #mainContent ul li
{
float:none;
text-align:center;
width:auto;
}
body #footer>div
{
margin:0!important;/*!important is for the .links so I don't have to add rules*/
float:none!important;
width:auto!important;
padding:5px;
overflow:hidden;
border-bottom:1px solid #666;
}
.followFooter a
{
clear:none;
margin-right:20px;
}
.followHeader a
{
margin-left:1px;
}
.followHeader
{
clear:none;
float:left;
min-width:initial;
}
.search
{
float:left;
margin-left:5px;
}
.search input
{
width:100px;
}
.followHeader img, .followFooter img
{
width:40px;
height:40px;
}
ul#navigation li:first-child
{
display:none;
}
ul#navigation li
{
width:16.66%;
}
#lightbox img
{
max-width:100%;
}
#sidebar
{
display:none;
}
#main
{
background-image:none;
}
#mainContent
{
border:0;
border-top:1px solid transparent;
left:0;
position:static;
padding:0;
margin:0;
}
.portfolio ul li
{
width:auto;
margin:0;
}
.portfolio ul li a img
{
width:auto;
}
#footer .links a:active
{
background-color:#38BCD9;
color:#000;
}
#footer input[type=submit]
{
vertical-align:middle;
}
}
If you shrink it to mobile, yo uwill notice the header changes, and the footer. I also remove the left navigation. Thatâs 90% of my responsive code right there. Very simple to do. So now it looks like I have two sites but in reality the HTML is one single webpage and then some CSS to style it to my liking for mobile.
Letâs say on mobile, I wanted the Portfolio link to go away. The portfolio link has a class on it already if I remember correctly so I donât need to do anything there.
In my media query, I would then target the .portfolio link for 575 and blow, and just dispay:none; that. Does that make sense?
If you wanted TWO navigation menus (one specifically for mobile and one specifically for large) then give the navigation menus a class each, and do the same thing. Hide one on hte media query etc.
I have managed to code in the @media that it gets rid of the main navigation bar. I have also coded it to say add a smaller navigation bar.
However, my problem now is if the screen is larger than 575px it is showing both what is in the @media and the larger navigation bar and it is not displaying properly (CSS is not applied).
On mobile devices it works fine though, as I said. So how do i code it to say if the screen is larger that 575px the smaller navigation bar is not there but the large one is? What are I missing?
Post the HTML for the large and small navigation bar. And then post the CSS that you believe should be hiding the small navigation bar for small screens. Also give the media query code taht hides the big/shows the small.
Sorry to disobey you but I am only including the HTML. I have sorted the problem apart from this HTML. The problem is in the @media the styling is applied. When the screen size is larger that 575px it is only the styling that is not applied (but the small navigation bar still shows without the styling). I have tried adding display:none; to the main CSS but then it never shows (i.e⌠the @media does not override the main CSS styling).
Any ideas? Basically when the screen is bigger that 575px the small navigation bar displays as well as the bigger navigation bar but the small navigation bar has no styling. But the small navigation should not be there at all.
Your mobile media query needs to be after your large desktop rules. Otherwise it wonât overrule the large desktop rules since you use the same specificity.
<!DOCTYPE HTML>
<html>
<head><link href="css/mobilestyles.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
<style>
@charset "UTF-8";
/* CSS Document */
h1{font-size:20px;font-family:Arial;font-weight:500;color: #000000;}
h2{font-size:20px;font-family:Arial;font-weight:500;color: #000000;}
h3{font-size:20px;font-family:Arial;font-weight:500;color: #000000;}
h4{font-size:20px;font-family:Arial;font-weight:500;color: #000000;}
h5{font-size:20px;font-family:Arial;font-weight:500;color: #000000;}
h6{font-size:20px;font-family:Arial;font-weight:500;color: #000000;}
h1, h2, h3, h4, h5, h6{
margin-top:20px;
margin-bottom:10px;
}
body {
max-width: 1024px;
font-family: Arial, Helvetica, sans-serif;
font-size:87.5%;
background-image:url('../images/navigation/wallpaper.gif');
}
#container {
width:975px;
margin:0 auto;
padding:5px;
border:1px solid #cccccc;
background:#ffffff;
}
#navigation{
width: 970px;
float: left;
}
#navigation1
{
display:none;
}
#menu{
margin:0;
padding:0;
}
#menu ul{
margin:0;
padding:0;
line-height:27px;
}
#menu li{
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
background:#009900;
}
#menu ul li a{
background: url(../images/navigation/line.gif) bottom right no-repeat;
text-align:center;
font-family:"Helvetica";
text-decoration:none;
height:27px;
width:139px;
display: block;
color:#FFF;
border:none;
}
#menu ul ul{
position:absolute;
visibility:hidden;
top:27px;
}
#menu ul li:hover ul{
visibility:visible;
top:27px;
}
#menu li:hover{
background:grey;
}
#menu ul li:hover ul li a:hover{
background:#009900;
color:white;
text-decoration:underline;
}
@media (max-width:575px)
{
#navigation1{
width: 300px;
float: left;
display:block;
}
#smallmenu{
margin:0;
padding:0;
}
#smallmenu ul{
margin:0;
padding:0;
line-height:27px;
}
#smallmenu li{
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
background:#009900;
}
#smallmenu ul li a{
background: url(../images/navigation/line.gif) bottom right no-repeat;
text-align:center;
font-family:"Helvetica";
text-decoration:none;
height:27px;
width:139px;
display: block;
color:#FFF;
border:none;
}
#smallmenu ul ul{
position:absolute;
visibility:hidden;
top:27px;
}
#smallmenu ul li:hover ul{
visibility:visible;
top:27px;
}
#smallmenu li:hover{
background:grey;
}
#smallmenu ul li:hover ul li a:hover{
background:#009900;
color:white;
text-decoration:underline;
}
#navmenu{
display:none;
margin:0;
padding:0;
}
#navigation{
display:none;
margin:0;
padding:0;
}
/*this will affect 575px and down. Even on desktop (if you minimize your window enough). But this will mainlyaffect mobile and maybe some small tablets. Customize the pixel value!*/
}
</style>
</head>
<body>
<div id="navigation1">
<div id="smallmenu">
<ul>
<li><a href='iphone.htm'>Apple iPhone</a>
<ul>
<li><a href='iphone-6.htm'>iPhone 6</a></li>
<li><a href='iphone-5.htm'>iPhone 5</a></li>
<li><a href='iphone-4.htm'>iPhone 4</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='ipad.htm'>Apple iPad</a>
<ul>
<li><a href='ipad-air-2.htm'>iPad Air 2</a></li>
<li><a href='ipad-air.htm'>iPad Air</a></li>
<li><a href='ipad-mini-3.htm'>iPad mini 3</a></li>
<li><a href='ipad-mini-2.htm'>iPad mini 2</a></li>
<li><a href='ipad-mini.htm'>iPad mini</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="navigation">
<div id="menu">
<ul>
<li><a href='iphone.htm'>Apple iPhone</a>
<ul>
<li><a href='iphone-6.htm'>iPhone 6</a></li>
<li><a href='iphone-5.htm'>iPhone 5</a></li>
<li><a href='iphone-4.htm'>iPhone 4</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='ipad.htm'>Apple iPad</a>
<ul>
<li><a href='ipad-air-2.htm'>iPad Air 2</a></li>
<li><a href='ipad-air.htm'>iPad Air</a></li>
<li><a href='ipad-mini-3.htm'>iPad mini 3</a></li>
<li><a href='ipad-mini-2.htm'>iPad mini 2</a></li>
<li><a href='ipad-mini.htm'>iPad mini</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='ipad.htm'>Apple iPad</a>
<ul>
<li><a href='ipad-air-2.htm'>iPad Air 2</a></li>
<li><a href='ipad-air.htm'>iPad Air</a></li>
<li><a href='ipad-mini-3.htm'>iPad mini 3</a></li>
<li><a href='ipad-mini-2.htm'>iPad mini 2</a></li>
<li><a href='ipad-mini.htm'>iPad mini</a></li>
</ul>
</li>
<li><a href='ipad.htm'>Apple iPad</a>
<ul>
<li><a href='ipad-air-2.htm'>iPad Air 2</a></li>
<li><a href='ipad-air.htm'>iPad Air</a></li>
<li><a href='ipad-mini-3.htm'>iPad mini 3</a></li>
<li><a href='ipad-mini-2.htm'>iPad mini 2</a></li>
<li><a href='ipad-mini.htm'>iPad mini</a></li>
</ul>
</ul>
<ul>
</li>
</ul>
<ul>
<li><a href='ipad.htm'>Apple iPad</a>
<ul>
<li><a href='ipad-air-2.htm'>iPad Air 2</a></li>
<li><a href='ipad-air.htm'>iPad Air</a></li>
<li><a href='ipad-mini-3.htm'>iPad mini 3</a></li>
<li><a href='ipad-mini-2.htm'>iPad mini 2</a></li>
<li><a href='ipad-mini.htm'>iPad mini</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href='ipad.htm'>Apple iPad</a>
<ul>
<li><a href='ipad-air-2.htm'>iPad Air 2</a></li>
<li><a href='ipad-air.htm'>iPad Air</a></li>
<li><a href='ipad-mini-3.htm'>iPad mini 3</a></li>
<li><a href='ipad-mini-2.htm'>iPad mini 2</a></li>
<li><a href='ipad-mini.htm'>iPad mini</a></li>
</ul>
</li>
</ul>
</div>
</div>
<p>Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. Mobile site. </p>
<p> </p>
</body>
</html>