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.
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.
Double click within the viewport boundaries. Then, type Zoom and the Command Line. Next, enter the scale you would like to use.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With