Passa al contingut principal

Tips and best practices to develop responsive websites

Tips and best practices to develop responsive websites:

Start with a template



Sure, you can start coding from scratch, but there’s a lot of interesting free templates that will make you save a lot of time. Among others, I recommend Mobile boilerplate, The 1140 grid and Skeleton. There’s a lot more than those ones, so feel free to google “responsive web design template” if you want more.

Working with fluid grid based layouts



Fluid layouts are an important part of a good responsive layout. In order to have a website that can adapt to many different screen resolutions, you have to use a fluid layout with widths defined in percents instead of pixels.
To get the size in percents from a size in pixels, you have to take the element’s width and divide it by the full grid size. For example: 200 px (element size) / 960 px (grid size) = 0.2083. Multiply this by 100, and you’ll get 20,83%.
This is why it is interesting to work with a 1000px grid. 1000 is a round number, and it is easy to calculate that 24% of this size will be equal to 240 pixels. For more info about 1000px grids, I recommend you to check out this article.

Flexible images

A very important aspect of a responsive layout is how images can adapt to the size of their parent container. The basic solution is to define a maximum width of 100%. This will make sure that your images are never wider than the parent container.
.content img{
   max-width:100%;
}
A better solution is to use context-aware image sizing. This technique basically consists of having different sizes of an image, and displaying only the size adapted to the device. Quick example:
<img src="image.jpg" data-src-600px="image-600px.jpg" data-src-800px="image-800px.jpg" alt="">
And the related CSS:
@media (min-device-width:600px) {
    img[data-src-600px] {
        content: attr(data-src-600px, url);
    }
}

@media (min-device-width:800px) {
    img[data-src-800px] {
        content: attr(data-src-800px, url);
    }
}
For more info about this technique, check out this article.

jQuery is your friend

jQuery is definitely a super useful tool when it comes to web development. Lots of jQuery plugins can help you to create better responsive websites.

A quick round up of my personal favorites:
  • FitText: A plugin that makes font-sizes flexible.
  • Elastislide: A responsive jQuery carousel plugin.
  • Supersized: A fullscreen background slideshow plugin.
  • FitVids: A lightweight, easy-to-use jQuery plugin for fluid width video embeds.

Don’t forget Apple’s viewport


The <meta name="viewport""> tag was introduced by Apple for their mobile devices (iPhones, iPads and iPods Touch). This tag allow you to specify the default size of a page when viewed with an iPhone or iPad.
<meta name="viewport" content="width=device-width; initial-scale=1.0">
The code above will ensure that upon opening, your layout will be displayed properly at 1:1 scale. No zooming will be applied.
For more info, feel free to check out Apple developper documentation.

Scalable background images

The CSS3 specification introduced a new attribute named background-size. As you probably guessed, it is used to define the size of background images. It can be a size in pixels, or it can use some of the reserved keywords. The cover keyword scale the background image (while preserving original proportions) to be as large as possible so that the background positioning area is completely covered by the background image.
html {
 background: url(bg.jpg) no-repeat center center fixed;
 -webkit-background-size: cover;
 -moz-background-size: cover;
 -o-background-size: cover;
 background-size: cover;
}
The solution above works perfectly in Chrome, Safari 3+, IE 9+, Firefox 3.6+ and Opera 10+. If you’re looking for a solution that works in older browsers, I highly suggest using this jQuery plugin or one of the alternative CSS tweaks published here.

Get inspired



When designing a website, it is always good to be able to get inspired by what others have done. Since the rise of responsive web design, online galleries have been created to showcase the best responsive websites.
The most complete gallery is definitely mediaqueri.es, but if you need some more inspiration, you can get it here or here.

Test, test, test, and test again!



Indeed, when developing a responsive layout, you have to test it in different resolutions. Of course, you can manually resize your browser, but why not using one of the useful tools created to simplify this task?
Lots of differents tools are available for you to test your website in different screen sizes. At the moment, my favorites are definitely ScreenQueri.es and Resize my browser.

Comentaris

Entrades populars d'aquest blog

10 alternativas a Cuevana para ver películas online

10 alternativas a Cuevana para ver películas online : Durante este último tiempo, en Cuevana se sucedieron varios “problemas” por los cuales hubo que ajustar algunas cosas antes de tiempo (como el rediseño del sitio), que dejaron a algunos usuarios ciertos problemas para acceder a las películas o series del portal. Pero realmente esto es algo que no incumbe a los usuarios y, como sabemos, existen muchas otras alternativas a Cuevana dando vueltas por Internet, que intentaremos presentar aquí mismo. Los sitios que repasaremos funcionan del mismo modo que Cuevana, mediante la instalación de un plugin que permite visualizar los videos de Megaupload o WUShare, entre otros servicios, en una calidad de imágen realmente excelente. Tal como sucede con el más popular servicio, todos ellos tienen publicidad que en algunos casos resulta insoportable, pero como dice Federico en DotPod “a caballo regalado no se le miran los dientes”. Alternativas a Cuevana 1. Moviezet Posiblemente el mejor clon d

Sitio alternativo a Cuevana: Moviezet

Sitio alternativo a Cuevana: Moviezet : Nadie se quiere enfrentar al monstruo Cuevana , tan popular por estos días que es casi imposible ver tu serie favorita o tu película sin tener problema de saturación de tráfico. Pero hay proyectos muy sanos y prometedores, sobre todo porque están basados como una muy buena alternativa . Señores estamos hablando obviamente de un sitio alternativo a Cuevana, llamado Moviezet. Como bien dijimos, Moviezet es una excelente alternativa a Cuevana, ya que podremos ver películas y series de forma gratuita sin necesidad de que existan cortes – al mejor estilo Megavideo – y que podremos tener un seguimiento, es decir, si miramos una serie, podremos ver toda la lista con los capítulos disponibles. Lo que tiene de novedoso este sitio web Moviezet , es que tiene películas y series que quizá en Cuevana no se puedan conseguir, pero atención, que puede suceder lo mismo, pero al revés. Entonces aquí intervenimos nosotros y te daremos un sabio consejo, para no

Learn Composition from the Photography of Henri Cartier-Bresson

“Do you see it?” This question is a photographic mantra. Myron Barnstone , my mentor, repeats this question every day with the hopes that we do “see it.” This obvious question reminds me that even though I have seen Cartier-Bresson’s prints and read his books, there are major parts of his work which remain hidden from public view. Beneath the surface of perfectly timed snap shots is a design sensibility that is rarely challenged by contemporary photographers. Henri Cartier-Bresson. © Martine Franck Words To Know 1:1.5 Ratio: The 35mm negative measures 36mm x 24mm. Mathematically it can be reduced to a 3:2 ratio. Reduced even further it will be referred to as the 1:1.5 Ratio or the 1.5 Rectangle. Eyes: The frame of an image is created by two vertical lines and two horizontal lines. The intersection of these lines is called an eye. The four corners of a negative can be called the “eyes.” This is extremely important because the diagonals connecting these lines will form the breakdown