How can I make my text look like the image below using CSS?
相关问题
- JavaFX automatically resize Button's font size
- Get image width height javascript
- Get the size of an element when inside a display:n
- width equal to dynamic height square [duplicate]
- Installing Wine on Mac OS Catalina. Error: No avai
相关文章
- How to control print font size
- Label size in directlabels geom_dl()
- SSRS tablix column CanGrow property for width?
- Is it possible to style a text input to fill the w
- Selenium find_elements_by_id() doesn't return
- Canon EDSDK How can I get width and height of live
- Using docx python library, how to apply color and
- Adding a percent column to MS Access Query
First of all you need to use a mono-space font. You can find some pretty nice looking ones over at Google Fonts. The font in the image is Ubuntu Mono.
Secondly, we are going to be using Viewport Width, or 'vw' unit (If you clicked the link, you'd see that it is well supported by browsers). You need to make sure the top line of text is the width you need it be to fit the width. This also means that each line needs to be it's own element. Some example HTML:
We can now use this initial place-holder to work out the 'vw' size for the rest of the lines using the following formula:
I have created this example to show how this can be achieved programmatically with JavaScript (I used JQuery for ease). The code that it spits out is as follows:
It should be noted that because Google Chrome rounds all font sizes to the nearest round pixel (boo-hiss), it's not exact and it can look off, especially at smaller sizes.