Ionic how to fix ion content to fill the device screen size












0














What i want is my ion content to fit to device screen. I want reduce or expand ion-content instead of scroll.



Currently my page looks image below for Iphone 5 in chrome device toolbar. on the other hand, everything looks perfect for Iphone X because of device screen size.



I have following HTML:



<ion-content padding class="card-background-page " no-bounce>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
</ion-content>


CSS



page-menu {
.hr{
border: 0;
clear:both;
display:block;
width: 96%;
background-color:#f3f6db;
height: 1px;
}
.card-background-page {
ion-card {
position: relative;
text-align: center;
background-color: transparent;
}
.card-title {
top: 74%;
font-size: 2.0em;
width: 100%;
color: #fff;
font-family: auto;

}
.card-subtitle {
font-size: 1.0em;
position: absolute;
top: 52%;
width: 100%;
color: #fff;
}
}
}


enter image description here



StackBlitz Url: here



What is your advice or directive?
Thanks.










share|improve this question
























  • can you put this code together in a stackblitz?
    – Gabriel Barreto
    Nov 21 '18 at 17:50










  • sure, i edited my question.
    – Veysel
    Nov 21 '18 at 18:17










  • Okay, i understood what you need, but is this page going to be something like a menu? Will it be only 6 items or less? I can make a code for you, but keep in mind that the .scroll-content class has the purpouse to scroll your content so it doesn't fit you content to 100% of your screen height and more than 6 items will make it look weird.
    – Gabriel Barreto
    Nov 21 '18 at 19:22










  • as i understand it we can't do it dynamically. actually it would be good that you make a code for me. May be I can understand the event by examining your code.
    – Veysel
    Nov 21 '18 at 20:11










  • @GabrielBarreto could you help me please ?
    – Veysel
    Nov 25 '18 at 1:06
















0














What i want is my ion content to fit to device screen. I want reduce or expand ion-content instead of scroll.



Currently my page looks image below for Iphone 5 in chrome device toolbar. on the other hand, everything looks perfect for Iphone X because of device screen size.



I have following HTML:



<ion-content padding class="card-background-page " no-bounce>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
</ion-content>


CSS



page-menu {
.hr{
border: 0;
clear:both;
display:block;
width: 96%;
background-color:#f3f6db;
height: 1px;
}
.card-background-page {
ion-card {
position: relative;
text-align: center;
background-color: transparent;
}
.card-title {
top: 74%;
font-size: 2.0em;
width: 100%;
color: #fff;
font-family: auto;

}
.card-subtitle {
font-size: 1.0em;
position: absolute;
top: 52%;
width: 100%;
color: #fff;
}
}
}


enter image description here



StackBlitz Url: here



What is your advice or directive?
Thanks.










share|improve this question
























  • can you put this code together in a stackblitz?
    – Gabriel Barreto
    Nov 21 '18 at 17:50










  • sure, i edited my question.
    – Veysel
    Nov 21 '18 at 18:17










  • Okay, i understood what you need, but is this page going to be something like a menu? Will it be only 6 items or less? I can make a code for you, but keep in mind that the .scroll-content class has the purpouse to scroll your content so it doesn't fit you content to 100% of your screen height and more than 6 items will make it look weird.
    – Gabriel Barreto
    Nov 21 '18 at 19:22










  • as i understand it we can't do it dynamically. actually it would be good that you make a code for me. May be I can understand the event by examining your code.
    – Veysel
    Nov 21 '18 at 20:11










  • @GabrielBarreto could you help me please ?
    – Veysel
    Nov 25 '18 at 1:06














0












0








0







What i want is my ion content to fit to device screen. I want reduce or expand ion-content instead of scroll.



Currently my page looks image below for Iphone 5 in chrome device toolbar. on the other hand, everything looks perfect for Iphone X because of device screen size.



I have following HTML:



<ion-content padding class="card-background-page " no-bounce>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
</ion-content>


CSS



page-menu {
.hr{
border: 0;
clear:both;
display:block;
width: 96%;
background-color:#f3f6db;
height: 1px;
}
.card-background-page {
ion-card {
position: relative;
text-align: center;
background-color: transparent;
}
.card-title {
top: 74%;
font-size: 2.0em;
width: 100%;
color: #fff;
font-family: auto;

}
.card-subtitle {
font-size: 1.0em;
position: absolute;
top: 52%;
width: 100%;
color: #fff;
}
}
}


