Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
351 views
in Technique[技术] by (71.8m points)

html - display table height not always respected

I have the code below. For some reason when the table height is smaller than the height of the cells, the height is not respected. Why is that?

.table {
        border: 1px solid red;
        box-sizing: border-box;
        display: table;
        height: 15px;
      }
      .cell {
        height: inherit;
        border-width: 0;
        display: table-cell;
      }
      .cell span {
        display: inline-block;
        width: 31px;
      }
    <body>
      <div class="table">
        <span class="cell">
          <span>test1</span>
        </span>
        <span class="cell">
          <span>test2</span>
        </span>
      </div>
    </body>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Table cell and table heights are only initial recommendations. The same thing to a degree happens with width. If the content of the words can't shrink any further in width the table will grow to fit.

Think of it as a min-height when used on table styled elements.

If you are wanting the content inside to have a maximum height you will want to set the height and overflow, etc. on the final child span inside.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...