How to show ellipsis for a content - html

I am building an Ionic3/Angular application and i have a list of cards of some notes like below:
So, you can see that my notes can be larger than the width of the card. So, it has been truncated as ellipsis using ion-item.
<ion-col col-11 class="padding-0">
<ion-item class="padding-left-0">{{noteInfo.Notes}}</ion-item>
</ion-col>
But, the problem is that Notes are not always plain string like "This is test". It can be a HTML element like
<span style='color:red'>This is test</span>
and the note may be larger than this simple note. As the note will be HTML element, i change my code for showing the note in the card like below:
<ion-col col-11 class="padding-0">
<ion-item class="padding-left-0" [innerHTML]="progressNote[0].HTMLNotes | safeHtml:'html'">
</ion-item>
</ion-col>
And the output is:
But, i have an expand button for every note and if i click on that the actual note is like below:
Now, you can see that setting the HTML in the innerHTML of ion-item, it does not show ellipsis if the notes is larger than the width. But, i need to show only a preview in the card and that preview needs to be colored.
So, is there any way to show the HTML element in an ion-item so that it takes as much as the width can fit in the card and then show ellipsis for rest of the content?
Thanks in advance..

Here's an example of a div with content that acts as you wish, you can apply the CSS rules on your ion-col.
HTML
<div class="card">
<div class="item">
short text
</div>
<div class="item">
long text wrgj rgoiherg eroighe goeirhg rgirg rgihreg
</div>
</div>
CSS
.card{
width: 200px;
}
.item{
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

Check ellipsis-angular npm package.
Using it you may add ellipsis automatically if HTML content overflows container.
Installation: npm i ellipsis-angular
Usage example:
<div ellipsis-angular>
<!-- Static HTML content goes here --->
</div>
or
<div ellipsis-angular [innerHTML]="someHTMLStringVariable"></div>
for dynamic html.

Related

*ngStyle makes visualization disappear

I am trying to display a list of items in an Angular web app. I am having a list component which contains the related *ngFor directive to display each list-item component. Inside the HTML of the list-item component I defined the following structure:
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div class="item">
<div class="content font-weight-bold" style="width: 250px; height: 180px" *ngStyle="{'opacity':
(object.booleanValue) ? 1.0 : 0.5}">
<div class="someActualContent">
<div>{{object.text}}</div>
....
</div>
</div>
</div>
Displaying of the objects works fine (all information are correctly shown) until I add the *ngStyle-directive. Then, no element is visible anymore. However, in inspect mode I can see that all list-items are actually there - they are invisible and smaller than I defined them in the div at style="...". Compiling is successful.
I tried object.booleanValue==true but this didin't lead to any changes.
Does someone have an explanation?
Thank you in advance!
Enclose the ngStyle directive in square brackets instead of micro-syntax notation *ngStyle. Try the following
<div
class="content font-weight-bold"
style="width: 250px; height: 180px"
[ngStyle]="{'opacity': (object.booleanValue) ? 1.0 : 0.5}"
>
...
</div>

unabled to display some element and text at the right place in a card

I develop a small angular material application. My objective is to obtain the following design for a card, that fit on every kind of media (desktop, mobile, tablette)
my "app.component.html" is the following
<mat-toolbar color="primary">
<div style="width:100%;" class="md-toolbar-tools" >
Liste des annonces
<span flex></span>
</div>
</mat-toolbar>
<div fxLayout="row">
<div fxFlex="20%"></div>
<div fxFlex="60%">
<mat-card *ngFor="let annonce of annonces; let i = index" style="border:red">
<mat-card-content style="border:blue">
<img src="./../assets/image/image{{i+1}}.jpg" alt="Avatar" style="position:absolute;top:0px;left:0px;width:40%;height:100%">
<div class="container" style="left: 45%; top:10px;">
<div style="left:70%;">{{annonce.dateConstruction | date:'dd MMMM yyyy'}}</div>
<div>
<span>{{annonce.type}}</span>
<span style="float:right">{{annonce.prix}}</span>
</div>
<h4>{{annonce.surface}}</h4>
<h4>{{annonce.adresse}}</h4>
<div style="left:45%;">
<p>{{annonce.description}}</p>
</div>
</div>
</mat-card-content>
</mat-card>
</div>
<div fxFlex="20%"></div>
</div>
<router-outlet></router-outlet>
I am terrible in placing elements and text in html pages, and therefore in a material card. I obtain the following output in the browser
Furthermore when I shrink my browser, I can't see the element and text on the rigth of the image placed correctly. I tried to reproduce the same on stackblitz (https://stackblitz.com/edit/angular-pexq15?file=package.json), but I got trouble with the angular material tags that are not taken in account.
So could you help me and tell me what is going wrong and comment the correct code so I improve myself in html/css. Thanks a lot
You should try leveraging the #angular/flex-layout Library for this. Additionally, you should consider moving your styles to your CSS File, since this will make your HTML File a lot cleaner and the styles more reusable. In your stackblitz you missed to include the styles for #angular/material in your SCSS File and you did not import the #angular/flex-layout module, which is why your stylings were messed up.
I tried to fix your example on Stackblitz. To get the desired spacings for your text, simply add paddings or margins to the left of those elements. Also beware of your image: You have to add a fitting height property, or it will become cropped/stretched.

Angular: How can I remove wrapper (parent element) without removing the child?

