Can You Stretch Text Without Altering Its Font Size with CSS?

Barbara Streisand
Release: 2024-10-27 20:27:30
Original
310 people have browsed it

 Can You Stretch Text Without Altering Its Font Size with CSS?

Stretching Text with CSS: Is It Possible?

The desire to stretch text without altering its font size is a common challenge in web design. To achieve this unique effect, CSS 2D Transforms come into play.

Supported by modern browsers, including IE9 , this technique allows you to deform text vertically while maintaining its original size. Here's how it works:

  1. Wrap the Text in a Div: Start by enclosing the text you want to stretch in a
    element.
  2. Apply CSS Transform: Within the class applied to the div, use the following CSS rule:
<code class="css">transform: scale(2,1);</code>
Copy after login

This scale transformation scales the text by a factor of 2 vertically (along the y-axis) while keeping its horizontal (x-axis) dimensions unchanged.

  1. Add Inline-Block Property: Add the display:inline-block property to ensure that the stretched text wraps within its container.

Example:

<code class="html"><p>I feel like <span class="stretch">stretching</span>.</p></code>
Copy after login
<code class="css">span.stretch {
    display:inline-block;
    transform:scale(2,1);
}</code>
Copy after login

This example will stretch the word "stretching" vertically while keeping the rest of the text unstretched.

The above is the detailed content of Can You Stretch Text Without Altering Its Font Size with CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!