简体   繁体   English

在Firefox中固定字体大小?

[英]Fixed font size in firefox?

I'm wanting to keep the font size of a navigation menu the same size for all browsers. 我想使所有浏览器的导航菜单字体大小保持相同。 I set the font-size of the navigation menu text to a specific pixel size. 我将导航菜单文本的字体大小设置为特定的像素大小。 In IE this works, but not in FF. 在IE中,此功能有效,但在FF中则无效。

The problem is, if a person changes their browser's font size, then it completely ruins the menu layout in FF. 问题是,如果一个人更改了浏览器的字体大小,那么它将完全破坏FF中的菜单布局。

Is there a way to adjust this for FF or is there no way around it? 有没有办法针对FF进行调整,或者没有办法解决? I understand it is for accessibility, but it would otherwise mess up the design and I'd rather not use images instead of text for the navigation menu. 我了解它是为了可访问性而设计的,但否则会弄乱设计,并且我宁愿不要在导航菜单中使用图像而不是文本。

Thanks! 谢谢!

You have three choices: 您有三种选择:

  1. Fix your menu layout such that it is more tolerant of different font sizes (recommended: plenty of users who won't agree with your choice of font size - not just limited to visually impaired users either). 修正菜单布局,使其更能容忍不同的字体大小(建议:很多用户不同意您选择的字体大小-不仅限于视力不佳的用户)。
  2. Replace text with images (with appropriate alt text!); 用图片替换文字(带有适当的替代文字!); FF (and IE) will still scale these in "zoom" mode, but won't break the layout of the page. FF(和IE)仍将在“缩放”模式下缩放它们,但不会破坏页面的布局。
  3. Do nothing. 没做什么。 Leave the broken layout as a big "FU" to those users who would otherwise strain to read your fixed-sized text. 对于那些原本会费劲地阅读固定大小文本的用户,请将残缺的版式保留为较大的“ FU”。

You're fighting a fight you're not going to win if you try to keep everything fixed and happy for your eyes only. 如果您要努力使所有事物保持固定且仅对您的眼睛感到高兴,那么您在打架就不会赢。 If the content if for consumption by the public, then understand that Ms. Public has different opinions as to the correct font size she should be reading. 如果内容供公众使用,则应了解Public女士对于应该阅读的正确字体大小有不同的看法。

Browsers have evolved a long way to stop what you're trying to do from preventing people from seeing content. 浏览器已经发展了很长的路要走,以阻止您尝试做的事情阻止人们看到内容。

Evolve and understand that font-size SHOULD change with a CTRL + '+/-' 发展并了解字体大小应使用CTRL +'+/-'更改

The only guaranteed way to have this level of control is to render the text as images. 拥有这种控制级别的唯一保证方法是将文本呈现为图像。 Although this can work OK for menus (which don't change that often), I've seen it horribly abused by sites where all text was done as images. 尽管这对于菜单来说可以正常工作(它不会经常更改),但是我看到它被所有文本都以图像形式显示的网站所滥用。

I have a good friend who was trained as a print designer. 我有一个好朋友,他接受过印刷设计师的培训。 When she first started doing web design it almost caused her to go insane because of the lack of control. 她刚开始进行网页设计时,由于缺乏控制力,几乎使她发疯。 I suggested she breath deeply, study the CSS box model, and then design for the "normal" font size +/- 1 size. 我建议她深吸一口气,研究CSS盒子模型,然后设计“正常”字体大小+/- 1大小。

问题不是有人在缩放,客户想要那样,也就像他想要的那样,问题是9pt字体正在显示在ie 7和8和chorme中而不是在ff中

There is another option: 还有另一种选择:

Detect the user's font size using the following script: http://www.alistapart.com/articles/fontresizing/ 使用以下脚本检测用户的字体大小: http : //www.alistapart.com/articles/fontresizing/

Then adjust a container div in "ems" to compensate for the user size. 然后以“ ems”为单位调整容器div,以补偿用户的大小。

For instance if user font-size is 22 and base is 20, then make your container div have a font-size of 20/22 (ie, 22*(20/22)=20). 例如,如果用户font-size为22且base为20,则使您的容器div具有20/22的字体大小(即22 *(20/22)= 20)。 :) :)

