While looking for a way to implement navbar drop down menu (similar to accordion) I came upon this youtube video which uses custom component and manipulating max-height of card-content element to achieve the desired effect.
HTML:
<ion-card>
<ion-card-title text-center color="primary" (click)="toggle()"></ion-card-title>
<ion-card-content #cc>
<p>Hello World!</p>
</ion-card-content>
</ion-card>
CSS:
.card-content{
max-height: 0px;
}
TS:
toggled = false;
#ViewChild("cc") cc: any;
toggle() {
if (this.toggled) {
this.renderer.setStyle(this.cc.nativeElement, "max-height", "0px");
} else {
this.renderer.setStyle(this.cc.nativeElement, "max-height", "500px");
}
this.toggled = !this.toggled;
}
All was working fine while following the video from start to finish.
However what I wanted was a drop down menu from navbar so I decided to edit part of his code to...
#cc{
max-height: 0px;
}
<ion-navbar text-center color="primary" (click)="toggle()"></ion-navbar>
<div #cc id="cc">
<p>Hello World!</p>
</div>
But it is not working as expected. When div is (0px) i can still see the elements that it contains, in this case it's "Hello World!"
Am I doing something wrong here, or does it only work specifically with ion-cards?
Just add overflow: hidden; to the parent:
#cc{
max-height: 0px;
overflow: hidden;
}
<ion-navbar text-center color="primary" (click)="toggle()"></ion-navbar>
<div #cc id="cc">
<p>Hello World!</p>
</div>
use overflow: hidden;
#cc{
max-height: 0px;
overflow: hidden;
}
<ion-navbar text-center color="primary" (click)="toggle()"></ion-navbar>
<div #cc id="cc">
<p>Hello World!</p>
</div>
Related
My css code for navigation drawer
:host{
display: flex;
background-color: #f0fff0;
flex-grow:1;
}
.body-style{
padding: 20px;
min-height: 100px;
flex-grow: 1;
}
HTML:
<mat-drawer-container >
<mat-drawer #drawer [mode]="over">I'm a drawer</mat-drawer>
<mat-drawer-content>
<button mat-raised-button (click)="drawer.toggle()">Toggle drawer</button>
<div class="body-style">
<router-outlet>
</router-outlet>
</div>
</mat-drawer-content>
</mat-drawer-container>
I am obviously missing something in Flexbox concepts. The <mat-drawer-content>'s width is small.
Don't reinvent the wheel.
Angular team has already covered your need with Flex-Layout.
Once installed, it gives this :
<mat-drawer-container >
<mat-drawer #drawer [mode]="over">I'm a drawer</mat-drawer>
<mat-drawer-content fxLayout="row" fxLayoutAlign="start center">
<button mat-raised-button (click)="drawer.toggle()">Toggle drawer</button>
<div class="body-style">
<router-outlet></router-outlet>
</div>
</mat-drawer-content>
</mat-drawer-container>
No CSS required.
<div class="panel panel-line panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Meb Katmanları</h3>
<div class="panel-actions">
<mat-slide-toggle color="warn" [(ngModel)]="allMebLayers" (change)="mebToggle()"></mat-slide-toggle>
</div>
</div>
<div *ngIf="allMebLayers" class="panel-body" style="max-height: 70vh; overflow-y: auto">
<mat-selection-list *ngFor="let l of legends" style="overflow-y: hidden; overflow-x: hidden;">
<mat-checkbox>
<td class="p-5">{{l.layerName}}</td>
<td class="p-5"><img [src]="l.legend.imageData"></td>
</mat-checkbox>
</mat-selection-list>
</div>
</div>
I want to just style the image inside the checkbox. Any simple way without adding new class name ?
To style the image inside the checkbox WITHOUT a new class name, try this selector in your css document:
mat-checkbox img {
/* desired CSS properties */
}
To accomplish the styling, you could also use:
.p-5 img { ... }
If you want to only target that image for that class and not all of the mat-checkbox img elements that could also be on the same page.
I have an angular material 2 date-picker implemented in a bootstrap modal form:
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">{{title}}</h4>
</div>
<div class="modal-body">
<div class="timeline-cal">
<input class="date-field" [mdDatepicker]="picker" placeholder="Choose a date">
<md-datepicker-toggle mdSuffix [for]="picker"></md-datepicker-toggle>
<md-datepicker #picker></md-datepicker>
</div>
<div class="modal-footer">
<button type="button" class="btn grey-btn pull-right" (click)="cancel()">Cancel</button>
</div>
</div>
</div>
However, upon clicking the button, the datepicker wouldn't open in the modal dialog itself but opens in the background. I tried this but didn't help:
.mat-datepicker-content{ z-index: 1200}
try,
::ng-deep .cdk-overlay-container {
z-index: 1200 !important;
}
Or this
/deep/ .cdk-overlay-container {
z-index: 1200 !important;
}
For me this worked:
::ng-deep .cdk-overlay-container {
position: fixed !important;
z-index: 100000 !important; /* set value you need */
}
You have to specify certain position for z-index.
Note: z-index only works on positioned elements (position:absolute,
position:relative, or position:fixed).
CSS z-index # W3Schools
Add this code in the component html file :
<style>
::ng-deep .cdk-overlay-container {
z-index: 2000;
</style>
Hope fully this will resolve the issue !!!
In a view with header and subheader, subheader content overlaps the contents of the view.
Header in slide menu
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left" ng-hide="$exposeAside.active"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
Subheader in a view
<ion-header-bar align-title="center" class="bar bar-subheader custom bar-energized" ng-if="datos.subTitulo">
<div class="buttons">
<a class="ion-chevron-left" href="#/app/ranking/ubicacion/{{datos.divAnt}}" ng-if="datos.divAnt"></a>
</div>
<h2 class="subtitle">{{datos.subTitulo}}</h2>
<div class="buttons">
<a class="ion-chevron-right" href="#/app/ranking/ubicacion/{{datos.divSig}}" ng-if="datos.divSig"></a>
</div>
</ion-header-bar>
Div buttons in subheader overlapping content, h2 show 100%.
Something is missing in this code? Thanks
[EDIT]
Rewrote the code to suit my needs: subheader smaller than the header with two links in the corners and a title.
<ion-header-bar align-title="center" class="bar-subheader subheader_custom bar-energized">
<div class="button button-clear">
<a class="icon ion-ios-arrow-back blanco" href="#/app/ranking/ubicacion/{{datos.divAnt}}" ng-if="datos.divAnt"></a>
</div>
<div class="h2 title title_custom">{{datos.subTitulo}}</div>
<div class="button button-clear">
<a class="icon ion-ios-arrow-forward blanco" href="#/app/ranking/ubicacion/{{datos.divSig}}" ng-if="datos.divSig"></a>
</div>
</ion-header-bar>
Add this css:
.has-subheader {
top: 70px;
}
.bar-subheader.subheader_custom {
display: block;
height: 26px;
top: 44px;
}
.title.title_custom {
font-size: 16px;
font-weight: 300;
height: 20px;
left: 0;
line-height: 20px;
margin: 2px 10px 2px 10px;
min-width: 24px;
overflow: hidden;
position: absolute;
right: 0;
text-align: center;
text-overflow: ellipsis;
top: 0;
white-space: nowrap;
z-index: 0;
}
Even buttons are not in line with the subheader title. Any ideas?
New status:
Make sure that the content view knows it needs to leave space for the subheaders by adding the CSS class has-subheader:
<ion-content class="has-header has-subheader">
</ion-content>
See http://ionicframework.com/docs/components/#subheader
If you face this issue in Android, then use the following
.platform-android .bar-subheader {
top: 93px;
}
https://forum.ionicframework.com/t/sub-header-not-showing-on-android-with-tabs/15341/18
You can easily change the height of the subheader, footer, and subfooter if you are using SASS with Ionic. If you want a 70px tall subheader simply add $bar-subheader-height: 70px; to your ionic.app.scss file. Your scss file should look something similar to:
// The path for our ionicons font files, relative to the built CSS in www/css
$ionicons-font-path: "../lib/ionic/fonts" !default;
$bar-subheader-height: 70px;
// Include all of Ionic
#import "www/lib/ionic/scss/ionic";
Check out the www/lib/ionic/scss/_variables.scss file for some of the other things you can change easily.
Here are instructions for setting up sass with ionic and here is a quick tutorial.
You can add has-header or has-subheader class to your main content in ion-content directive.
Here's my code:
<ion-view view-title="View Title">
<ion-content>
<div class="bar bar-header">
<h2 class="title">Sub Header</h2>
</div>
<div class="list has-header">
<a class="item item-icon-left" href="#">
<i class="icon ion-email"></i>
Check mail
</a>
<a class="item item-icon-left item-icon-right" href="#">
<i class="icon ion-chatbubble-working"></i>
Call Ma
<i class="icon ion-ios-telephone-outline"></i>
</a>
</div>
</ion-content>
</ion-view>
<div class="list has-header"> I add the has-header class to my list to avoid subheader overlapping
I have been trying making ion-tabs fixed inside ion-content but it hardly seems posssible. So is there any way of making tabs fixed inside a scollable content in ionic?
$( "ion-content" ).scroll(function() {
var scrollWidth = $(".main-content").height()-$(".header-bar").height();
if (parseInt($(this).scrollTop()) > scrollWidth ) {
$("#fixedAboutTabs").addClass("fixed");
});
}
else {
$("#fixedAboutTabs").removeClass("fixed");
});
.fixed{
left: 0;
top:44px;
position: fixed;
z-index:100;
width: 100%;
}
<ion-view>
<div class="header-bar">
<button class="button button-clear arrow-btn" ng-click="goBack()"> <img src="img/arrow.png" class="arrow-img"> </button>
<h1 class="title">{{product.productName}}</h1>
</div>
<ion-content on-scroll="onScroll()" overflow-scroll="true" has-bouncing="false">
<div class="main-content">
<img src="img/video.png" class="video-img">
<div class="product-info">
//some content here
</div> <!--product info closes -->
</div> <!--main content closes-->
<div id="staticAboutTabs" class="demo-tabs">
<ul>
//customized tabs (want to make this tabs fixed bewlow header-bar)
</ul>
</div>
</ion-content>
</ion-view>
Instead of ion-tabs i have used my own customized tabs. let me know if the ion-tabs or any custom made tabs can be fixed inside scrollable ion-content
Try this by placing the to-be-fixed content inside <div slot="fixed"> </div>
<ion-content>
<div slot="fixed">
<ion-tabs #tabs tabsPlacement="top">
<ion-tab-bar slot="top" tabsHighlight="true">
<ion-tab-button tab="tab1">
<ion-label>Tab1</ion-label>
</ion-tab-button>
<ion-tab-button tab="tab2">
<ion-label>Tab2</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
</div>
</ion-content>