How do I make a div fill an entire table cell?

前端 未结 6 2269
日久生厌
日久生厌 2020-12-09 18:26

I\'m trying to fill the center cell of a table with a div element. For the purposes of illustrating the problem, the div is styled with a red background. It seems to work

6条回答
  •  爱一瞬间的悲伤
    2020-12-09 19:15

    Just set the table cell to: position:relative and the div to:

    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    

    Edit 2017: DEMO BELOW: (note how you cannot see the red td)

    #expandingDiv {
      position: absolute;
      height: 100%;
      width: 100%;
      top: 0;
      left: 0;
      background: yellow;
    }
    blue td green td
    yellow div
    Some longer text which makes the bottom two tds expand dynamically.

提交回复
热议问题