Media queries have appeared in web development quite recently and are a brilliant way of making a site looks good across all devices. Whether the site is being viewed on a television, desktop, computer, tablet or telephone it will dynamically change to be best suited to the screen size.
The difference between a phone which can be only 320px wide and a large monitor which could be 2000 pixels wide is huge and paying attention to this will enhance the user experience.
Most of the big sites use responsive web design and media queries to specify the width across the different devices. Websites like Amazon are accessed on phones and tablets daily and thus it is essential for them to be able to provide a mobile friendly version.
Media queries will add development to your scope but for a little extra time, it can make a lot of difference.
So to add media queries to a site you’ll need to add them at the end of the stylesheet so it overrides all the other styles specifically for each device.
So what would you use it for?
- Change a 3 column site into 1 column for a mobile screen.
- Loading higher resolution images for bigger screens
- Line-height and font sizes.
So if you’re ready to add it put this html in the head section of the site.
This will make the site be zoomed into 100% rather than it fitting the whole page to the screen.
The next code snippet is a good grounding to get started your different screen resolutions. Add it to the end of your css sheet and start coding!
@media screen and (min-width: 1200px) {}
@media screen and (max-width: 760px) {}
@media screen and (max-width: 550px) {}
@media screen and (max-width: 400px) {}
768px x 1024px is the resolution of an ipad
320px x 480px is the usual resolution of android and iphones (portrait and landscape)
A great place to check to see how the site looks is here.
Some examples I like, make sure you resize the window to see the media queries take effect:
Using Photoshop and CSS this tutorial will show you how to create a simple line break that appears indented, like that shown below, or like the ones on this website:

First in your photoshop paste a screenshot of your website, or simply have the background that the line break will sit on viewable. Note: This will not work on a white background, you will need to simply create a grey line break for that.
Now create a new layer, select the pencil tool on 1px brush size and select a foreground colour that is slightly darker than your current background colour. In the example the background colour is #17a884 and the foreground colour is #096a4f.
While holding down Shift draw a horizontal line. Now press Alt + Down arrow to copy this layer, press CTRL + U and bring the lightness to +100 to make into solid white. Now you can simply bring the opacity of that new white line layer down to suit, the example is 55%, but this will vary depending on how dark the background is.
Tweak the opacity and possibly darken the first layer to suit and once happy you can then add the css for your line break, as shown below:
hr, .linebreak {
width: 100%;
clear: both;
border: none;
border-top: 1px solid #096a4f;
background: #7fb1a3;
height: 1px;
font-size: 1px;
margin: 15px 0 15px 0;
}
This is the ideal css to ensure the linebreak works correctly and this can then be used with either the hr tag or a div of class=”linebreak”. Simply flatten your photoshop image and colour pick the colours, change the background colour to the white line colour and the border-top colour to the first coloured layer.
Combining images into single files and pointing to them using CSS background positioning can speed up your site, stop the need to preload hover images and keeps files more compact. This short tutorial will show how this technique is done.
Firstly when saving your images, create a new document and place each one of your images onto this ensuring they all sit next to one another, as this makes it easier to point to its position in the css, like that shown below.
![]()
Now you need to point to the image in your CSS and then you can position the image to choose your desired one.
#my-image {
background: url("sprite.jpg") no-repeat;
background-position: 0 0;
width: 100px;
height: 100px;
}
This CSS will show only Image 1 in the sprite, as the background-position: 0 0, is pointing to the top left of the image and the size of each of the images are 100px x 100px.
If I wanted to show Image 5, it would be background-position: 100px -100px. So the backgound-position will basically go 100px horizontally along the image and then -100px vertically as image 5 is below image 1. If Image 4 was 20px in width than it would have been background-position: 20px -100px.
You need to find out the size of each of the images in the sprite to ensure the correct positioning, width and height is entered.
This tutorial will show how to make an image float in the corner of a website, for instance, to highlight a feature or button, like that shown below.

First create your corner image and it’s best to create the image as a transparent png so that it can float on top of the page on a low res screen without looking odd (unless it is a solid image anyway).

