简体   繁体   English

尽管我们使用显示 css 属性,但如何使用 [hidden] 属性隐藏 DOM 元素?

[英]How can I hide DOM element using [hidden] property although we use display css property?

 public hide(){ this.show =.this;show; }
 .h1{ display: flex; }
 <button (click)="hide()">Hide/Show</button> <h1 class="h1" [hidden]="!show"> Hide me! </h1>

Here is the Problem.这是问题所在。 I have set a function for hide the DOM element.我设置了一个 function 来隐藏 DOM 元素。 So If I click the button text will be hide.所以如果我点击按钮文本将被隐藏。 Its OK.没关系。 but problem is I want to use display: flex;但问题是我想使用display: flex; if I use this CSS property hide is not working.如果我使用这个 CSS 属性隐藏不起作用。 If I remove display css property definitely text will be hide如果我删除display css 属性肯定会隐藏文本

  1. I want to hide the text using [hidden]=""我想使用[hidden]=""隐藏文本
  2. I want to use display:flex我想使用display:flex

using this both how can I hide the text, Have a any way to do this?使用这两个我如何隐藏文本,有什么办法吗? If not why?如果不是为什么?

In your css:在您的 css 中:

h1 {
  display: flex;
}

h1[hidden] {
  display: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM