0

I want to know how to make a website, and all of its elements responsive to adapt to different screen sizes: fonts, images etc...

I have done something like this:

@media only screen 
and (max-width : 320px)
{  
    //here put the width and height of all the elements in the site 
}

I have to specify target resolution for each one. Can there be a common setting that can apply to all resolution?

Can there be other ways to make it dynamic for each screen size? Is there an easier way?

Abhinav Saxena
  • 1,990
  • 2
  • 24
  • 55
user3016968
  • 99
  • 1
  • 4
  • 10

4 Answers4

2

Adaptive layouts (Responsive layouts) consists of the following three factors:

1. Flexible Layouts:

The divs you use to create your web page layouts need to consist of relative length units. This means you shouldn't use fixed widths in your CSS, rather use percentages.

The formula to convert sizes from a design to percentages is (target/context)x100 = result

enter image description here

Lets take the picture above as an example of a design. To calculate what the size of the div on the left is going to be calculated like this: (300px/960px)x100 = 30.25%

The CSS would look something like this:

.leftDiv
{
    width: 30.25%;
    float: left;
}

.rightDiv
{
    width: 65%;
    float: left;
}

For text to automatically resize you can use a unit called VW (ViewWidth)

.myText
{
    font-size: 1vw;
}

This ensures that the text automatically resize relative to the view width.

2.Flexible Media:

Flexible media applies to images, videos and canvasses which automatically resize relative to its parent.

Example:

img, video, canvass
{
    max-width: 100%;
}

This ensures that these elements resize automatically inside its parent.

3. Media Queries:

The next step is to use media queries like you've done in your question, these media queries define certain CSS statements for certain screen sizes. I normally use only three media queries for computers screens, tablets and phone screens. Its not necessary to have more than this because the Flexible Layouts and Flexible Media will ensure relative resizing if done correctly.

You may find this helpful: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries

JakesRassie
  • 616
  • 1
  • 6
  • 20
0

There are two options I am aware of.

  1. Use Adobe Reflow, which exactly what you have but the software writes it for you and you just click and drag your elements, so you will achieve the same result much faster.
  2. Have absolutely everything a percentage, size, margins, borders, everything. This way you won't have to rewrite code over and over, a 'one size fits all' option.
cameronjonesweb
  • 2,435
  • 3
  • 25
  • 37
0

Take a look at Bootstrap and more specifically the Grid System. It should help you with css for different screen sizes.

Stu
  • 69
  • 7
0

Incase if you are new to CSS adaptive layout please do have a look at the following websites:-

a) Bootstrap
b) Foundation

In my opinion Foundation, is a great place to start with.It has a very beautiful documentation about grids.Please do check it out

malcolmX
  • 429
  • 4
  • 15