I have seen this answer but it answers for jquery and not angular/typescript.
My question is similar to this question, but my question is seeking a solution for angular.
How can I remove wrapper (parent element) without removing the child in Angular using typescript or scss? (If it is possible by both kindly show both methods).
For example how to programatically manupulate the dom below from
<div class="wrapper">
<span>This is It!</span>
</div>
<div class="button">Remove wrapper</div>
to: (After clicking on the button I would like to have the dom iook like below)
<span>This is It!</span>
<div class="button">Remove wrapper</div>
EDIT:
Kindly also show how to set it so that it can add the wrapper div back when I click the button again. Basically toggling the wrapper div.
I think you can simulate using ng-template and two divs, some like
<div *ngIf="toogle" class="wrapper">
<ng-content *ngTemplateOutlet="template"></ng-content>
</div>
<ng-content *ngTemplateOutlet="!toogle?template:null"></ng-content>
<ng-template #template>
<hello name="{{ name }}"></hello>
</ng-template>
<button (click)="toogle=!toogle">toogle</button>
See a example in stackblitz

Bootstrap (TB3) does not wrap button text in bootstrap (TB3) cols

I am using bootstrap (Twitter-Bootstrap 3) in a quiz style application and I use bootstrap buttons for the answers of the quiz. My problem is that sometimes the answers are quite long, and instead of wrapping the text to the width of the col that the buttons are placed in, the text just keeps going in one line and goes over the col and the width. Is there an easy way to fix this (Note that I canot define set widths as the length of the answers change)? Showing the code is a bit difficult, as it uses javascript to populate the answer buttons, but I will show a screen shot and the resulted populated HTML (after the javascript has populated the question and answers):
Here is the resulting HTML:
<div class="row">
<div style="float: none; margin: 0 auto;" class="col-sm-7">
<div class="panel panel-default">
<div class="panel-heading">Quiz 4 - This is the quiz 4 description</div>
<div class="panel-body" id="question" style="display: block;"><font color="#AAAAAA"><strong>Code: </strong>80559</font><br><br><font color="#888888"><strong>Instruction: </strong>Based on the provided correct answer, select the answer choice that correctly gives the required evidence from the text. Once the timer runs down you will be forced to move onto the next question.</font><br><br><div class="alert alert-info"><strong>Question: </strong>express a negative sentiment in humorous terms</div></div>
<div class="panel-footer clearfix">
<div class="row">
<div class="col-sm-1" id="submit"></div>
<div class="col-sm-11" id="answers" style="display: block;"><button onclick="submitAnswer(22)" class="btn btn-default btn-sm">negative sentiment: You couldn't pay me to watch that....that's how I feel / humorous terms: beach reading without the beach, airport reading without the airport...</button><br><br><button onclick="submitAnswer(23)" class="btn btn-default btn-sm">negative sentiment: they are just the wrong amount of time / humorous terms: they don't have the compressed energy of a short story</button><br><br></div>
</div>
</div>
</div>
</div>
I would think that bootstrap should be wrapping the button text within the div automatically, but it doesn't. I have been looking for solutions but I haven't been able to find anything that covers this problem particularly. Any help would be appreciated. I don't want to use <a href='#" ...> because it is important that the page not reload or be redirected when the button is pressed. Only the onclick function submitAnwers() should be called with no redirect.
The btn class in Bootstrap 3 contains 'white-space:no-wrap;', so the buttons will not wrap on mutliple lines. You can change this using a simple CSS override like:
.btn {
white-space: normal;
}
Demo: http://www.bootply.com/90082
This is an old question with an old answer. The answer solves the problem, but you can get ugly word breaks, where the button breaks in the middle of a word, seemingly wherever it wants to.
My answer forces the button to wrap between words, providing for a nice, clean, and responsive button.
.btn-responsive {
white-space: normal !important;
word-wrap: break-word;
}
Click Here
Hope it helps someone in the future.

My click event isn't being prevented in my (modified) foundation accordion

I have a modified foundation 4 accordion. The reason I've tweaked it is so I can have a row/column setup in my section header, and squeeze an extra column into it.
So instead of this:
<p class="title" data-section-title>Section 1</p>
I have something like this:
<div class="row">
<div class="large-10 columns">
<p class="title" data-section-title>Modified HTML (uses div.row)</p>
</div>
<div class="large-2 columns">
<p>extra column</p>
</div>
</div>
My problem: The click event is not being prevented.
Heres the demo: (ive added the scrolldown to demonstrate the click on the a-tag jumping back to top.)
http://jsfiddle.net/pickledegg/nbJyu/4/
The javascript that prevents the click in a normal scenario is in foundation.section.js. Its combined into foundation.min for my example, so here is the actual un-minified code:
https://gist.github.com/pickledegg/5797197
It seems to be because of this in the javascript
content = $this.siblings(self.settings.content_selector),
if (!settings.deep_linking && content.length > 0) {
e.preventDefault();
}
The code above would be preventing the normal click behavior. However, in your modified code, you add 2 containers around the p with the title class. In order for the code to prevent the link followthrough, the p with the title class and the div with the content class must be siblings. Therefore, I'd probably just add a modified id to the html here:
p class="title" id="modified" data-section-title="">Modified HTML (uses div.row)</p>
and to the javascript:
$('#modified').click(function(event) {
event.preventDefault();
});
Worked for me :)