Challenge with line breaking and shortening lengthy content in Angular

Struggling with properly wrapping and truncating long text in an Angular project. The goal is to wrap the text in 2 lines and if it goes beyond that, add "..." at the end of the second line. Pure CSS doesn't work because the text needs to be left-aligned, not justified. Also, compatibility with Firefox rules out the use of -webkit-line-clamp. Both the text container and the text itself need to be responsive.

Any tips on how to achieve this in Angular 7?

Answer №1

If you're working with Angular, you have the option to create an ng-if statement that checks the length of a value and adds ellipses if it exceeds a certain number.

<span ng-if="textValue.length > 100" class="ng-scope">...</span>

To enable wrapping in your code, you can utilize the following CSS properties:

word-wrap: break-word;
overflow-wrap: break-word;

To dive deeper into this topic, check out the CSS-Tricks article available at https://css-tricks.com/almanac/properties/o/overflow-wrap/

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

"Encountering an issue where Django Python fails to redirect to the login page despite clicking the sign up

This is my initial Django project, and I'm facing an issue where users are not redirected to the login page after filling out the sign-up form and clicking on the button. Instead, the sign-up form just reloads, keeping me on the signup.html page. I&ap ...

The value in reactive forms is represented as an object containing the key "value" with the corresponding value of "therealname", instead of just being the string "therealname"

Snippet Example: <div>name: {{fg.get('name').value | json}}</div> When I set up the reactive form with #1 this code snippet: this.fg = this.fb.group({name: "myname"}); The result in the div is, name: myname #2 However, using e ...

Unable to contain Bootstrap 4 dropdown text within a div

I have spent countless hours trying to solve this issue and I am feeling quite desperate at this point. The task at hand is creating a notification dropdown in Bootstrap 4. Despite trying numerous approaches, none seem to be effective. The dropdown should ...

Having trouble aligning my CSS form correctly

The issue is with the alignment of the second row of textbox elements under the "Add Equipment" section on this page: While organizing the code in Dreamweaver, the elements line up correctly. However, when viewed in Google Chrome, they shift to the second ...

What are some creative methods to apply CSS styling to material-table in React?

I've spent several days searching for a solution without any luck. My project involves using material-table in React, and I am struggling to apply CSS styles to the headers (columns) and content (such as changing font size, adjusting width, and creati ...

Concealing forms within an Angular 5 application

I'm currently working on displaying the terms of use on the initial screen along with two buttons. If the user clicks the accept button, they will be directed to the authentication form. However, if they click refuse, the "Refused Terms" screen will a ...

Determine the vertical position of an element within an iframe

Hi there, I've noticed a similar question has been asked before. On my iframe page, there are approximately 10 textfields. Whenever a user clicks on one of the textfields, I want to be able to determine the Y position on that particular page. Is this ...

Having trouble sending a POST request to a .NET API through the browser but successful with Postman? Need some troubleshooting advice?

My current struggle is with the inability to send a POST request to my .NET API using a browser, even though it works perfectly fine with Postman. //angular const url = "http://localhost:5001/ApplicationManager/saveForm"; const model = { ...

Tips for aligning the image and text in the center of the page

Struggling to center this image on my website. I've attempted various methods like margin: 0 and absolute positions, but nothing seems to work. Being a beginner in html and css doesn't help either. My attempts to center it have been futile. The ...

Is it permissible to have empty elements in HTML for accessibility purposes?

Can you help me with a question I have? I was informed that utilizing code like the following is not recommended for creating accessible HTML: <span class="fa-stack fa-lg"> <i class="fa fa-cloud fa-stack-2x"></i> <i class="fa fa-c ...

What is the best way to maintain the routerLinkActive state when navigating to another component page that is related to the current page

Why does the navigation link become inactive when routing from myloans to syncmyloans? How can I maintain navigation activation when moving to related sub pages within the main navigation? Navigation <nav> <ul class="navbar-nav ml-auto&q ...

Using JavaScript to Show Variables When Clicked

I have been working on populating multiple divs with data stored in variables that change when an image is clicked. Here's a snippet of the code within my tag:</p> <pre><code>function displayName(name){ document.getElementById( ...

Pros and Cons of Using HTML5 Mode versus Hash Mode in AngularJS

When using AngularJS 1.3, it is necessary to include the <base> tag in HTML5 mode. This led me to consider the pros and cons of HTML5 mode versus Hash mode. In Hash mode, the major drawback is that URLs can appear unattractive and may not be easy fo ...

The PHP tag is being terminated by the code within the query $db->

Apologies for my lack of recent experience in php. I am revisiting some old code to troubleshoot a peculiar issue that has arisen. Within the realm of wordpress, I find myself editing php code and noticing an unexpected closure of the php tag below: <? ...

Having trouble with the Tap to copy discount code function not working in the Shopify cart drawer?

Our goal is to implement tap to copy functionality for code snippets on our Shopify website. It works seamlessly on the product detail page, but in the cart drawer, it only functions properly after the second page load. https://i.sstatic.net/xzMVY.png ...

Mobile devices may experience a glitch with the input group append feature on screens with lower resolution

I have a form in a navigation bar where I am trying to display the submit button beside my text box. Everything looks good on larger screens, but when I switch to mobile view, there is an awkward gap between the text box and the button. This issue becomes ...

Styling <html:link> elements with CSS

I'm new to using struts and I'm struggling with applying my CSS styles to link tags. <html:link action="LoginLink" styleClass="loginButton"/> My goal is to add a button image to a link that directs to a login page. I've successfully ...

Swimming Left and Right Arrows

I am struggling to create a layout where images are stacked horizontally, with small arrows centered vertically on the left and right sides for scrolling. However, the arrows are currently centered relative to the page, rather than to the center image. I ...

"Google Maps Integration: Customize Your Map with Grey Color Scheme and User-F

After reviewing the other questions and answers related to my problem, none of them seemed to address it. The issue is that when loading and placing a marker, the map seems to "freeze," turns grey, but still displays controls. The marker ends up in the up ...

Adding an element below the 3rd line using CSS

Here's the HTML code I need help with: <style> .ad { margin: 15px; height: 30px; background-color: #7f7f7f; } .article { width: 300px; font-size: 24px; line-height: 30px; border: 1px solid; } </style> <div class="ad"></div> ...