CSS样式-百分比vs em vs px? [英] CSS style - percentage vs em vs px?

查看:104
本文介绍了CSS样式-百分比vs em vs px?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网上阅读了几篇文章后,我有点困惑何时将percentempx用于div´sinput´sfont´sbuttons等. ..

After reading several articles on the web I´m a bit confused about when to use percent, em or px for div´s, input´s, font´s, buttons and so on...

对于我正在研究的网站,我们不想添加响应式设计,据我从不同的文章中了解到,elementsdiv´s的使用方式是百分比.但是让我感到困惑的是,因为我认为即使我使用px布局,并且根据设备/屏幕分辨率在px中设置不同的宽度,高度,我也应该能够获得响应式设计...?

For the site I´m working on we wan´t to add a responsive design, and from what I understand from different articles than percent is the way to go for elements and div´s. But than I get confused because I´m thinking that I should be able to get a responsive design even if I use px för layout and than set different width, height in px depending on device/screen resolution...?

在何时使用什么方面有最佳实践吗?不仅适用于fontsize,还适用于div´s和其他元素?

And is there a best practice for when to use what? And not only for fontsize, but for div´s and another elements as well?

推荐答案

使用em的主要优点是它的实际大小取决于用户的设置,即默认字体的大小.因此,喜欢大字体的用户会增加此值.百分比会创建一种静态布局,即使它的大小灵活,再加上最小高度和最大高度/宽度,也可以带来安静的效果.如果您希望使用带有列的灵活布局,那么只有一个小屏幕,两个大屏幕,最多三个,您还必须使用浮点数与(min-/max-)宽度/高度相结合.

The main advantage of using em is that it actual size depends on the settings of the user, namely the size of the default font. So Users that prefer big type increase this value. Percentages create a kind of static layout, even if it flexible in size, combined with min- and max-height/width this can lead to quiet nice results. If you would like to have a flexible layout with columns, so that there is only one one small screens, two on bigger ones and three in maximum you will also have to use floats combined with (min-/max-) width / height.

通常,我不会从询问最佳单元开始,而且,我将开始有关布局应如何工作的基本概念.有时候,事实证明,对于整个版式使用javascript是最快,最可靠的解决方案,因此,要使用的单位取决于您的特殊目标,因此对于这个问题,通常不存在这是最好的解决方案",处于什么状态.

In general I would not begin with questioning the best unit, furthermore I would begin a basic concept about how the layout should work. Sometimes it turns out that using javascript for the whole Layout is the fastest and most reliable solution, so however, the unit to use depends on your special goal and a »this is the best solution« does not exist for this question in general, that is what state.

问候.

这篇关于CSS样式-百分比vs em vs px?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