Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scaling a web layout with the viewport

Tags:

css

I am aware of the CSS 3 units vw, vh and vm, which seem to be useful for making elements that have their box sizes and text sizes relative to the browser's viewport size. However, sadly, these are not well-supported with the current major browsers; only Internet Explorer 9+ does.

What other methods can I use to do things like CSS font-size properties that scale with the viewport? I would like to avoid JavaScript and/or jQuery solutions if possible.

like image 618
Delan Azabani Avatar asked Aug 03 '11 02:08

Delan Azabani


People also ask

How do you scale the size of a viewport?

In the Dimension Style Manager, select the style you want to change. Click Modify. In Modify Dimension Style dialog box, Fit tab, under Scale for Dimension Features, select Scale Dimension to Layout (Paper space). Click OK.

What command do you use to scale viewport?

Double click within the viewport boundaries. Then, type Zoom and the Command Line. Next, enter the scale you would like to use.


1 Answers

Doing a 100% scalable website is possible. As Rev said, you can do this by using percentage values, but it is tricky.

The better option is to utilize @media queries. These allow you to apply CSS rules to a page only under certain conditions. By using media queries to detect the device width and/or the page width, you can apply fine tune control over how your site looks AT different viewport sizes. For instance:

@media screen and (max-device-width: 960px) {
    font-size:14px;
}
@media screen and (max-device-width: 480px) {
    font-size:13px;
}

Now, the above example is rather trivial and contrived. For a deeper understanding of what you can accomplish with media queries, I recommend you view the W3C spec page. Some of the most powerful are the width, min-device-width, max-device-width, portrait|landscape, and print queries.

As a side note, make sure to include these styles at the bottom of your CSS, so that they dont get overwritten by default styles.

like image 181
Moses Avatar answered Nov 22 '22 14:11

Moses