TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

FlowType: font-size and line-height based on element width

148 pointsby aadlaniover 11 years ago

24 comments

crazygringoover 11 years ago
<i>PLEASE</i> do not use this.<p>Yes, the ideal (&quot;most legible&quot;) width for a column of text is ~60 characters, no question. But that&#x27;s <i>only once you&#x27;ve chosen the most legible font size</i>.<p>You&#x27;re supposed to adjust your column width to fit an appropriate number of characters, not adjust the font size to your column width! Adjusting the font size is completely backwards, and worst of all, <i>it&#x27;s breaking my browser zoom</i>, so it&#x27;s terrible for usability.<p>This is a cool demo, but absolutely <i>not</i> something to be used in production. (Sorry to be so negative about it, but the whole project seems based on a misunderstanding of an important design principle.)
评论 #6251957 未加载
评论 #6252189 未加载
评论 #6251544 未加载
评论 #6251306 未加载
评论 #6251009 未加载
评论 #6259332 未加载
felipellrochaover 11 years ago
I don&#x27;t know why all the negative comments here. Just because this solution doesn&#x27;t fit any of your use cases, it doesn&#x27;t mean it&#x27;s a bad solution.<p>There was once I worked on a web app, which was supposed to be viewed on viewports as small as a laptop to viewports as big as a four 57&quot; TVs strung together. Back then, I had to come up with something similar to this to make the content of the TVs visible from a distance. This library would have come really handy back then.
评论 #6251011 未加载
liamondropover 11 years ago
The line-height part of this is unnecessary &#x2F; duplicates css behavior. No need to use px. Just set the line-height to the ratio you want in css.<p><pre><code> p { line-height: 1.45; } </code></pre> and you&#x27;re done.
评论 #6253228 未加载
weegoover 11 years ago
This is entirely the wrong solution to a problem that doesn&#x27;t even exist. In actual fact the problem is fonts are too small on my mobile devices so I&#x27;m constantly zooming in... why would I want my on screen text to start off a couple of pixels high?<p>Also, the whole notion (and seemingly a sub-trend of responsive design) of page content (fonts&#x2F;images) scaling to try and maintain structure when the page is resized is naive to the point of being ridiculous.
ohwpover 11 years ago
So on small screens this will make the font even smaller.<p>This is the wrong solutions.<p>There is a reason why 16pt is the standard font-size. And its no problem to design a responsive website with columns that use &#x27;between 45 and 75 characters per line&#x27;.
评论 #6250272 未加载
gizmoover 11 years ago
I think this is pretty cool (and I like the slider-demo!), but it&#x27;s clearly developed for laptops and mobile devices. On a bigger monitor the website is essentially unreadable. A 29px font for the body copy is a bit outrageous.<p>I like the idea, but I don&#x27;t think fully automatic font scaling is the way to go. Mapping resolution to font size (which is essentially what the Javascript magic does) doesn&#x27;t work because resolution doesn&#x27;t mean much anymore. An HD tablet and a 27&quot; monitor have the same resolution but demand completely different text sizes because you sit so much farther away from a desktop monitor.<p>So for the time being I think the best way to go is to create a mostly fluid layout and to write custom CSS for manual adjustments to make sure it looks good on smartphones, tablets, laptops and desktop monitors.
de_daveover 11 years ago
Seems like a reasonable solution until vmin&#x2F;vmax&#x2F;vh&#x2F;vw are more widely supported.
评论 #6250286 未加载
yannisover 11 years ago
The script can be extremely useful and the concerns raised regarding readability can be overcome using the min and max width. If you adjust line height in conjunction with font-size and font selection, text can be readable from 12pt and up, even at 10pt.
transfireover 11 years ago
Why this kind of functionality hasn&#x27;t been part of the HTML standard from day one boggles the mind. There are many good use cases for this. You don&#x27;t have to use it for everything, btw, even just having it adjust a header could be useful.
lignuistover 11 years ago
&gt; Ideally, the most legible typography contains between 45 and 75 characters per line.<p>The demo impressively shows, that this is not the case for narrow viewports. However, the idea is great.
评论 #6251014 未加载
评论 #6252965 未加载
javindoover 11 years ago
This seems pretty cool but is an absolute nightmare for people like myself who require Ctrl + Scroll zoom all the time for accessibility.
restlessdesignover 11 years ago
I really hate when libraries blindly assume that you are going to be using jQuery and make zero mention of that as a dependency.
评论 #6249929 未加载
shirroover 11 years ago
Another solution in search of a problem that doesn&#x27;t exist. If your viewer has a small screen REDUCE YOUR CONTENT. You probably have lots of waffle you don&#x27;t need anyway. Conversely if they have more screen real estate than brain cells and expand their window to 2000px+ they are stupid. Don&#x27;t encourage them.
mck-over 11 years ago
&gt; This is difficult to accomplish for all screen widths with only CSS media-queries.<p>Couldn&#x27;t you do it with viewport units?
crsmithdevover 11 years ago
Love it. This is great for some very specific use cases (thinking about wall displays &#x2F; large dashboards). It is definitely NOT for accessibility or for the bulk of text on most web pages.<p>Not every library &#x2F; tool has to be universally applicable to be useful.
ksmsjmover 11 years ago
different but cleaner readability trick for blocks containing text, with css: max-width:62em
评论 #6250315 未加载
dizietover 11 years ago
This seems to break browser zoom, so while it is a neat feature, it is not worth having at the cost of accessibility.
endergenover 11 years ago
Seems like a decent idea. Though it seemed to have far too few characters per line on the low end of the slider.
nevesover 11 years ago
Nice hack, but a accessibility failure. Now the users with poor sight can&#x27;t increase the font size.
评论 #6250991 未加载
Ryguover 11 years ago
This would be a nice user script &#x2F; bookmarklet, but I don&#x27;t think websites (except for Readability-type apps) will ever need this. Proper responsive design and usability testing are the correct solution, not this... &quot;hack&quot;. But since we&#x27;re at HACKernews after all, cool effort and props for a very comfortable + practical landing page! Kudos!
rodneytownsover 11 years ago
Just getting started with CSS - Are there any &quot;golden ratio&quot; typography generators?
unicornpornover 11 years ago
This is exactly what I&#x27;ve been looking for a number of times before but was too stupid to hack together myself. Makes sense to me.
ozhover 11 years ago
simple, yet awesome
monsterixover 11 years ago
This is nice, but you&#x27;ll see some alphabets or words would get wrapped into new lines when the <i>element</i>(.demo-type) is resized. It&#x27;s a minor but subtle effect.<p>You might want to revisit how the font-size (and line-height) do not always remain in perfect sync to the element-width. What we&#x27;ve here is the ratio of font-size over width-of-the-element. Since font-size doesn&#x27;t depict width of the font accurately, a percentage change in it doesn&#x27;t reflect proportionally to revised width of the element(.demo-type). Hope this helps.<p>We call this <i>resolution stationary rendering</i> internally and use it in our product: <a href="https://bubbleideas.com/letters/the-tiger-by-sir-william-blake" rel="nofollow">https:&#x2F;&#x2F;bubbleideas.com&#x2F;letters&#x2F;the-tiger-by-sir-william-bla...</a>