I have a card with a bunch of text inside of it. Some of this is lengthy and it is forced onto the next line like this,
I'd like for the text to remain on one line, and become an ellipsis if necessary for a tooltip. So like 'Declined to ans...' etc
I've used flex and angular-material to set this up currently.
Things I have tried:
Setting the following css properties:
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
This will make the text no longer overflow, but the ellipsis isn't applied.
Here is the HTML
<div *ngIf="profile" fxLayout="row" style="justify-content: space-evenly;">
......
<div fxLayout="column" style="flex-basis: 75%; margin-right: 10px;">
<mat-card class="card-info" style="flex: 1.5;">
<div class="mat-card-header-text">Personal Information</div>
<mat-card-content class="flex-and-justify-between">
<div fxLayout="column" style="padding: 5px;">
<label class="info-heading">Date of Birth</label>
<label>{{profile.dateOfBirth | date }}</label>
<label class="info-heading info-heading-padded">Sexuality</label>
<label>{{profile.sexuality.value}}</label>
<label class="info-heading info-heading-padded">Previous Offender</label>
<label>{{profile.previousOffender}}</label>
</div>
<div fxLayout="column">
<label class="info-heading">Gender</label>
<label>{{profile.gender}}</label>
<label class="info-heading info-heading-padded">Gender Identity</label>
<label>{{profile.genderIdentity.value}}</label>
<label class="info-heading info-heading-padded">Date of First Visit</label>
<label>22/01/2018</label>
</div>
<div fxLayout="column">
<label class="info-heading">Postcode</label>
<label>{{profile.postcode}}</label>
<label class="info-heading info-heading-padded">Location</label>
<label>{{profile.location.value}}</label>
<label class="info-heading info-heading-padded">Employment Status</label>
<label>{{profile.employmentStatus.value}}</label>
</div>
<div fxLayout="column">
<label class="info-heading">Ethnicity</label>
<label>{{profile.ethnicity.value}}</label>
<label class="info-heading info-heading-padded">Sex Worker</label>
<label>{{profile.sexWorker}}</label>
</div>
</mat-card-content>
</mat-card>
</div>
Here is the CSS:
.card {
padding: 0;
width: 225px;
margin: 15px 15px 0 15px;
}
.card-initials {
display: flex;
flex-wrap: nowrap;
background-color: #D3DCE5;
border-bottom: #afbfd0 1px solid;
}
.card-initials span {
text-align: center;
width: inherit;
line-height: 225px;
font-size: 72px;
}
.card-info {
margin-top: 15px;
}
.mat-card-header-text {
margin: 0;
margin-bottom: 10px;
font-weight: bold;
}
.info-heading {
color: #728ba7;
}
.info-heading-padded {
padding-top: 13px;
}
.mat-card-header-text a {
float: right;
font-weight: normal;
font-size: 12px;
text-decoration: none;
color: #58708d;
}
.tooltip {
fill: #333333;
}
If you want to prevent the text from wrapping, you can apply white-space: nowrap; Notice in HTML code example at the top of this article, there are actually two line breaks, one before the line of text and one after, which allow the text to be on its own line (in the code).
nowrap. Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered.
You can do it like this:
.text {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
display: block;
width: 100%;
min-width: 1px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With