How to parse CSS font shorthand format

前端 未结 4 456
梦谈多话
梦谈多话 2021-01-11 23:19

I need to parse the CSS font shorthand format into the separate components (font-family, font-size, font-weight, ...). This shorthand format looks pretty complicated. Here a

4条回答
  •  长发绾君心
    2021-01-11 23:27

    Here's a "temporary DOM element and using jquery's css() function" solution:

    http://jsfiddle.net/thirtydot/tpSsE/2/

    var $test = $('');
    $test.css('font', 'bold italic small-caps 1em/1.5em verdana,sans-serif');
    
    alert($test.css('fontWeight'));
    alert($test.css('fontStyle'));
    alert($test.css('fontVariant'));
    alert($test.css('fontSize'));
    alert($test.css('lineHeight'));
    alert($test.css('fontFamily'));
    

提交回复
热议问题