Ausnahme gefangen: SSL certificate problem: certificate is not yet valid 📌 CSS text-wrap: balance

🏠 Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeiträge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden Überblick über die wichtigsten Aspekte der IT-Sicherheit in einer sich ständig verändernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch übersetzen, erst Englisch auswählen dann wieder Deutsch!

Google Android Playstore Download Button für Team IT Security



📚 CSS text-wrap: balance


💡 Newskategorie: Programmierung
🔗 Quelle: developer.chrome.com

Chrome Canary includes a new feature—text-wrap: balance from CSS Text Level 4. To check it out, enable chrome://flags/#enable-experimental-web-platform-features, and then take a look at the examples in this post to learn how this one line of CSS can massively improve your text layouts.

Try a demo

Without text-wrap: balance; designers, content editors and publishers have few tools to change the way lines are balanced.. The best options available being to use <wbr> or &shy; to help guide text layouts into smarter decisions about where to break lines and words.

As a developer, you don’t know the final size, font size, or even language of a headline or paragraph. All the variables needed for an effective and aesthetic treatment of text wrapping, are in the browser. This is why we see headline wrapping as in the following image:

Headline is highlighted with DevTools, is spanning the full width of its inline space, and has two hanging words on the second line.
Try a demo
.unbalanced {
max-inline-size: 50ch;
}

With text-wrap: balance from CSS Text 4, you can request the browser to figure out the best balanced line wrapping solution for the text. The browser does know all the factors, like font size, language, and allocated area. Results of browser balanced text wrapping looks like this today in Chrome Canary with chrome://flags/#enable-experimental-web-platform-features enabled:

Headline is highlighted like the previous DevTools, this time is not spanning the full width. It started a new line before the end and as such is a balanced block of text.
Try a demo
.balanced {
max-inline-size: 50ch;
text-wrap: balance;
}

It's helpful to see them side by side, still, and without debug information overlaid.

The two previous exaples are shown together, one is marked as unbalanced and the other as balanced.

Your eye should be much more pleased with the balanced text block. It grabs attention better and is overall easier to read.

Finding the balance

Headlines are the first thing readers see; they should be visually appealing and easy to read. This grabs user attention and provides a sense of quality and assurance. Good typography gives confidence to readers, encouraging them to continue reading.

Traditionally this task was done by hand, or optically, as the designer balancing the text wants to please the eye not the math. This topic is often referred to as metric versus optical alignment. For large publications like the New York Times, headline balancing is a very important user experience detail.

Try a demo

Balancing main article text is not common as it doesn't need to stand out or catch a reader's eye.

Balancing text in typography dates back to early days of printing, when printers would hand place letters. As tools and techniques evolved, so did the results. These days, designers have color, weight, size, and more, to balance text in their designs.

On the web however, there's less control available because the document changes sizes and colors based on users. text-wrap: balance brings the art of balancing text to the web in an automated way, building on the work and traditions of designers from the print industry.

Balancing headlines

This will, and should be, the primary use case for text-wrap: balance. Draw the eye with size and make it symmetrical and legible for the eye to read. Set all the headlines to balanced text wrapping with the following CSS:

h1,h2,h3,h4,h5,h6 {
text-wrap: balance;
}

Just applying this style may not provide you with the results you expect, as the text needs to wrap and therefore have a maximum line length applied from somewhere. You'll see a max-inline-size set on the examples in this post, this style is like max-width but can be set once for any language.

Limitations

The task of balancing text is not free. The browser needs to loop over iterations to discover the best balanced wrapping solution. This performance cost is mitigated by a rule, it only works for 4 wrapped lines and under.

Try a demo

Performance considerations

It is not a good idea to apply text-wrap balancing to your entire design. It's a wasted request, due to the four line limit, and may impact page render speed.

Don't

* {
text-wrap: balance;
}

CONSIDER INSTEAD

h1, h2, h3, h4, h5, h6, blockquote {
text-wrap: balance;
}

A big win for this feature is that you don't need to wait and time text wrap balancing with font loading, like you may be doing with JavaScript today. The browser takes care of it!

Interactions with the white-space property

Balancing text competes with the white-space property because one is asking for no wrapping and the other is asking for balanced wrapping. Overcome this by unsetting the white space property, then balanced wrapping can apply again.

.balanced {
white-space: unset;
text-wrap: balance;
}

Balancing won’t change the inline-size of the element

There's an advantage to some of the JavaScript solutions for balanced text wrapping, as they change the max-width of the containing element itself. This has an added bonus of being "shrink wrapped" to the balanced block. text-wrap: balanced does not have this effect and can be seen in this example:

