Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...