Now open your css file and you will need the following css for your image.
#float-image {
position: absolute;
top: 0;
right: 0;
width: 114px;
height: 118px;
background: url(images/misc/image-name.png) no-repeat;
display: block;
}
This code will make whatever you set as id=float-image to be position absolute on the page to the top right corner, you may also need a z-index of say 100 encase the image floats below any other divs.
If you want the image to constantly be fixed at the top right corner even when scrolling then simply change position: absolute to position: fixed.
This tutorial will show how to add curved corners to boxes using the curvycorners.src file, which you can download here.
Save the file to your root folder and point to the .src file in your html.
Now all you need to do is add a few simple lines of css to add curves to your div box.
-moz-border-radius-topleft: 10px;
-moz-border-radius-topright: 10px;
-moz-border-radius-bottomright: 10px;
-moz-border-radius-bottomright: 10px;
You can now adjust the size of the curvature by amending the pixel amount, the bigger the amount the bigger the curve. You can even remove some of the corner curves so for instance only the top of your box has curves.
This css works fine in firefox, however as Internet Explorer is a different breed you may also require the following css to make sure it is cross-browser friendly:
-webkit-border-top-left-radius: 10px;
-webkit-border-top-right-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
So your div would then be:
#curved-corners {
-moz-border-radius-topleft: 10px;
-moz-border-radius-topright: 10px;
-moz-border-radius-bottomright: 10px;
-moz-border-radius-bottomright: 10px;
-webkit-border-top-left-radius: 10px;
-webkit-border-top-right-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
-webkit-border-bottom-right-radius: 10px;
}
I have always found it a pain adding footers to the bottom of the page, either the footer wont push down with the page or it just wont sit where it is supposed to. This tutorial will show how to effectively add a centrally aligned footer that sticks to the bottom of the page and follows the content when it scrolls down.
Firstly, create a new HTML document and set up the page as follows:

Now in your stylesheet all you need is the following:

These styles basically give the whole page a forced width and height of 100%, then gives the wrapper of the content a minimum height of 100%, so that even when there is no content it will still force to 100%.
This would obviously push the footer below the 100%, so the margin of 0 auto (to align center) and -80px is there to bring the footer back up. So the 80px would be whatever the height of the footer is.
With this configuration the footer would then sit over the content so the push div was created as the same height as the footer to resolve that issue.
Finally, in order for the footer to push down with the content the height of the content has been set to auto, so it will adjust accordingly.
By default, elements in HTML are aligned left, but nearly all websites these days align centrally on the page. To do this effectively you need to make the width of the body tag 100%, make the text align center and add a margin of 0 auto (otherwise there will automatically be margins added), as below:
body {
width: 100%;
text-align: center;
}
Now create a wrapper div that the whole site will sit in. The max width for sites these days is 980px, so make a width of 980px, make the margin 0 auto again and align the text left now so that text within the wrapper will align left but still be contained within the centrally aligned div, see below:
#wrapper {
width: 980px;
margin: 0 auto;
text-align: left;
}
Finally, here is how your HTML should now look:
<div id=”wrapper”>
Site content goes here
</div>
Until all browsers can support the CS3 background-size property, there is a need to create a layer which appears as a background image.
First, make sure that all browsers have a 100% height, 0 margin, and 0 padding on the html and body tags:
<style type=”text/css”>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
Add the image you want as the background as the first element of the web page, and give it the id of bg:
<body>
<img src=”images/background.jpg” alt=”background image” id=”bg” />
<!—- all other content goes below here à
Position the background image so that it’s fixed at the top left and is 100% wide and 100% in height:
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}
Add all your content to the page inside of a <div> called “content”. So what we have now is:
<body>
<img src=”images/background.jpg” alt=”background image” id=”bg” />
<!—- all other content goes below here à
<div id=”content”>
Web content here
<!—end content à
</div>
</body>
However, the page will now display the background image and then the content. We need to float the content over the image.
Position your content so that it’s relative and has a z-index of 1. This will bring it above the background image in standards-compliant browsers. Add this to your style sheet:
#content {
position:relative;
z-index:1;
}
In order for IE6 to display the page, add the following to the end of your style sheet:
<!–[if IE 6]>
<style>
html { overflow-y: hidden; }
body { overflow-y: auto; }
img#bg { position:absolute; z-index:-1; }
#content { position:static; }
</style>
<![endif]–>
This will give a background image to your site which will stretch to the size of your window
All developers have to transfer sites at some point, if you don’t I envy you. It seems that site transfers always have teething issues with the difference in server builds, operating systems having different compilations of PHP and the rest.
And worst of all, different hosts limitations…
But to transfer a site you need to make a simple list of things that need to be done in order for it to work.
- Get all files, including hidden files (many a time I’ve been caught up on the .htaccess on a mac being hidden and a site riddled with 404 errors…)
- Get all database details of the new server
- Update all calls to databases
- Use Dream Weaver (for the only things its any good for) to search and replace across the site for the old URL and change it to the new one, and the same with database details)
- Make sure image, stylesheet, javascript and any other call is base root not an absolute URL (unless externally hosted)
- Upload everything, including creating the new databases
- Test everything, fix bugs and teething issues
If you can do all of the above your site will transfer easy peasy.
We’ve all felt the pain of Internet Explorer and we all know its a truly horrible browser for any developers with its completely “out there” standards to every other main stream browser.
And most specifically we’ve all wondered “How the hell do I get IE7 to allow floating elements with overflow hidden?”
Its actually very very simple to fix this, what seems like a bit of a silly bug to leave in a mainstream browser.
To fix this issue all you have to do is attach the below code to the container
#element_name{
position:relative;
}
And it really is as simple as that to fix the error, all praise position:relative!
