How do I make a website responsive? [closed]

和自甴很熟 提交于 2019-11-26 23:12:40

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

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

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!