css - 如何从同一模式内的选择下拉列表中选择选项时设置模式的边距

标签 css angular typescript

当在模态中选择选项时,如何将边距顶部调整为模态内容,当人选择模态的边距顶部应为 260px,如果公司选择其应为 300px

指南.html

<div bsModal #addGuide="bs-modal" class="modal fade guide" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-md">
    <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">Header</h4>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>Guide Type</label>
            <ng-select [options]="guide" [(ngModel)]="addGuide.value" name="Guide" class='filterDropDown' placeholder="Guide Type" notFoundMsg="No Category Found">
            </ng-select>
          </div> 
          <div class="form-group" *ngIf="addGuide.value == 'person'">
            <md-input-container>
              <input type="text" mdInput name="Name" placeholder="Person Name" [(ngModel)]="addName">
            </md-input-container>
            <md-input-container>
              <input type="text" mdInput name="DOB" placeholder="Person DOB" [(ngModel)]="addDob">
            </md-input-container>
          </div> 
          <div class="form-group" *ngIf="addGuide.value == 'company'">
            <md-input-container>
              <input type="text" mdInput name="AddCompName" placeholder="Company Name" [(ngModel)]="addCompName">
            </md-input-container>
            <md-input-container>
              <input type="text" mdInput name="Add Company Description" placeholder="Company Description" [(ngModel)]="addCompDescription">
            </md-input-container>
          </div>           
        </div>
        <div class="modal-footer">
          Footer
        </div>
      </form>
    </div>
  </div>
</div>

guide.component.ts

import { Component } from '@angular/core';
import { ModalDirective } from 'ng2-bootstrap';

@Component({
  templateUrl: './guide.html'
})
export class GuideComponent{
	constructor() {}
	guide:any = [{ label: 'person', value:'person'}, {label: 'company', value:'company'}];
}

样式.css

.pin .modal-content {
  margin-top: 260px;
}

最佳答案

您可以使用ngStyle来做到这一点

<div [style.margin-top.px] = "addGuide.value == 'person' ? '260' : '300'"></<div> 

您还可以添加条件类并添加重要的 css

last of your css page

<div class="modal-content" [ngClass]="{'margin260': addGuide.value =='person','margin300': addGuide.value == 'company'}"> 
.pin .modal-content.margin260{
    margin-top: 260px !important;
}
.pin .modal-content.margin300{
    margin-top: 300px !important;
}

关于css - 如何从同一模式内的选择下拉列表中选择选项时设置模式的边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47589763/

相关文章:

javascript - ( Angular 6)子函数是否应该返回它正在操作的对象?

typescript - linter 错误静态方法 lodash typescript

html - 包装器内的内部 div 容器居中问题

html - 无法使 css 表格边框在整个表格和嵌套表格中保持一致

css - 检查变量是否包含在 SCSS 的单词列表中

angular - Angular辅助路由懒加载时报错: Cannot match any routes.

css - 附加到中间 div 的左右 div

angular - 访问 ViewChildren 查询列表的第 n 个子项( Angular )

angular - 引用错误 : "__decorate is not defined" when passing input to an angular directive

reactjs - 尝试使用 create-react-app 运行 typescript