22.08.2022
When creating a layout in CSS, it is essential to consider the length of text content. If a word is added or removed in the text, many situations will cause the design to change. I will discuss the methods used to manage different text lengths in this article. Techniques may vary depending on the purpose of the page.
If the size of the content is larger than the container’s area, it is not divided into the bottom line by default and overflows beyond its container. One of the ways we can use to avoid this issue is overflow-wrap. By default, it will take overflow-wrap: normal;
. We must set this value to overflow-wrap:break-word;
to enable long content to move to a subline when there is not enough space left. With the CSS code below, we can get any we want.
.element {
overflow-wrap: break-word;
}
When words do not fit in the line, they are divided by the browser according to the language specified in HTML. The following CSS code allows us to cross a subline with hyphens.
.element {
hyphens: auto;
}
It’s a method we can use when we want our content to be one line. At the end of the container area, it truncates the content by placing three points. That way, we can also indicate that there is more to the content. There is no custom CSS attribute, but several CSS properties combine to help us create the image we want.
.element{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
We may ask that our content truncates after a specific line. In such cases, the developer can use the line-clamp feature. Following the number specified in this feature, the content is truncated. display: - webkit-box;
must be used for this method to work. Another important thing is to use the element padding property. Padding is detected as an empty line, and the content appears in more rows than we set. Below is the difference between CSS line-clamp code and padding applied and non-padding applied.
.element {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
Perfist Blog
Similar Articles
What is Site Speed? Site speed refers to how quickly a web page loads. (Site speed has multiple factors. The most important of these are initial load time and load speed.) This speed directly affects the visitor experience. A slow-loading site can cause users to leave the site and choose other pages. Additionally, search engines […]
Read More
Mid Level SEOWhat is Structured Data? Structured data is a coding system used to help search engines better understand the content of a website. Implemented using formats like JSON-LD and Microdata, it enables the presentation of detailed information such as products, events, and business details in a comprehensible way. This is especially advantageous for e-commerce websites, as […]
Read More
Mid Level SEOIn the digital marketing world, user-generated content (UGC) is becoming increasingly important. UGC includes videos where users share their own experiences, opinions, and creativity in promoting brands and products. So, why are UGC videos so significant in digital marketing strategies? 1. Trustworthiness and Authenticity User-generated content creates a more trustworthy perception for consumers compared to […]
Read More
Performance MarketingWith the transition from Universal Analytics to Google Analytics 4, there may be some issues you need to resolve. One of these issues is “unassigned” traffic. Dimensions appearing as “unassigned” / (not set) in reports negatively impact your ability to analyze and optimize. We will discuss the causes of “unassigned” traffic in your GA4 reports […]
Read More
Beginner Level Web/App Analytics