1

I need two columns, one responsive, another fixed with 100px width

For example left columns have 100px width and right columns have the remaining width

In this simple code how much to put the width?

<!DOCTYPE html>
<html>
<head>
    <style>
        .main{
            display: table;
            clear: both;
            width: 100%;
        }
        #left{
            float: left;
            width: 100px;
        }
        #right{
            float: right;
            /*width: ;*/
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="main">
        <div id="left">
            left
        </div>
        <div id="right">
            right
        </div>
    </div>
</body>
</html>
Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
sadegh
  • 1,720
  • 1
  • 16
  • 30
  • 1
    this looks like it might help just swap the left for right and the 180 pixel to 100 pixels http://stackoverflow.com/questions/5195836/2-column-div-layout-right-column-with-fixed-width-left-fluid – john taylor Jul 23 '15 at 01:49

3 Answers3

2

Since you're already using display: table on the parent, set the children's display to table-cell and give a width to the first one like you did. The second column will automatically take the remaining width.

#left{
    display: table-cell;
    width: 100px;
}

#right{
    display: table-cell;
}

Example : https://jsbin.com/dicuvigaka/edit?html,output

Drown
  • 5,852
  • 1
  • 30
  • 49
1

You can use calc() to calculate the remaining width. Check the browser compatibility table: Can I use calc().

html,
body {
  margin: 0;
  padding: 0;
}
.main {
  width: 100%;
}
#left {
  float: left;
  width: 100px;
  background: lightblue;
}
#right {
  float: left;
  background-color: tomato;
  width: calc(100% - 100px);
}
<!DOCTYPE html>
<html>

<head>
  <style>
  </style>
</head>

<body>
  <div class="main">
    <div id="left">
      left
    </div>
    <div id="right">
      right
    </div>
  </div>
</body>

</html>
m4n0
  • 29,823
  • 27
  • 76
  • 89
1

Try this:

#left {
    position: absolute;
    left: 0;
    width: 100px;
}

#right {
    position: absolute;
    left: 100px;
    width: 100%;
}
Kwarrtz
  • 2,693
  • 15
  • 24