Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parent element with only child has height even if the only child had all paddings, margins, height and width set to zero

Tags:

html

css

I encountered a problem: Parent element with only child has height even if the only child had all paddings, margins, borders, outline, height and width set to zero, however when I set display to none it suddenly works.

Why is this happening? What have I forgotten? How can I reach the point when parrent element will have height of zero without altering the height of parent element?

Here is quick snippet I've made.

* { box-sizing: border-box; }

div{
  border: 3px red solid;
  margin: 0;
  padding: 0;
}

input{
  display: inline-block;
  height: 0;
  width: 0;
  padding: 0;
  margin: 0;
  outline: none;
  border: none;
}
<div><input type="text"></div>

Thanks.

Edit: I need input to be displayed as inline-block as well, is there any way to do that with display inline-block?

like image 931
DoeJane Avatar asked Jan 18 '26 11:01

DoeJane


1 Answers

Set the divs line-height to 0

* {
  box-sizing: border-box;
}

div {
  border: 3px red solid;
  margin: 0;
  padding: 0;
  line-height: 0;
}

input {
  display: inline-block;
  height: 0;
  width: 0;
  padding: 0;
  margin: 0;
  outline: none;
  border: none;
}
<div><input type="text"></div>
like image 89
Paulie_D Avatar answered Jan 21 '26 04:01

Paulie_D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!