基於容器寬度的字體縮放 - Font scaling based on width of container

問題:

I'm having a hard time getting my head around font scaling. 我很難理解字體縮放。 html

I currently have this site with a body font-size of 100%. 我目前有一個網站的正文font-size爲100%。 100% of what though? 不過是100% This seems to compute out at 16 pixels. 這彷佛能夠計算出16個像素。 瀏覽器

I was under the impression that 100% would somehow refer to the size of the browser window, but apparently not because it's always 16 pixels whether the window is resized down to a mobile width or full blown widescreen desktop. 我給人的印象是100%會以某種方式引用瀏覽器窗口的大小,可是顯然不是由於將窗口縮小到移動寬度仍是全屏寬屏桌面老是16像素。 app

How can I make the text on my site scale in relation to its container? 如何使網站上的文本相對於其容器而言? I tried using em , but this doesn't scale either. 我嘗試使用em ,但這也沒法擴展。 ide

My reasoning is that things like my menu become squished when you resize, so I need to reduce the px font-size of .menuItem among other elements in relation to the width of the container. 個人理由是,當您調整大小時,菜單之類的東西會變得狹窄,所以我須要根據容器的寬度來減小.menuItempx font-size (For example, in the menu on a large desktop, 22px works perfectly. Move down to tablet width and 16px is more appropriate.) (例如,在大型桌面上的菜單中, 22px能夠完美工做。向下移動至平板電腦寬度,則16px更合適。) 字體

I'm aware I can add breakpoints, but I really want the text to scale as well as having extra breakpoints, otherwise I'll end up with hundreds of breakpoints for every 100 pixels decrease in width to control the text. 我知道我能夠添加斷點,可是我確實但願文本可以縮放以及具備額外的斷點,不然我將每減小100像素的寬度就會獲得數百個斷點來控制文本。 網站


解決方案:

參考一: https://stackoom.com/question/15N3H/基於容器寬度的字體縮放
參考二: https://oldbug.net/q/15N3H/Font-scaling-based-on-width-of-container
相關文章
相關標籤/搜索