Created
May 8, 2014 14:39
-
-
Save andipollok/7bd6aee8a2376086bd36 to your computer and use it in GitHub Desktop.
Align text on typographic baseline at absolute position on page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Align text on typographic baseline at absolute position on page | |
| * http://en.wikipedia.org/wiki/Baseline_(typography) | |
| * also see discussion on SO http://stackoverflow.com/questions/6178506/css-display-text-at-descent-instead-of-baseline | |
| */ | |
| .position { | |
| position:absolute; | |
| top:100px; | |
| left:50px; | |
| } | |
| .showBaseline { /* the red baseline - this line is just there for debug purposes */ | |
| width:100%; | |
| height:1px; | |
| background-color:red; | |
| position:absolute; | |
| } | |
| .textoffset { | |
| width:0px; | |
| height:99999px; | |
| background-color:yellow; | |
| display:inline-block; | |
| } | |
| .text { | |
| position:relative; | |
| top:-99999px; | |
| font-size:3em; /* font-size can be changed */ | |
| font-family:serif; | |
| display:inline-block; | |
| vertical-align:baseline; /* just to be sure */ | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- content to be placed inside <body>…</body> --> | |
| <div class="position"> | |
| <div class="showBaseline"></div> | |
| <div class="textoffset"></div> | |
| <div class="text">text aligned on baseline yxlg</div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"view":"split","fontsize":"90","seethrough":"","prefixfree":"1","page":"all"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment