The CSS code designed to limit the display to only a two-line sentence is failing to work properly in Internet Explorer

I've implemented the following CSS code to ensure that the display sentence doesn't exceed 2 lines, with the remaining text being replaced by "...".

.bell-notification-max-words-display {
      overflow: hidden;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;  
    }

While this solution works well for Chrome, Safari, and Mozilla, it's not functioning properly in Internet Explorer. Upon inspecting the element, an error is displayed as shown below:

https://i.sstatic.net/1JFh4.png

Does anyone have any ideas on how to make it work in IE?

Answer №1

Have you experimented with all of these options?

display: -moz-box;
display: -webkit-box;
display: box;
display: -ms-flexbox;

Answer №2

When it comes to ensuring compatibility across various browsers, the most reliable solution might involve utilizing JavaScript for line clamping. My experience using Clamp.js was positive, finding it user-friendly and effective. If you're interested in delving deeper into the "line clamping issue", I recommend checking out this article here.

To implement Clamp.js in your scenario, consider the following:

$clamp(myText, {clamp: 2});

In this code snippet, replace myText with the element you wish to line clamp and set the value to 2 for two lines.

Answer №3

The use of the vendor prefix -webkit indicates specificity to the webkit engine, which is not used by IE, resulting in non-functionality.

To achieve the desired outcome, adjust the line-height and utilize line-height adjustments, along with adding overflow: hidden;.

With overflow set to hidden, content exceeding div dimensions will be truncated:

An effective example:

.parent {
  font-size:16px;
  height: 36px; /* 2x "font-size" +4px clearing */
  line-height: 36px; /* should match your parent div height */
  width: 90%;
  overflow: hidden;
  margin-top: 20px;
}

.child {
  display: inline-block;
  vertical-align: middle;
  line-height: normal; /* reset line height here it here */
}
<div class="parent">
  <div class="child">
    Lorem ipsum dolor sit amet, cu ancillae expetendis ius, pro reque laudem facilisis in, dicta euismod qui eu. No pri graecis similique, ei vim nobis veritus argumentum, platonem torquatos vituperata eum eu. Mel purto eros legendos id, saepe laudem at qui,
    te eum semper interesset. Has id admodum deleniti, eu sumo iisque noluisse ius, vix facer partiendo temporibus ut. In civibus consetetur cum, quo atqui omnium periculis ne. Vim nullam nemore ut.
  </div>
</div>

Another approach involves utilizing a reset HTML textarea element:

Successful implementation:

textarea {
  all: unset;
  width: 100%
}

.sample {
  overflow: hidden;
  max-width: 80%;
  overflow: ellipsis;
}
<textarea class="sample" rows="2">
Lorem ipsum dolor sit amet, cu ancillae expetendis ius, pro reque laudem facilisis in, dicta euismod qui eu. No pri graecis similique, ei vim nobis veritus argumentum, platonem torquatos vituperata eum eu. Mel purto eros legendos id, saepe laudem at qui,
    te eum semper interesset. Has id admodum deleniti, eu sumo iisque noluisse ius, vix facer partiendo temporibus ut. In civibus consetetur cum, quo atqui omnium periculis ne. Vim nullam nemore ut.
</textarea>

Unfortunately, neither method supports the use of ellipsis or "..."

It appears that achieving ellipsis and overflow together solely through CSS without relying on hacks or scripts may not be feasible.

One such hack involves pseudo-elements (suitable only for justified text):

.sample {
  max-width: 80%;
  overflow: hidden;
  position: relative;
  max-height: 2.2em;
  text-align: justify;
  padding-right: .75em;
}

.sample:before {
  content: "...";
  position: absolute;
  right: 0;
  bottom: 0;
}
<div class="sample">
  Lorem ipsum dolor sit amet, cu ancillae expetendis ius, pro reque laudem facilisis in, dicta euismod qui eu. No pri graecis similique, ei vim nobis veritus argumentum, platonem torquatos vituperata eum eu. Mel purto eros legendos id, saepe laudem at qui,
  te eum semper interesset. Has id admodum deleniti, eu sumo iisque noluisse ius, vix facer partiendo temporibus ut. In civibus consetetur cum, quo atqui omnium periculis ne. Vim nullam nemore ut.
</div>

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

What is the method to conceal an element after detecting and locating a specific class using jQuery?

Can someone please assist me today with the following task: Step 1: <div id="htmlData"> <div class="col-md-12"> <div class="pull-left"> <h3>Report: <strong>Travel </strong></h3> ...

Error message: The color shade "100" is not in the color palette. The only available shades are primary, accent, and contrast

I am in the process of upgrading from Angular 12 to 13. Encountering this error, and so far I haven't been able to find a solution for it. Could someone please guide me in the right direction? Here is my package.json file: { "name": &quo ...

