Home >Web Front-end >CSS Tutorial >Can CSS Prevent Text Wrapping in a Container?

Can CSS Prevent Text Wrapping in a Container?

Susan Sarandon
Susan SarandonOriginal
2024-12-07 17:55:13385browse

Can CSS Prevent Text Wrapping in a Container?

Eliminate Text Wrapping with CSS

Question:

Is it possible to prevent text from wrapping to multiple lines within a given space, regardless of its length?

Answer:

Yes, you can use the white-space property in CSS to eliminate text wrapping. Here's an example:

div {
  white-space: nowrap;
  overflow: hidden;
}

Explanation:

  • white-space: nowrap; prevents the text from wrapping onto a new line.
  • overflow: hidden; truncates the text that exceeds the width of the element.

Additional Notes:

  • This solution works in all major browsers, including versions before CSS3.
  • It's important to add both properties (white-space and overflow) to ensure the desired behavior.

The above is the detailed content of Can CSS Prevent Text Wrapping in a Container?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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