enter image description here



StackBlitz Url: here



What is your advice or directive?
Thanks.










share|improve this question















What i want is my ion content to fit to device screen. I want reduce or expand ion-content instead of scroll.



Currently my page looks image below for Iphone 5 in chrome device toolbar. on the other hand, everything looks perfect for Iphone X because of device screen size.



I have following HTML:



<ion-content padding class="card-background-page " no-bounce>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
<ion-row>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
<ion-col (click)="goPage(4)">
<ion-card>
<img src="assets/imgs/kid.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</ion-col>
</ion-row>
</ion-content>


CSS



page-menu {
.hr{
border: 0;
clear:both;
display:block;
width: 96%;
background-color:#f3f6db;
height: 1px;
}
.card-background-page {
ion-card {
position: relative;
text-align: center;
background-color: transparent;
}
.card-title {
top: 74%;
font-size: 2.0em;
width: 100%;
color: #fff;
font-family: auto;

}
.card-subtitle {
font-size: 1.0em;
position: absolute;
top: 52%;
width: 100%;
color: #fff;
}
}
}


enter image description here



StackBlitz Url: here



What is your advice or directive?
Thanks.







css ionic-framework ionic4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 18:17







Veysel

















asked Nov 21 '18 at 16:16









VeyselVeysel

166




166












  • can you put this code together in a stackblitz?
    – Gabriel Barreto
    Nov 21 '18 at 17:50










  • sure, i edited my question.
    – Veysel
    Nov 21 '18 at 18:17










  • Okay, i understood what you need, but is this page going to be something like a menu? Will it be only 6 items or less? I can make a code for you, but keep in mind that the .scroll-content class has the purpouse to scroll your content so it doesn't fit you content to 100% of your screen height and more than 6 items will make it look weird.
    – Gabriel Barreto
    Nov 21 '18 at 19:22










  • as i understand it we can't do it dynamically. actually it would be good that you make a code for me. May be I can understand the event by examining your code.
    – Veysel
    Nov 21 '18 at 20:11










  • @GabrielBarreto could you help me please ?
    – Veysel
    Nov 25 '18 at 1:06


















  • can you put this code together in a stackblitz?
    – Gabriel Barreto
    Nov 21 '18 at 17:50










  • sure, i edited my question.
    – Veysel
    Nov 21 '18 at 18:17










  • Okay, i understood what you need, but is this page going to be something like a menu? Will it be only 6 items or less? I can make a code for you, but keep in mind that the .scroll-content class has the purpouse to scroll your content so it doesn't fit you content to 100% of your screen height and more than 6 items will make it look weird.
    – Gabriel Barreto
    Nov 21 '18 at 19:22










  • as i understand it we can't do it dynamically. actually it would be good that you make a code for me. May be I can understand the event by examining your code.
    – Veysel
    Nov 21 '18 at 20:11










  • @GabrielBarreto could you help me please ?
    – Veysel
    Nov 25 '18 at 1:06
















can you put this code together in a stackblitz?
– Gabriel Barreto
Nov 21 '18 at 17:50




can you put this code together in a stackblitz?
– Gabriel Barreto
Nov 21 '18 at 17:50












sure, i edited my question.
– Veysel
Nov 21 '18 at 18:17




sure, i edited my question.
– Veysel
Nov 21 '18 at 18:17












Okay, i understood what you need, but is this page going to be something like a menu? Will it be only 6 items or less? I can make a code for you, but keep in mind that the .scroll-content class has the purpouse to scroll your content so it doesn't fit you content to 100% of your screen height and more than 6 items will make it look weird.
– Gabriel Barreto
Nov 21 '18 at 19:22




Okay, i understood what you need, but is this page going to be something like a menu? Will it be only 6 items or less? I can make a code for you, but keep in mind that the .scroll-content class has the purpouse to scroll your content so it doesn't fit you content to 100% of your screen height and more than 6 items will make it look weird.
– Gabriel Barreto
Nov 21 '18 at 19:22












as i understand it we can't do it dynamically. actually it would be good that you make a code for me. May be I can understand the event by examining your code.
– Veysel
Nov 21 '18 at 20:11




as i understand it we can't do it dynamically. actually it would be good that you make a code for me. May be I can understand the event by examining your code.
– Veysel
Nov 21 '18 at 20:11












@GabrielBarreto could you help me please ?
– Veysel
Nov 25 '18 at 1:06