What is the best way to remove unnecessary space in a div when the content is smaller than the height, while still using overflow:auto?

HTML CODE <p>overflow:auto</p> <div class="auto">This code snippet will add a vertical scroll bar to the content within the div if it exceeds the height of the div. The background color is set to green, width and height are both 100px, ...

Apply a style to the div element that contains a TextInput component

As a beginner in the world of React and Material UI, I am currently working with Material UI version "1.0.0-beta.17", React 15.6.2, styled-components 2.0.0, and styled-components-breakpoint 1.0.1. Within a div element, I have two TextInput fields. const ...

Having trouble with CSS background-attachment not functioning properly and unable to adjust padding or margins on the background

Currently, I am in the process of learning CSS and HTML5. However, I am experiencing some difficulty when it comes to implementing basic elements. Specifically, I am using Google Chrome and attempting to create a top bar for my webpage. This top bar should ...

Tips for maintaining a single-line div while adding ellipses:

What is the CSS way to ensure that a div or class contains only one line of text, with ellipses added if it exceeds that limit? I am aware that setting a specific height and using overflow:hidden can achieve this, but it doesn't quite work for my need ...

What is the best way to reduce the width of the preformatted tag?

Is there a way to adjust the width of the pre tag in order to avoid affecting the q-card when resizing the browser window? I am trying to create a q-card that can display code similar to what you see in ChatGPT. However, the q-card's size is not respo ...

Obtaining a CHUNKY h1

After years of designing websites, one thing that continues to puzzle me is how people achieve that bold and THICK h1 effect. Take a look at this example - https://i.sstatic.net/xOJHn.png Even with a font weight of 700, it always seems too thin no matter ...

Lack of animation on the button

Having trouble with this issue for 48 hours straight. Every time I attempt to click a button in the top bar, there is no animation. The intended behavior is for the width to increase and the left border color to change to green, but that's not what&ap ...

What is the best technique for creating a preloader that can seamlessly fill the background of a vector image?

I am looking for guidance on creating a CSS3 preloader using a vector image. My goal is to have the logo start off transparent with only the border visible, and as the loading occurs, fill in from bottom to top with the background color. Thank you to ever ...

Converting HTML to PDF using AngularJS

Can anyone help me with converting HTML to PDF in Angular? I have tried using the angular-save-html-to-pdf package from npm, but encountered errors. Are there any other solutions or custom directives available for this task? ...

Tips for modifying the appearance of this input document

Hey there, I have this input element created in React: <span className="btn-file" type='button'> <div style={{display:'flex',justifyContent:'space-around'}}> <span style ...

When trying to interact with the IE element using Selenium WebDriver, it does not register the click on the first

Having a little trouble with clicking on a link in IE 11 using the code below: driver.findElement(By.xpath("//a[text()='En savoir plus']")).click(); No exceptions are being thrown, but the page isn't navigating anywhere. It's freezing ...

There is a noticeable increase in memory leakage when running Selenium in EDGE IE11 mode compared to using IE

Recently, we made the decision to upgrade our Selenium version from 2.53 to 4.1.2 in order to facilitate testing of our application in MS EDGE IE11 mode. This shift is a result of Internet Explorer being phased out soon, so we are transitioning to EDGE in ...

How to position footer at the bottom of Material UI cards - see example below

After getting inspiration from the material-ui example of cards, I wanted to create a grid layout with multiple cards. My goal was to make all the cards have equal height (which I achieved using height:100%) and position the footer at the bottom of each ca ...

jQuery mCustomScrollbars does not correctly resize the height of the div on the initial load

Need help with resizing the height of a div. Currently, I am setting the height of the div using JavaScript, but it only takes effect after refreshing the page (F5). Is there a way to make it work without needing a refresh? Check out the code snippet be ...

Make sure that the input field and label are aligned side by side in the

Is there a way to arrange the following HTML in the specified layout? <div> <div> <label>Counterparty</label> <input id="paymentsApp-inpt-cpty" ng-model="selectedPaymentCopy.counterparty" ng-required="true" ...

Sidebar content alignment vertically

Struggling with aligning items in a sidebar, specifically regarding the fixed footer and the overflow of the main sidebar container. Trying to achieve a layout where the scrollable element stays within the designated space. Current setup includes: ...

Unable to get the desired 100px margin at the bottom

Can someone assist me in positioning the right side image at the bottom of the div tag using CSS? I have tried using the .up class in my style tag but with no success. How can I achieve this by adjusting the margin? <!DOCTYPE html> <html lang=" ...

Switching between dark and light mode in Ant Design

I have successfully implemented dark mode toggling in my application. However, when I try to switch back to light mode, the CSS does not seem to be reloading properly. Below is the code snippet: //ThemeContext.jsx const DarkTheme = lazy(() => import(". ...