Skip to content

Instantly share code, notes, and snippets.

@kogakure
Created March 4, 2009 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kogakure/73789 to your computer and use it in GitHub Desktop.
Save kogakure/73789 to your computer and use it in GitHub Desktop.
Python: Simple calculator for target font-size (CSS) with em
#!/usr/bin/python
# -*- coding: utf-8 -*-
def fontsize(base_fontsize, target_fontsize, lineheight):
lineheight_px = base_fontsize * lineheight
target_lineheight = lineheight_px / target_fontsize
target_fontsize_em = 1.0 / base_fontsize * target_fontsize
target_lineheight = round(target_lineheight, 4)
target_fontsize_em = round(target_fontsize_em, 4)
return "###################\nfont-size: %sem\nline-height: %s\nmargin-bottom: %s\n###################" % (target_fontsize_em, target_lineheight, target_lineheight)
base_fontsize = int(raw_input('base fontsize (px): '))
lineheight = float(raw_input('line-height: '))
target_fontsize = float(raw_input('Target font-size (px): '))
result = fontsize(base_fontsize, target_fontsize, lineheight)
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment