What dependency between font-size and width of char in monospace font?

前端 未结 3 807
天涯浪人
天涯浪人 2021-02-07 15:15

What dependency between font-size and width of char in monospace font? In my web-application I use \"courier new\" font. I want to know, what realy length in pixels of string? I

3条回答
  •  爱一瞬间的悲伤
    2021-02-07 15:55

    forgive me if I'm doing thing completely wrong as I've been on SO for a while now but this is the first time I have contributed.

    This was something that was bugging me and @Stephen James has really nailed it for what I was trying to acheive.

    I had some issues getting it to work and found that the CSS in your fiddle was incorrect

    CSS:

    #checkSizeExample
    {
    font-family : Courier;
    font-size : 8pt;
    }
    
    
    
    .sizingClone {                  // this was originally an id tag not a class tag
    position : absolute !important;
    
    /* top : 100% !important;
    left : 100% !important;         // not sure why but this line was causing the div to
                                    // expand to 100%.
    visibility: hidden !important;    
    width : auto;
    height : auto; */
    }
    

    I commented out everything but the position in the sizingClone class as I found it unnecessary.

    This now works perfectly

提交回复
热议问题