Headline is highlighted like the previous DevTools, this time is not spanning the full width. It started a new line before the end and as such is a balanced block of text.

See how the width shown from DevTools has a bunch of extra space at the end? That's because it's a wrapping style only, not a size changing style. Because of this, there's a few scenarios where text-wrap: balance isn't that great, at least in my opinion. For example, headings inside of a card (or any container with borders or shadows).

Balanced text wrapping ironically creates imbalance to the contained element.

A brief explanation of the technique the browser is using

The browser effectively performs a binary search for the smallest width which doesn't cause any additional lines, stopping at one CSS pixel (not display pixel). To further minimize steps in the binary search the browser starts with 80% of the average line width.

...



📌 Text Balance in CSS is coming 🔥


📈 31.65 Punkte

📌 CSS Grid: Moving From CSS Frameworks To CSS Grid (2018 and beyond)


📈 28.76 Punkte

📌 Stylify CSS: Automagic CSS bundles splitting into CSS layers in Astro.build


📈 28.76 Punkte

📌 A BRIEF REVIEW OF CSS CASCADING, CSS SELECTORS and CSS SPECIFICITY.


📈 28.76 Punkte

📌 Should You Pay Your Credit Card Statement Balance or Current Balance?


📈 27.97 Punkte

📌 How to Check Amex Gift Card Balance at balance.amexgiftcard.com


📈 27.97 Punkte

📌 Creating an animated text gradient with Tailwind CSS (and vanilla CSS)


📈 27.25 Punkte

📌 CSS Text Transform: You Don't Need JavaScript to Capitalize Your Text


📈 25.74 Punkte

📌 Plain Text Editor 1.2.1 - Simple distraction-free text editor without any rich text nonsense.


📈 24.24 Punkte

📌 Facing an issue in froala text editor, style of the text is lost when the text is cut


📈 24.24 Punkte

📌 CSS: How About Building A Search Engine With CSS?


📈 19.17 Punkte

📌 The Future of CSS: CSS Houdini


📈 19.17 Punkte

📌 New in Chrome 65: CSS Paint API, Server Timing API, and CSS display: contents


📈 19.17 Punkte

📌 Medium CVE-2021-33587: Css-what project Css-what


📈 19.17 Punkte

📌 State Of CSS Survey: Influence The Future Of CSS


📈 19.17 Punkte

📌 Do CSS framework users actually know CSS? We might have some data


📈 19.17 Punkte

📌 CSS Guide: Basics of CSS


📈 19.17 Punkte

📌 Stylify CSS: Code your Remix website faster with CSS-like utilities


📈 19.17 Punkte

📌 How to create navigation menu with HTML CSS step by step | web design tutorial | HTML CSS tutorial


📈 19.17 Punkte

📌 Stylify CSS: Code your SvelteKit website faster with CSS-like utilities


📈 19.17 Punkte

📌 Learn CSS by Building the Figma Logo in Pure CSS


📈 19.17 Punkte

📌 Learn CSS by Building the YouTube Logo in Pure CSS


📈 19.17 Punkte

📌 Learn CSS by Building the Microsoft Logo 2 Different Ways in Pure CSS


📈 19.17 Punkte

📌 Learn CSS by Building the React Logo in Pure CSS


📈 19.17 Punkte

📌 Learn CSS by Building the Nextflix Logo in Pure CSS


📈 19.17 Punkte

📌 MediaWiki bis 1.23.14/1.26.3/1.27.0 CSS User Subpage Preview common.css Cross Site Scripting


📈 19.17 Punkte

📌 MediaWiki up to 1.23.14/1.26.3/1.27.0 CSS User Subpage Preview common.css cross site scripting


📈 19.17 Punkte

📌 Schneider Electric U.motion Builder up to 1.3.3 css.inc.php css directory traversal


📈 19.17 Punkte

📌 mTheme-Unus Theme up to 2.2 on WordPress css/css.php files directory traversal


📈 19.17 Punkte

📌 Post-Modern CSS (In-Depth on CSS Grid, Flexbox and Other New Properties)


📈 19.17 Punkte

📌 Schneider Electric U.motion Builder bis 1.3.3 css.inc.php css Directory Traversal


📈 19.17 Punkte

📌 Learn CSS by Building the Git Logo in Pure CSS


📈 19.17 Punkte

📌 Learn CSS by Building the Google Logo in Pure CSS


📈 19.17 Punkte











matomo