Tips for truncating a long string on Firefox for a responsive design

Can someone help me figure out how to display a 2-line image text below? Sample Image

This is what it looks like in Chrome, but unfortunately, it doesn't work in Firefox. I came across a website that has a tutorial for Chrome: https://css-tricks.com/line-clampin/. The tutorial uses -webkit-line-clamp to add "..." at the desired line, however, this property does not work in Firefox as mentioned in the tutorial. Is there another way to truncate text in Firefox? I attempted to use JavaScript to trim the string like so:

String.prototype.truncString = function(max, add){
    add = add || '...';
    return (this.length > max ? this.substring(0,max)+add : this);
};
if($(".smaller_768 ").width() < 200 && $(".smaller_768 ") > 120){
    trim_content(28);
}
function trim_content(numberofwords){
            $(".smaller_768").each(function(){
                var content = $.trim($(this).text());
                $(this).text(content.truncString(numberofwords, "..."));
            });
}

However, this method doesn't work consistently when changing devices due to variations in div sizes.

Thank you for your assistance.

Answer №1

One way to implement your function on window resize is by using the following code snippet:

$(window).on("resize", function(){
   if($(".smaller_768 ").width() < 200 && $(".smaller_768 ") > 120){
      trim_content(28);
   }
});

This will dynamically adjust the string length each time you resize your browser window.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoid displaying incorrect UI states while data is being loaded

Within my Vue application version 2.6.X, I utilize single-file components similar to the following structure: <template> <div> <div v-if="users.length"> <!-- users list rendering here --> </div> & ...

Unusual spacing problem detected on iPad device

When I visit my demo site on my iPad, I'm having a strange issue where the player seems to be shifted to the top. This is how it looks on my iPad Mini running iOS 6.1 and tested on both Chrome and Safari: Here is the link to the demo site (change the ...

Form validation has not passed the necessary checks

Struggling to create a new user POST form with Bootstrap form validation but encountering an issue. The button code is as follows: <button class="btn btn-primary btn-addUser" type="submit">Add User</button> This button trig ...

NUXT: Module node:fs not found

Encountering an error when running yarn generate in a Kubernetes container during production. The same command works fine locally and was also functioning properly in production up until last week. Error: Cannot find module 'node:fs' Require stac ...

Learn how to implement drag-and-drop functionality in React by making a component

I am currently experimenting with dragging a component using the react-dnd library. I wanted to replicate functionality similar to this example, specifically only focusing on dragging at the moment. In my application, I have imported and utilized the rea ...

Is the Three.JS camera update causing issues with the shader?

Attempting to replicate the Bubble shader from https://github.com/stemkoski/stemkoski.github.com/blob/master/Three.js/Bubble.html, but encountering issues due to outdated code. The example should refract whatever is behind it, like this: https://i.sstatic ...

PHP 5's HTML Form Library

Currently in search of an alternative to QuickForm. I have encountered performance problems with QF, specifically when dealing with a large number of options in combobox. I prefer something that is more object-oriented like Zend_Form, but without the exc ...

Customize checkbox and label using jQuery

I have a scenario where I have multiple checkboxes and corresponding labels. When the answer is correct, I want to change the background color of the selected checkbox and label. <input type="checkbox" id="a" class="check-with-label" /> <label fo ...

Stripping away AM | PM from date variables

Is there a way to accurately calculate the difference between two datetime values in minutes without including AM|PM? When attempting to trim out the AM | PM from my code, I encounter errors (specifically NaN minutes). How can I safely remove this element ...

Troubleshooting: Issue with CSS chaining adjacent sibling and :checked functionality

When I click the second radio button in Chrome, why does paragraph 2 stay highlighted and paragraph 4 doesn't get highlighted? Is this a bug with Chrome? HTML: <input type="radio" name="toggler" checked /> <p>Paragraph one</p> < ...

Position the label to float on the right side and be centered vertically

I have successfully implemented a navigation bar, but I am facing an issue where the 'menu toggle' button does not align on the right side of the screen when the screen width is 768px or less. Instead, it appears right after the image. (Refer to ...

Guide on validating an input field with an array type name using the jquery.validate.min.js plugin

I am dealing with input tag fields that each have a name attribute within an array. For example: <div class="form-group"> <label class="col-sm-2 control-label"> <span style="color: red;">*</span> Title</label ...

Customizing screen dimensions for a single page using jQuery mobile

I am currently facing an issue with adjusting the size of a specific page within my application. Even though I am using <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, target-den ...

Can someone explain the significance of this error message in Redux - Toolkit?

Encountered this error message while working with Redux-Toolkit, could someone explain its meaning? name:"ConditionError" message:"Aborted due to condition callback returning false." ...

Convert HTML to PDF and ensure that the table fits perfectly on an A4

I am currently utilizing html-pdf to convert my table data into a PDF format. The issue I am facing is that the table content exceeds the specified A4 paper size in such a way that two columns are completely missing in the generated PDF. However, when I c ...

Extracting data from datepicker and passing it to PHP

My appointment booking form consists of 1 input and 2 selects: First: an input field using jQuery for selecting a date. Second: a select dropdown for choosing a hairdressing option. Third: another select dropdown that displays available times based on the ...

Initial 16 characters of the deciphered message are nonsensical

In a specific scenario, I encounter data encryption from the API followed by decryption in TypeScript. I have utilized CryptoJS for decryption in TypeScript. Below is the decryption code snippet: decrypt(source: string, iv: string): string { var key = envi ...

Bootstrap 4 Popover malfunctioning on Safari browser

I'm facing an issue with a popover not showing on hover, specifically in Safari. It works perfectly in all other browsers except Safari, where nothing happens. I've checked my code but can't seem to figure out what's wrong. Below is th ...

Passing PHP loop values to JavaScript

In my current project, I made a decision to avoid using a database and instead opted for files and folders. Each folder in a directory is represented as a button, clicking on which displays a list of files within that folder on the screen. Now, my challeng ...

Transferring Data from Cookie to Drift's Custom Attribute

Seeking assistance: Currently, I am attempting to transfer data from a Cookie in GTM to a custom attribute inside Drift. I have referred to this documentation, but unfortunately, the implementation seems to be failing: Below is the code snippet that I h ...