In web development, sometimes you may encounter the need to prevent text from wrapping onto multiple lines. This can be useful for maintaining the aesthetics of your layout or for ensuring data is displayed in a compact manner.
A simple yet effective solution is to use the white-space property. By setting white-space to nowrap, you instruct the browser to prohibit text from breaking across multiple lines.
div { white-space: nowrap; }
To prevent the wrapped text from extending beyond the designated height, combine white-space: nowrap with overflow: hidden. This combination truncates the text horizontally and vertically.
div { white-space: nowrap; overflow: hidden; }
It's important to note that this approach works consistently across all major browsers before CSS3 was introduced. However, for modern browsers, it's recommended to use the text-wrap property for wider compatibility.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3