0

I have two divs that I want to put side by side in a container. The problem I am having is that the left div has a veriable size depending on the content and the right div should use all available space.

<style>
div.left {
    display: inline-block;
    outline-width: 0;
    background-color: yellow;
    padding-right: 5px;
}

div.right{
    display: inline-block;
    max-width: 100%;
    outline-width: 0;
    background-color: green;
}

.container{
    background:black;    
    width:450px;
}
</style>

<div class="container">
    <div class="left">
        LEFT
    </div>
    <div class="right">
        RIGHT
    </div>
</div>

I tried with flex, table-cell, ... - almost everything. What am I missing?

Danilo Körber
  • 858
  • 1
  • 7
  • 27

1 Answers1

2

display: flex would do the job if you also assign flex:1 to the .right div, so it will take all the remaining space:

div.left {
    background: peachpuff;
    padding: 10px;
}

div.right{
    flex: 1;
    background-color: yellowgreen;
    padding: 10px;
}

.container{
    background:black; 
    display: flex;
    width:450px;
}
<div class="container">
    <div class="left">
        Variable content here
    </div>
    <div class="right">
        remaining space
    </div>
</div>
Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177