0

I have the following code. I don't understand why the p element is still visible when the height is 0%. Please explain, thanks!

p {
  height: 0%;
  overflow: hidden;
}
<p>I am Ozi</p>
Temani Afif
  • 211,628
  • 17
  • 234
  • 311
Ozichukwu
  • 326
  • 2
  • 9
  • 1
    Possible [answer](https://stackoverflow.com/a/1622097/2635367) "To set a percentage height, its parent element(*) must have an explicit height." The parent of p need a specific height. Also needs overflow hiidden. – Serafín Aug 01 '19 at 09:54
  • 1
    yes try line-height 0. its working..@Vikas Jadhav – Ranjith v Aug 01 '19 at 09:55
  • Use just `0` instead of `0%` – Bhuwan Aug 01 '19 at 09:57
  • @TemaniAfif I want you to know, as you've closed this question, I searched thoroughly and couldn't find the said duplicate question. The title is not self explanatory. That's why i asked this new one. – Ozichukwu Aug 01 '19 at 10:09
  • 1
    and that's why we are here to close question as duplicate, no one is blaming you for asking the question. – Temani Afif Aug 01 '19 at 10:11
  • @Serafin Your solution works! Thanks. – Ozichukwu Aug 01 '19 at 10:11

2 Answers2

1

Dont include percentage in height. Just specify 0 and it works.

p {
  height: 0;
  overflow: hidden;
}
<p>I am Ozi</p>
Allan Jebaraj
  • 1,052
  • 8
  • 23
1

SOLUTION:

p {
 display: block;
 line-height:0;
 height: 0px;
 overflow: hidden;
}
<p> hi </p>
<div>
Hi is not displayed
</div>
Naveen Kumar V
  • 2,223
  • 1
  • 23
  • 41