@GabrielBarreto could you help me please ?
– Veysel
Nov 25 '18 at 1:06












1 Answer
1






active

oldest

votes


















1














So the problem is that it wasn't responsive enough and it can be tricky to get something responsive in an ionic 3 app, since in that page you have the ion-content wich has .scroll-content and .fixed-content inside, also the tab doesn't "push" the content up, ionic simply add an exact amount of margin to the content so it doesn't collide with the footer.



So here is what i've done:



HTML:



<ion-content class="card-background-page">
<div class="buttons">
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</div>
</ion-content>


CSS:



page-home {
ion-content{
background: url('https://i.imgur.com/olLunTc.jpg')no-repeat fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}

.scroll-content {
overflow-y: hidden;
}
.card-background-page {
.buttons {
display: grid;
grid-template: repeat(3, 1fr) / repeat(2, 1fr);
height: calc(100vh - 55px); // i've added this number of pxls, but you can inspect and get the exact amount of the tab footer
}
ion-card {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
background-color: transparent;

img {
width: 80%;
}
.card-title {
font-size: 2rem;
width: 100%;
color: #fff;
font-family: auto;
}
}
}
}


So first i removed the ionic grid from your code and instead used CSS grid to do the job. Ionic grid is good, it does a great job as a responsive grid, but you can't control it enough, so for this CSS grid is better.



I created an div with class buttons to hold the "menu", it has a calculated height so it can fit the whole content removing the tab height. This alone'll make your content stretch only to that area.



So with this the cards will respect the rows and columns of the CSS grid, now the job is making the image and text responsive and that's easy using % for the image and rem for the text.



I've asked about the amount of items in that menu because it'll look strange if it's more than 6 items, you'll need to modify the number of rows in the first argument of grid-templates. So 8 or more items will make the image smaller and depending of what you want to show it'll not be good, in that case i advice removing the image, you can even put all items inside and array and use and conditional to show it only if array.length <= 6, something like



.TS



public menu: any = [{img: "url", text: "menu text"}, ...];


HTML



<ion-card *ngFor="let item of menu">
<img [src]="item.img" *ngIf="menu.length <= 6"/>
<div class="card-title">{{item.text}}</div>
</ion-card>


So this what i've came up with, sorry for the delay and hope this helps :D






share|improve this answer

















  • 1




    Hi, sorry for i late. it works perfectly. thank you so much
    – Veysel
    Nov 28 '18 at 16:50










  • Hi, it's ok, i'm glad i could help.
    – Gabriel Barreto
    Nov 28 '18 at 17:37











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416280%2fionic-how-to-fix-ion-content-to-fill-the-device-screen-size%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














So the problem is that it wasn't responsive enough and it can be tricky to get something responsive in an ionic 3 app, since in that page you have the ion-content wich has .scroll-content and .fixed-content inside, also the tab doesn't "push" the content up, ionic simply add an exact amount of margin to the content so it doesn't collide with the footer.



So here is what i've done:



HTML:



<ion-content class="card-background-page">
<div class="buttons">
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</div>
</ion-content>


CSS:



page-home {
ion-content{
background: url('https://i.imgur.com/olLunTc.jpg')no-repeat fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}

.scroll-content {
overflow-y: hidden;
}
.card-background-page {
.buttons {
display: grid;
grid-template: repeat(3, 1fr) / repeat(2, 1fr);
height: calc(100vh - 55px); // i've added this number of pxls, but you can inspect and get the exact amount of the tab footer
}
ion-card {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
background-color: transparent;

img {
width: 80%;
}
.card-title {
font-size: 2rem;
width: 100%;
color: #fff;
font-family: auto;
}
}
}
}


So first i removed the ionic grid from your code and instead used CSS grid to do the job. Ionic grid is good, it does a great job as a responsive grid, but you can't control it enough, so for this CSS grid is better.



I created an div with class buttons to hold the "menu", it has a calculated height so it can fit the whole content removing the tab height. This alone'll make your content stretch only to that area.



So with this the cards will respect the rows and columns of the CSS grid, now the job is making the image and text responsive and that's easy using % for the image and rem for the text.



I've asked about the amount of items in that menu because it'll look strange if it's more than 6 items, you'll need to modify the number of rows in the first argument of grid-templates. So 8 or more items will make the image smaller and depending of what you want to show it'll not be good, in that case i advice removing the image, you can even put all items inside and array and use and conditional to show it only if array.length <= 6, something like



