简体   繁体   English

字体大小em在某些设备上显示不同

[英]Font size em shows differently on certain devices

I'm creating a chat program for the web designed primarily for mobile devices. 我正在为主要为移动设备设计的网络创建聊天程序。 My issue is that in trying to be as appropriate for mobile devices as possible I dropped pixel font sizes for em , however on my desktop pc with firefox the li text shows as very small and does on the iPad too. 我的问题是,在尝试尽可能适合移动设备时,我放弃了用于em像素字体大小,但是在我的桌面电脑上使用firefox, li文本显示为非常小,并且在iPad上也是如此。 On my Nokia Lumia 800 windows phone it shows as much larger. 在我的诺基亚Lumia 800 Windows手机上,它显示的更大。

My CSS: 我的CSS:

* { margin:0; padding:0; font-family:arial; }
body > div { width:auto; margin:10px; }
h1 { font-size:1.5em; }
h2 { font-size:4em; text-align:center; }
h2#signIn > a { color:#aaaaaa; }
h2#signIn > a:hover { color:#000000; }
h3 { text-align:left; font-weight:normal; margin:10px; }

ul { list-style:none; }
ul > li { font-size:0.8em; font-weight:normal; padding:5px; text-align:center; }

a { color:#000000; text-decoration:none; font-variant:small-caps; }
a:hover { color:#aaaaaa; }
div.fieldContainer { display:block; border:1px solid #000000; padding:5px; }
span.yell, span.wire { font-variant:small-caps; }
span.wire { color:#aaaaaa; }

input[type="text"], input[type="password"]
{
    width:100%; margin:0;
    font-size:2em; border:0;
}

input[type="button"]
{
    width:100%; padding:10px; font-size:2em;
    font-variant:small-caps; letter-spacing:2px;
    border:1px solid #000000; background-color:#dddddd;
}

#messages
{
    width:100%; height:200px;
    border:0; padding:0; margin:0;
    overflow:auto; font-size:0.9em;
}

span.msgTime { font-size:0.7em; }

.fromMe { color:#aaaaaa; }
.fromYou { color:#000000; }
.clear { clear:both; }

As you can see the list element uses 0.8em. 如您所见,list元素使用0.8em。 I realise there are browser inconsistencies but is this really unavoidable? 我意识到存在浏览器不一致但这是否真的不可避免?

I also use this to make sure the scale of the web pages show properly: 我还使用它来确保网页的比例显示正确:

<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0;"> 

update 1 更新1

I think it's worth mentioning that all other relative font sizes look fine, it appears to only be the list element that differs across the mobile browsers. 我认为值得一提的是,所有其他相对字体大小看起来都很好,它似乎只是移动浏览器中不同的列表元素。

em is a measurement relative to the current font size. em是相对于当前字体大小的度量。 If the browsers all have a different default base font size, then they'll look differently. 如果浏览器都具有不同的默认基本字体大小,那么它们看起来会有所不同。 Try using pt instead which is still appropriate for different size screens and is not fixed like px would be. 尝试使用pt代替仍适用于不同尺寸的屏幕,并且不像px那样固定。

http://www.w3schools.com/cssref/css_units.asp http://www.w3schools.com/cssref/css_units.asp

Each browser has its own default stylesheet which sets the base text size. 每个浏览器都有自己的默认样式表,用于设置基本文本大小。 Ems are relative units that change size based on that default text size. Ems是基于默认文本大小更改大小的相对单位。 Try giving your body a font-size:16px , just as an example, and see if that doesn't make the text show at the same size. 尝试给你的body一个font-size:16px ,就像一个例子,看看是否不会使文本显示相同的大小。

To be more clear here is a link to help explain why I suggest using a pixel size on the body element, and only that element. 为了更清楚,这里有一个链接,以帮助解释为什么我建议在body元素上使用像素大小,并且只使用该元素。 http://www.alistapart.com/articles/fluidgrids/ http://www.alistapart.com/articles/fluidgrids/

In css file line no 1 shows 在css文件行中没有显示1

* { margin:0; padding:0; font-family:arial; }

replace it with 用它替换它

* { margin:0; padding:0; font-family:arial; font-size: 1em; }

it will work! 它会工作!

If you wish to let each browser use its default font size, presumably suitable for the device, simply do not set body font size at all and do not use a meta tag to prevent scaling, as you are now. 如果您希望让每个浏览器使用其默认字体大小(可能适用于该设备),则根本不要设置正文字体大小,也不要像现在那样使用meta标记来防止缩放。

If you think that “one size fits all” is your way, then set font sizes in pixels or points (different approaches), instead of trying to achieve that using the em unit. 如果您认为“一刀切”是您的方式,那么设置字体大小(以像素或点为单位)(不同的方法),而不是尝试使用em单元来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM