UPDATE: Today (11the May 2022) Elementor Pro released version 3.7 which includes the feature to “Apply to custom Excerpt” This fixes the excerpt length issue.
The Excerpt Length in the post widget’s layout panel does not match the number you put in the field.
It is quite frustrating and leaves a huge space in between the content when you disable the masonry option.
This happened to my blog before and now it is fixed with the help of CSS.
I want to show you how I did it step by step
The applied excerpt length is not working in the Elementor post widget
After adding the CSS, it fixed the issue
You can see that I am not the only one with this issue. See it for yourselves in GitHub.
Here is the step-by-step tutorial on how to fix the Excerpt Length issue in the post widget with the help of CSS:
Provide CSS class to the post widget
- Click the Post widget handle and navigate to the Advanced tab-
- Give CSS class to the post widget as “line-height”
Add Custom CSS to fix the excerpt length issue
We will use the -webkit-line-clamp CSS property to limit the contents to the specified number of lines.
The -webkit-line-clamp CSS property allows limiting of the contents of a block container to the specified number of lines.
It only works in combination with the display property set to -webkit-box or -webkit-inline-box and the -webkit-box-orient property set to vertical.
In most cases you will also want to set overflow to hidden, otherwise the contents won’t be clipped but an ellipsis will still be shown after the specified number of lines.
When applied to anchor elements, the truncating can happen in the middle of the text, not necessarily at the end.
On the bottom of the panel, you will find Custom CSS, and there add this CSS.
This CSS only works with post-excerpt
/*
* This CSS only works with post excerpt
* Adjust the line-clamp integer value.
* Require Browser prefix to work.
* You can use the selector but using CSS class is much better
*/
.line-height .elementor-post__excerpt,
.line-height .elementor-post__excerpt p,
.line-height .elementor-post__excerpt a p{
-webkit-line-clamp: 3;
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
}
Compatibility
When we use new CSS property, we often ask whether it is going to be compatible with the majority of the browser vendors but it turns out it supports over 95% globally which is excellent and safe to use according to Can I Use and MDN.
Hope it helps.
Cheers