.TS



public menu: any = [{img: "url", text: "menu text"}, ...];


HTML



<ion-card *ngFor="let item of menu">
<img [src]="item.img" *ngIf="menu.length <= 6"/>
<div class="card-title">{{item.text}}</div>
</ion-card>


So this what i've came up with, sorry for the delay and hope this helps :D






share|improve this answer

















  • 1




    Hi, sorry for i late. it works perfectly. thank you so much
    – Veysel
    Nov 28 '18 at 16:50










  • Hi, it's ok, i'm glad i could help.
    – Gabriel Barreto
    Nov 28 '18 at 17:37
















1














So the problem is that it wasn't responsive enough and it can be tricky to get something responsive in an ionic 3 app, since in that page you have the ion-content wich has .scroll-content and .fixed-content inside, also the tab doesn't "push" the content up, ionic simply add an exact amount of margin to the content so it doesn't collide with the footer.



So here is what i've done:



HTML:



<ion-content class="card-background-page">
<div class="buttons">
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</div>
</ion-content>


CSS:



page-home {
ion-content{
background: url('https://i.imgur.com/olLunTc.jpg')no-repeat fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}

.scroll-content {
overflow-y: hidden;
}
.card-background-page {
.buttons {
display: grid;
grid-template: repeat(3, 1fr) / repeat(2, 1fr);
height: calc(100vh - 55px); // i've added this number of pxls, but you can inspect and get the exact amount of the tab footer
}
ion-card {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
background-color: transparent;

img {
width: 80%;
}
.card-title {
font-size: 2rem;
width: 100%;
color: #fff;
font-family: auto;
}
}
}
}


So first i removed the ionic grid from your code and instead used CSS grid to do the job. Ionic grid is good, it does a great job as a responsive grid, but you can't control it enough, so for this CSS grid is better.



I created an div with class buttons to hold the "menu", it has a calculated height so it can fit the whole content removing the tab height. This alone'll make your content stretch only to that area.



So with this the cards will respect the rows and columns of the CSS grid, now the job is making the image and text responsive and that's easy using % for the image and rem for the text.



I've asked about the amount of items in that menu because it'll look strange if it's more than 6 items, you'll need to modify the number of rows in the first argument of grid-templates. So 8 or more items will make the image smaller and depending of what you want to show it'll not be good, in that case i advice removing the image, you can even put all items inside and array and use and conditional to show it only if array.length <= 6, something like



.TS



public menu: any = [{img: "url", text: "menu text"}, ...];


HTML



<ion-card *ngFor="let item of menu">
<img [src]="item.img" *ngIf="menu.length <= 6"/>
<div class="card-title">{{item.text}}</div>
</ion-card>


So this what i've came up with, sorry for the delay and hope this helps :D






share|improve this answer

















  • 1




    Hi, sorry for i late. it works perfectly. thank you so much
    – Veysel
    Nov 28 '18 at 16:50










  • Hi, it's ok, i'm glad i could help.
    – Gabriel Barreto
    Nov 28 '18 at 17:37














1












1








1






So the problem is that it wasn't responsive enough and it can be tricky to get something responsive in an ionic 3 app, since in that page you have the ion-content wich has .scroll-content and .fixed-content inside, also the tab doesn't "push" the content up, ionic simply add an exact amount of margin to the content so it doesn't collide with the footer.



So here is what i've done:



HTML:



<ion-content class="card-background-page">
<div class="buttons">
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</div>
</ion-content>


CSS:



page-home {
ion-content{
background: url('https://i.imgur.com/olLunTc.jpg')no-repeat fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}

.scroll-content {
overflow-y: hidden;
}
.card-background-page {
.buttons {
display: grid;
grid-template: repeat(3, 1fr) / repeat(2, 1fr);
height: calc(100vh - 55px); // i've added this number of pxls, but you can inspect and get the exact amount of the tab footer
}
ion-card {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
background-color: transparent;

img {
width: 80%;
}
.card-title {
font-size: 2rem;
width: 100%;
color: #fff;
font-family: auto;
}
}
}
}


So first i removed the ionic grid from your code and instead used CSS grid to do the job. Ionic grid is good, it does a great job as a responsive grid, but you can't control it enough, so for this CSS grid is better.



I created an div with class buttons to hold the "menu", it has a calculated height so it can fit the whole content removing the tab height. This alone'll make your content stretch only to that area.