Note: The reason you'd need a container div is because your event listener would be watching out for font-size changes to the body. 注意:之所以需要容器div是因为事件侦听器会注意主体的字体大小更改。

(This answer will probably piss off some usability experts. Sorry to those people. You do have good points, but an answer is still an answer. :p) (此答案可能会激怒一些可用性专家。对不起这些人。您的确有长处,但答案仍然是答案。:p)


PS. PS。 I figure I'd best attach my implementation code just to prove that it works. 我想我最好附上我的实现代码,只是为了证明它可以工作。 I haven't edited this code for global application. 我尚未为全球应用程序编辑此代码。 It's copied and pasted...look out for things such as replacing my IE conditional (which uses dynamically added CSS classes) with convential browser detect conditionals (for instance). 它已被复制并粘贴...注意寻找诸如用常规浏览器检测条件替换我的IE条件(使用动态添加的CSS类)之类的东西。

It's lengthy but all necessary: 这很长,但所有必要:

updateBaseFontSize : function(fontSize,reloadBool){
                /*Format 1 is fed from the plug; format2 is the body size equiv
                 *examples:
                 *Frmt 1 (all/IE) | Frmt 2 (all/IE)
                 *20/18           | 16px/16px
                 *21/21           | 17.6px/19px
                 *22/23           | 19.2px/22px
                 *
                 *Purpose of updateBaseFontSize is:
                 * 1. convert format 1 figures to format 2
                 * 2. modify the all containing div 'fontbodyreadjust'
                 *    to compensate for the new user defined body font size
                 */

                var format1Base;
                var format1Size = fontSize; //equals new size in pixels
                var reloadPage = reloadBool; //prevents reload on 1st visit

                var baseConverter;
                var changeConverter;

                if ($('body').hasClass('browserIE')) {
                    format1Base = 19; //expected base size value for IE
                    baseConverter=16/19; //converts from format 1 to 2 for IE
                    changeConverter=1.5; //ditto for the difference from base size for IE
                } else {
                    format1Base = 20;//expected base size value for all other browsers
                    baseConverter=16/20; //converts from format 1 to 2 for all others
                    changeConverter=1.6; //ditto for the difference from base size for all others
                }


                //Find modifiedSize, how much to compensate for the new body size
                var format2Base = format1Base * baseConverter;

                var format2SizeChange = (format1Size-format1Base)*changeConverter;
                var format2NewSize = format2SizeChange + format2Base;

                var modifiedSize = format2Base/format2NewSize;


                //Allow text resizing for shrinking text and very very large text
                //Only works for safari. meant to prevent odd behavior at math extremes
                if ((format2NewSize >= format2Base)&&(modifiedSize>.6)){
                    $('#fontbodyreadjust').css('font-size',modifiedSize+'em');
                }

                //reloadPage boolean in place so that reload doesn't occur on first visit
                if (reloadPage){
                    window.location.reload()
                }
    },

    initHome : function(){


        // UNHIDE HOME PAGE CONTENT AFTER IT'S LOADED. OTHERWISE, LAYERED AND MESSY
        $('#slider').css('display', 'block');


                // PREVENT VARIOUS USER BROWSER-FONT RESIZE SCENARIOS
                // Note: irrelevant for browsers that zoom all elements simultaneously
                window.initFontResizeDetector = function(){
                        var iBase = TextResizeDetector.addEventListener(onFontResize,null);

                        //Don't run the updateBaseFontSize if font size is not larger than usual
                        if (iBase>20){
                            var reloadBoolean = false;
                            window.updateBaseFontSize(iBase,reloadBoolean);
                        }
                }

                //id of element to check for and insert control
                TextResizeDetector.TARGET_ELEMENT_ID = 'bodyContent';
                //function to call once TextResizeDetector has init'd
                TextResizeDetector.USER_INIT_FUNC = window.initFontResizeDetector;

                window.onFontResize = function(e,args) {
                        var iSize = args[0].iSize; //get new user defined size
//                        var iDelta = args[0].iDelta; //get new user defined size
//                        var iBase = args[0].iBase; //get new user defined size
                        var reloadBoolean = true;
//                        console.log(iSize,iDelta,iBase);
                        window.updateBaseFontSize(iSize,reloadBoolean);
                }

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

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