How to center SVG text vertically in IE9

后端 未结 3 524
说谎
说谎 2021-01-07 20:43

In order to align text vertically in SVG one has to use the dominant-baseline attribute. This has already been discussed on SO (Aligning text in SVG) and is par

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-07 21:03

    This is a giant hack, but we can approximate the vertical middle position by taking the font size into account.

    The specification defines central like that:

    central

    This identifies a computed baseline that is at the center of the EM box.

    We can take an EM box of known font size and measure its bounding box to compute the center.

    
    
        
        
            M
        
        
    
        
        
            M
        
    
    

    Obviously, the code can be much cleaner, but this is just a proof-of-concept.

提交回复
热议问题