October 8, 201313 yr Hi folks, I've been getting to grips with responsive design lately and, well, want to make sure I'm not going mad. I've always assumed that the following method was the way you do it, but it's getting rather long-winded and monotonous and I want to make sure there isn't a short-cut. Here's a snippet of my responsive coding: @media screen and (max-width: 480px){ #wrapper{ max-width: 460px; } #topstrip{ height: 140px; max-width: 463px; min-width: 463px; } #logo{ max-width: 460px; position: relative; } #logoimg{ width: 495px; height: 130px; position: relative; left: -20px; } #iheartcss{ display: none; } #navbar{ max-width: 478px; position: relative; left: 115px; top: -20px; } #navbar a:link{ color: #fff; font-size: 13px; } .navlink{ height: 20px; line-height: 20px; margin-right: 0px; padding-left: 8px; padding-right: 8px; } .navlink:hover{ background: transparent; color: #fff; } .navlinkcur{ background: transparent; border: 0px; border-radius: 0px; color: #fff; height: 20px; line-height: 20px; margin-right: 0px; padding-left: 8px; padding-right: 8px; } #scrollnav, #scrollnavbar, #scrollshare{ display: none; background: transparent; border: 0px; box-shadow: 0px 0px 0px; } #portfolionav, #tutorialnav{ display: none; } #main{ max-width: 460px; } #side{ display: none; } .box{ display: none; } #followbox{ display: none; } } It's very untidy and needs organising, but essentially that's it - just elements resized and in many cases hidden. This is for max-width: 480px, and then I'll have to move onto other sizes and repeat the process (hopefully by just modifying this 480px template). But is this the right way, or am I missing something? Someone give me good news, ha.
October 9, 201313 yr that works make sure u have this in ur html within head tag <meta name="viewport" content="width=device-width, initial-scale=1.0"> and this is what u need in css * Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 320px) and (max-device-width : 480px) { /* Styles */ body {background-image:url('paper9.gif'); } /* Smartphones (landscape) ----------- */ @media only screen and (min-width : 321px) { /* Styles */ body {background-image:url('paper8.gif'); } /* Smartphones (portrait) ----------- */ @media only screen and (max-width : 320px) { /* Styles */ body {background-image:url('paper7.gif'); } /* iPads (portrait and landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { /* Styles */ body {background-image:url('paper6.gif'); } /* iPads (landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) { /* Styles */ body {background-image:url('paper5.gif'); } /* iPads (portrait) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) { /* Styles */ body {background-image:url('paper4.gif'); } /* Desktops and laptops ----------- */ @media only screen and (min-width : 1224px) { /* Styles */ body {background-image:url('paper.gif'); } /* Large screens ----------- */ @media only screen and (min-width : 1824px) { /* Styles */ body {background-image:url('paper2.gif'); } /* iPhone 4 ----------- */ @media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (min-device-pixel-ratio : 1.5) { /* Styles */ body {background-image:url('paper3.gif'); }
October 9, 201313 yr Author Thanks sash, but I knew all this. I'm aware of the header tag and how to write it. I was asking if there were an easier way I haven't yet come across.
October 9, 201313 yr As you altar the width of your browser, you will notice your design breaks in places. This is where you need to include media queries, not on a per-device basis, that isn't future proof. If you're using percentage widths, often in the mobile view I change these from width: 30%; to width: 100%; as they appear too narrow otherwise. I also change display: inline-block; to just display: block to allow elements to stack on top of each other. Most frameworks do this automatically.
Create an account or sign in to comment