Css 使用模态和样式的Ionic 2登录弹出窗口

Css 使用模态和样式的Ionic 2登录弹出窗口,css,ionic-framework,ionic2,Css,Ionic Framework,Ionic2,我有一个projet,我想在其中使用这种类型的登录: 我已经正确地设置了一个模式,我可以毫无问题地忽略它,但我的问题是它占用了整个页面,我只希望它与图片中的一样 我不知道如何选择css文件中的所有页面,已经用*尝试过了,但它与html文件中的内容太多了 提前谢谢你 编辑: 打开模式的页面上的代码: showLogin() { let modal = this.modalCtrl.create(LoginPage); // this.navCtrl.push(modal); modal.pre

我有一个projet,我想在其中使用这种类型的登录:

我已经正确地设置了一个模式,我可以毫无问题地忽略它,但我的问题是它占用了整个页面,我只希望它与图片中的一样

我不知道如何选择css文件中的所有页面,已经用*尝试过了,但它与html文件中的内容太多了

提前谢谢你

编辑:

打开模式的页面上的代码:

  showLogin() {
let modal = this.modalCtrl.create(LoginPage);
// this.navCtrl.push(modal);
modal.present();
}
模式代码: HTML:

TS:

我的错误可能是html和css之间的错误检查这个

它在ionic1中,但css是相同的


根据需要更改值

我最终得到了它,我没有选择正确的属性

以下是有效的方法:

page-login {
    .sample-modal-page {
        padding: 30px;
        background: rgba(0,0,0,0.5);
    }
}
感谢瓦伦·阿鲁鲁对我的帮助,以及他为出色的编辑所做的所有贡献

在这里,你还可以找到一篇很好的帖子,谈论如何很好地设计它: 我的解决方案:

import { Renderer } from '@angular/core';
import { ModalController, NavParams, ViewController } from 'ionic-angular';

@Component(...)
class HomePage {

  constructor(
    public modalCtrl: ModalController
  ) { }

  presentProfileModal() {
    let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
    profileModal.present();
  }

}

@Component(...)
class Profile {

  constructor(
    params: NavParams,
    public renderer: Renderer,
    public viewCtrl: ViewController
  ) {
    this.renderer.setElementClass(viewCtrl.pageRef().nativeElement, 'my-popup', true);
    console.log('UserId', params.get('userId'));
  }

}
将此添加到您的SCS:

ion-modal.my-popup {
  @media (min-width: 300px) and (min-height: 500px) {
    ion-backdrop {
      visibility: visible;
    }
  }

  .modal-wrapper {
    position: absolute;
    overflow: hidden;
    max-width: 280px;
    border-radius: 2px;
    width: 80vw;
    height: 50vh;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    border: 0;
    box-shadow: 0 16px 20px rgba(0,0,0,.4);
    background-color: #fafafa;
  }
}
或者这个css,它将提出动态高度:

ion-modal.my-popup {
  @media (min-height: 500px) {
    ion-backdrop {
      visibility: visible;
    }
  }

  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: $z-index-overlay;

  display: flex;

  align-items: center;
  justify-content: center;

  contain: strict;
  .modal-wrapper {
    &,
    .ion-page,
    .ion-page .content,
    .ion-page .content .scroll-content {
      contain: content;
      position: relative;
      top: auto;
      left: auto;
    }

    z-index: $z-index-overlay-wrapper;
    display: flex;
    overflow: hidden;

    flex-direction: column;

    min-width: $alert-min-width;
    max-height: $alert-max-height;

    opacity: 0;

    height: auto;
    max-width: $alert-md-max-width;
    border-radius: $alert-md-border-radius;
    background-color: $alert-md-background-color;
    box-shadow: $alert-md-box-shadow;

    .ion-page .content {
      background-color: color($colors, light);
    }
  }
}
我只是在调用时将一个类设置为modal元素并更改样式

模式实现源代码基于官方API
为了使模态显示在部分屏幕中,您必须删除离子内容标签并替换为div。这是因为离子在有两个离子内容标签时会混淆


在这种情况下,父模式中有一个,子模式中有一个。因此,最好将其从儿童模式中去掉。代码的其余部分保持不变

remove.modal wrapper和tryalready已尝试,不起作用,我需要一种方法来选择页面上的所有内容,或者使用像div这样的容器,但我不知道在ionicOverlay中使用哪一个,因为我没有在后台添加,我该怎么办?请建议您好,我的问题不是特别是写什么作为属性和样式,而是选择什么。谢谢,但是我们在哪里应用这个呢?我们使用这一个,但它只适用于内容,但我们想要完整的屏幕,感谢分享这一点,我有一个在模态列表,与此实现我不能滚动列表。有什么建议吗?@AlanAlbuquerque你可以试试
page-login {
    .sample-modal-page {
        padding: 30px;
        background: rgba(0,0,0,0.5);
    }
}
import { Renderer } from '@angular/core';
import { ModalController, NavParams, ViewController } from 'ionic-angular';

@Component(...)
class HomePage {

  constructor(
    public modalCtrl: ModalController
  ) { }

  presentProfileModal() {
    let profileModal = this.modalCtrl.create(Profile, { userId: 8675309 });
    profileModal.present();
  }

}

@Component(...)
class Profile {

  constructor(
    params: NavParams,
    public renderer: Renderer,
    public viewCtrl: ViewController
  ) {
    this.renderer.setElementClass(viewCtrl.pageRef().nativeElement, 'my-popup', true);
    console.log('UserId', params.get('userId'));
  }

}
ion-modal.my-popup {
  @media (min-width: 300px) and (min-height: 500px) {
    ion-backdrop {
      visibility: visible;
    }
  }

  .modal-wrapper {
    position: absolute;
    overflow: hidden;
    max-width: 280px;
    border-radius: 2px;
    width: 80vw;
    height: 50vh;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    border: 0;
    box-shadow: 0 16px 20px rgba(0,0,0,.4);
    background-color: #fafafa;
  }
}
ion-modal.my-popup {
  @media (min-height: 500px) {
    ion-backdrop {
      visibility: visible;
    }
  }

  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: $z-index-overlay;

  display: flex;

  align-items: center;
  justify-content: center;

  contain: strict;
  .modal-wrapper {
    &,
    .ion-page,
    .ion-page .content,
    .ion-page .content .scroll-content {
      contain: content;
      position: relative;
      top: auto;
      left: auto;
    }

    z-index: $z-index-overlay-wrapper;
    display: flex;
    overflow: hidden;

    flex-direction: column;

    min-width: $alert-min-width;
    max-height: $alert-max-height;

    opacity: 0;

    height: auto;
    max-width: $alert-md-max-width;
    border-radius: $alert-md-border-radius;
    background-color: $alert-md-background-color;
    box-shadow: $alert-md-box-shadow;

    .ion-page .content {
      background-color: color($colors, light);
    }
  }
}