1

I have two divs in my application. How can I make my left div to fit all space till right div. Right one can be text or image with any width.

<div id="header" class="header">
    <div class="logo">
        <img src="/Content/images/my_logo.png" alt="" />
    </div>
    <div class="logoClient">
        Test Client /*here can be text or image with ANY SIZE */
    </div>
    <div class="clear"></div>
</div>

In this example I've done with fixed widths(700px and 200px), but this is wrong, because right one's text is dynamic and I want to left green bar be dynamic too.

http://jsfiddle.net/C5GL6/1/

Another approach with table, table-cell css options... but again... can't make left green bar fit all space.

http://jsfiddle.net/sjfQj/

How can I achieve this?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Gab
  • 471
  • 3
  • 10
  • 25
  • Are you looking for [this](http://stackoverflow.com/questions/16529291/div-to-take-up-entire-remaining-width/16529353#16529353)? someone recently downvoted that answer of mine for no good reason – Mr. Alien Jan 16 '14 at 11:23
  • 1
    Remove `width` from both div's – Anup Jan 16 '14 at 11:28
  • @Mr.Alien, no, in your example left div has fixed width... I don't want both left and right divs to have fixed width... :) – Gab Jan 16 '14 at 11:39
  • @Anup, you really think that I haven't tried such ways? – Gab Jan 16 '14 at 11:39

2 Answers2

0

Remove the width size in div

Edited fiddle http://jsfiddle.net/C5GL6/2/

 .logo {
float: left;
height: 55px;
padding: 10px 20px;
background: #004B35;

}
BNL
  • 7,085
  • 4
  • 27
  • 32
neel
  • 5,123
  • 12
  • 47
  • 67
0

Remove width and add float:left to both the divs

    .header 
{
    width: 950px;
    font-family:Helvetica, Arial, sans-serif;
    display:table
}

.logo {
    height: 55px;
    padding: 10px 20px;
    background: #004B35;
    display:table-cell;
}

 .logoClient 
 {
   display:table-cell;
    height: 55px;
    line-height: 55px;
    padding: 10px 0px;
    margin:0px -10px 0px 0px;
    font-size: 30px;
    color: #004B35;
    overflow:hidden;
    font-weight: bold;
    text-align: right;
    background: red;
}

DEMO Updated

Sowmya
  • 26,684
  • 21
  • 96
  • 136
  • http://jsbin.com/ORetUbu/4 Small text is not apperaing in the right part and left part is not fitting all remaining space. – Gab Jan 16 '14 at 11:49
  • 1
    Use `display:table` and `table-cell`. here is the demo http://jsbin.com/ORetUbu/6/ – Sowmya Jan 16 '14 at 11:52
  • This is going to be good way... But anyway I need just opposite(the red part must be with the size of text(size of "Test Client" or whatever text they will be) and black part must fit remaining space)... – Gab Jan 16 '14 at 11:59