gpt4 book ai didi

javascript - 如何避免 Angular 中的元素重叠

转载 作者:太空狗 更新时间:2023-10-29 18:00:09 25 4
gpt4 key购买 nike

我的应用是基于 Angular 的,我用表格行动态填充页面。页面下方有一个app-console,这个元素的位置好像是固定的。当我单击按钮添加新行时,新行与应用程序控制台重叠。如何避免这种情况。

下面是图片和代码片段。

enter image description here

**app.component.html**
<div>
<button style="width:100px;" class="btn" (click)="addProduct()" >Add
Product</button>
.... other elements needed for table row ....
</div>
<br>
<app-console [consoleMessages]="consoleMessages"></app-console>

**app.component.ts**


addProduct () {
let product = JSON.parse(JSON.stringify(this.productTemplate));
this.record['products'].push(product);//dynamically adds table row
}

Angular支持动态添加元素,如何避免元素重叠?

关于这个问题的更新:

console.component.html

<mat-tab-group class="console">
<mat-tab class="tab" label="Console">
<pre style="height:200px;"><code [innerHtml]="htmlCode"></code></pre>
</mat-tab>
</mat-tab-group>

console.component.ts

import { Component, OnInit, Input } from '@angular/core';
import { highlightAuto } from 'highlight.js';
@Component({
selector: 'app-console',
templateUrl: './console.component.html',
styleUrls: ['./console.component.css']
})
export class ConsoleComponent implements OnInit {

@Input() consoleMessages = '';
consoleHtmlMessages = '';

constructor() { }

ngOnInit() {
}


get htmlCode() {
return highlightAuto(this.consoleMessages, ['html']).value;
}

}

最佳答案

/* reset the html and body */
html, body {
height: 100%;
padding: 0;
margin: 0;
}

.container {
display: flex;
height: 100%;
flex-direction: column;
justify-content: space-between;
}

.list, .console {
box-sizing: border-box;
padding: 0 1em;
/* this scroll will keep both areas always visible */
overflow: auto;
}

.list {
background: #ccedff;
flex-grow: 1;
}

.console {
background: #eeefef;
/* define a minumum size to your console */
min-height: 200px;
}
<div class="container">
<div class="list">
<!--- // your list component... -->
</div>
<div class="console">
<!--- // your console component... -->
</div>
</div>

Obs: the snippet seems not to render correctly here, so you can see a live example below.

Live example

关于javascript - 如何避免 Angular 中的元素重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58076213/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com