So with this the cards will respect the rows and columns of the CSS grid, now the job is making the image and text responsive and that's easy using % for the image and rem for the text.



I've asked about the amount of items in that menu because it'll look strange if it's more than 6 items, you'll need to modify the number of rows in the first argument of grid-templates. So 8 or more items will make the image smaller and depending of what you want to show it'll not be good, in that case i advice removing the image, you can even put all items inside and array and use and conditional to show it only if array.length <= 6, something like



.TS



public menu: any = [{img: "url", text: "menu text"}, ...];


HTML



<ion-card *ngFor="let item of menu">
<img [src]="item.img" *ngIf="menu.length <= 6"/>
<div class="card-title">{{item.text}}</div>
</ion-card>


So this what i've came up with, sorry for the delay and hope this helps :D






share|improve this answer












So the problem is that it wasn't responsive enough and it can be tricky to get something responsive in an ionic 3 app, since in that page you have the ion-content wich has .scroll-content and .fixed-content inside, also the tab doesn't "push" the content up, ionic simply add an exact amount of margin to the content so it doesn't collide with the footer.



So here is what i've done:



HTML:



<ion-content class="card-background-page">
<div class="buttons">
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
<ion-card>
<img src="https://i.imgur.com/YpXomyN.png"/>
<div class="card-title">Lorem Ipsum</div>
</ion-card>
</div>
</ion-content>


CSS:



page-home {
ion-content{
background: url('https://i.imgur.com/olLunTc.jpg')no-repeat fixed;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}

.scroll-content {
overflow-y: hidden;
}
.card-background-page {
.buttons {
display: grid;
grid-template: repeat(3, 1fr) / repeat(2, 1fr);
height: calc(100vh - 55px); // i've added this number of pxls, but you can inspect and get the exact amount of the tab footer
}
ion-card {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
background-color: transparent;

img {
width: 80%;
}
.card-title {
font-size: 2rem;
width: 100%;
color: #fff;
font-family: auto;
}
}
}
}


So first i removed the ionic grid from your code and instead used CSS grid to do the job. Ionic grid is good, it does a great job as a responsive grid, but you can't control it enough, so for this CSS grid is better.



I created an div with class buttons to hold the "menu", it has a calculated height so it can fit the whole content removing the tab height. This alone'll make your content stretch only to that area.



So with this the cards will respect the rows and columns of the CSS grid, now the job is making the image and text responsive and that's easy using % for the image and rem for the text.



I've asked about the amount of items in that menu because it'll look strange if it's more than 6 items, you'll need to modify the number of rows in the first argument of grid-templates. So 8 or more items will make the image smaller and depending of what you want to show it'll not be good, in that case i advice removing the image, you can even put all items inside and array and use and conditional to show it only if array.length <= 6, something like



.TS



public menu: any = [{img: "url", text: "menu text"}, ...];


HTML



<ion-card *ngFor="let item of menu">
<img [src]="item.img" *ngIf="menu.length <= 6"/>
<div class="card-title">{{item.text}}</div>
</ion-card>


So this what i've came up with, sorry for the delay and hope this helps :D







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 11:17









Gabriel BarretoGabriel Barreto

4,86911137




4,86911137








  • 1




    Hi, sorry for i late. it works perfectly. thank you so much
    – Veysel
    Nov 28 '18 at 16:50










  • Hi, it's ok, i'm glad i could help.
    – Gabriel Barreto
    Nov 28 '18 at 17:37














  • 1




    Hi, sorry for i late. it works perfectly. thank you so much
    – Veysel
    Nov 28 '18 at 16:50










  • Hi, it's ok, i'm glad i could help.
    – Gabriel Barreto
    Nov 28 '18 at 17:37








1




1




Hi, sorry for i late. it works perfectly. thank you so much
– Veysel
Nov 28 '18 at 16:50




Hi, sorry for i late. it works perfectly. thank you so much
– Veysel
Nov 28 '18 at 16:50












Hi, it's ok, i'm glad i could help.
– Gabriel Barreto
Nov 28 '18 at 17:37




Hi, it's ok, i'm glad i could help.
– Gabriel Barreto
Nov 28 '18 at 17:37


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416280%2fionic-how-to-fix-ion-content-to-fill-the-device-screen-size%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Feedback on college project

Futebolista

Albești (Vaslui)