CSS Property Value How to - display: table; Make the middle column div always expand to fit








Question

We would like to know how to display: table; Make the middle column div always expand to fit.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#root {<!--   www  . jav  a  2s.  co m-->
  display: table;
  border-spacing: 0;
  width: 100%;
  height: 500px;
}

#root>div {
  display: table-cell;
}

#left {
  background: red;
  width: 25%;
}

#middle {
  background: green;
}

#right {
  background: blue;
  width: 100px;
}
</style>
</head>
<body>
  <div id="root">
    <div id="left">Left</div>
    <div id="middle">Middle</div>
    <div id="right">Right</div>
  </div>
</body>
</html>

The code above is rendered as follows: