Is there a way to achieve multiline ellipsis text in ionic 2. I have a card view and need to restrict maximum 2 lines to be showed inside it with vertical center alignment. I tried webkit css option but it is not working. I saw similar questions asked by others but couldn't figure out an answer for it.
Below is my html code
<ion-content class="cards-bg light-gray">
<ion-list>
<ion-card *ngFor="let od of orderDetails” class="fade_logo">
<ion-card-content> {{od.description}} </ion-card-content>
</ion-card>
</ion-list>
</ion-content>
Here the order description is long text, I just need to show only 2 lines.
It depends on font size and line height but put this in your .scss file and also change the height: to get the best result.
ion-card-content {
display: block;
display: -webkit-box;
height: 60px;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
Related
I am working on the Ionic 5 application for iPad/Tablet. I want to increase the font size of ion-input for full app.
I have tried various options
ion-input {
font-size: 20px !important;
}
input {
font-size: 20px !important;
}
But none of it is increasing the font size. I have even tried to increase the browser inspect element there also it has increased the space but font size is same.
My code structure is
<ion-item class="ion-padding-horizontal">
<ion-label class="input-label" position="stacked">Email</ion-label>
<ion-input class="input-text" type="email"></ion-input>
</ion-item>
When I give font size in the input-text class it is just increasing the size of the input, not the font size
make sure you input is in an ion-item element and then give it your class like this:
CSS:
.size {
font-size: 30px;
}
HTML:
<ion-item>
<ion-input class="size"></ion-input>
</ion-item>
I tested it just now. it works.
I have an ion-item with ion-avatar and ion-label with large text.
For showing full text in ion-label i added a class 'ion-text-nowrap' to ion-label.
It works fine.
But the problem is ion-avatar automatically placed to vertical center of ion-item.
I don't need to align avatar vertical align middle. I want that align left-top of ion-item. How can i do that?
This is my code:
<ion-item>
<ion-avatar slot="start">
<img [src]="img">
</ion-avatar>
<ion-label class="ion-text-nowrap">
<p>{{text}}</p>
</ion-label>
</ion-item>
There are no css properties to achieve this in Ionic.
But it is possible by overwriting the css of the ion-avatar and ion-label.
Change the position of the avatar to absolute and place it in the top corner of the item. Then adjust the label margin to place the text back where you want it.
ion-avatar{
position: absolute;
top: 0px;
left: 0px;
}
ion-label{
margin-left: // size needed
}
Example output:
I would like to vertical align the content on each slide in the center of the screen. But it seems there is no way to style the css of the ion-slides in a way that my content is vertically aligned in the center.
I tried various ways, but none had an impact on the slides.
<ion-slide>
<h2>Date of Birth</h2>
<p>Please select</p>
<ion-item>
<ion-datetime formControlName="birthday" displayFormat="DD-
MM-YYYY" picker-format="DD-MM-YYYY" cancelText="Cancel"
doneText="Done" placeholder="Day-Month-Year">
</ion-datetime>
</ion-item>
</ion-slide>
And CSS i tried:
.slide-container {
vertical-align: center !important;
}
or..
.slides {
display: flex !important;
justify-content: center !important;
align-items: center !important;
height: 100%;
}
How can I overwrite the ion-slides css, so that the content of the slide is perfectly in the middle of the screen?
Make sure your ion-slides have enough height
ion-slide{ height: 80vh;}
I use 80vh with <ion-header>, but without <ion-header> you can use 100vh.
If you still want to make it middle you can use
ion-slide{
position: relative;
top:50%;
transform: translate(0,-50%);
}
I have a button with shape round as follows:
<ion-button expand="full" class="shadow-red" shape="round">Signup with</ion-button>
The class shadow-red is:
.shadow-red{
box-shadow: 0px 14px 25px rgba(182, 30, 30, 0.59);
border-radius: 5px;
}
And the result is:
So I tried many different ways to change the round shape but since it isn't a css class doing the following didn't work.
.round{
border-radius:5px!important;
}
I tried adding border-radius:5px!important; to ion-button class, button, .btn, and many other combinations but none of them worked.
I have also tried to add to variables.css the following lines and none of them worked:
--ion-button-round-border-radius: 5px;
--ion-button-border-radius: 5px;
--ion-border-radius: 5px;
--border-radius: 5px;
....
Don't use the shape attribute, now you can change the look of the button to your wishes. One thing to change is the expand attribute. If you set it to full, you remove the left and right borders (see in docs). And so you can't set or change the border-radius. Set it to block and you will still have a full-width button.
<ion-button expand="block" class="shadow-red">Signup with</ion-button>
Use the following CSS custom properties as described in the Ionic 4 docs.
.shadow-red{
--border-radius: 5px;
--box-shadow: 0px 14px 25px rgba(182, 30, 30, 0.59);
}
Result:
Following code worked for me. As per your need change the height and width value to meet your requirement.
<ion-button slot="end" shape = "round" style="height: 3rem; width : 3rem">
<ion-icon name="create-outline" slot="icon-only"></ion-icon>
</ion-button>
Posting here for future references.
If you want to change the ionic button radius we can use following css. it is working on expand="block" attribute
ion-button {
--border-radius: 20px;
border-radius: 20px;
}
But in ionic button, when we use expand="full" attribute it does not work. so to overcome this limitation we can use CSS Pseudo-elements.
to add a border radius to the bellow button
<ion-button fill="solid" type="submit" color="primary" expand="full" >Login</ion-button>
as bellow image we need to select the native element within the shadow DOM
we can use below Pseudo-elements selector
ion-button::part(native) {
--border-radius: 20px;
border-radius: 20px;
}
above will add the radius on the ionic button with expand="full" attribute
I'm trying to align text in Html but it doesn't work and I do not know why. I'm using Ionic Framework.
My code is:
<ion-list>
<ion-item>
<b>Name</b> <p align="right"> {{paciente.name}}</p>
</ion-item>
....
</ion-list>
and it looks like this:
but I want all text int the same line, and I do not know how to get that.
See this demo: http://play.ionic.io/app/b477ea2f5623
In ionic items, if you write any text within span with item-note class then it will be aligned to right.This is built in class by ionic, your code will be like this :
<ion-item>
<b>Name</b> <span class="item-note"> {{paciente.name}}</span>
</ion-item>
See more tricks with ionic items provide by built in classes, see this Documentation
Add a css class as
.item {
position: absolute;
right: 0px;
width: 300px;
padding: 10px;
}
The p tag creates a paragraph on a new line, so you need an other element. You could use a span element which is floated right:
Html:
<ion-list>
<ion-item>
<b>Name</b> <span class="right"> {{paciente.name}}</span>
</ion-item>
....
</ion-list>
Css:
.right {
float: right;
}
Apply the ckass to all items you want to be on the right.