Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Why a div with a small height (4px) cannot fit an element?The child element is displayed outside

I checked that it wasn't the width, I set the child element to be 10% wide and only one element

.pct-bar {
  height: 4px;
  background-color: rgba(121, 121,121,.3);

  .gogo {
display: inline-block;
// float: left; // If I set float, this problem will not occur
width: 10%;
height: 100%;
background-color: #fff;
  }
}
<div class="pct-bar">
  <span class="gogo"></span>
</div>

Gif: problem

The only way I've found so far is to set float to the child or display:flex to the parent, but hopefully that will answer the question. The text is translated by translator, if you have any questions, please feel free to ask, thank you

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

For inline-block element there's line height in the play. Effectively your .gogo element lies on the baseline of the .pct-bar container (which has some default line-height). You can fix your issue by adding vertical-align: top; to the .gogo element.

.pct-bar {
  height: 4px;
  background-color: rgba(121, 121,121,.3);
}
.gogo {
  display: inline-block;
  width: 10%;
  height: 100%;
  background-color: #f00;
  vertical-align: top;
}
<div class="pct-bar">
  <span class="gogo"></span>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

You could set min-height for .gogo

.gogo {
    ...
    min-height: 1px;
}

sorry, got you wrong.

maybe display: table; might be an option?

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!