Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed width div on left, fill remaining width div on right

I want a div with a fixed width image on the left and a variable width div with a background color, which should extend its width 100% on my device. I can't stop the second div from overflowing my fixed div.

When I add overflow:hidden at the variable width div it just jumps under the photo, on the next row.

How can I fix this the right way (i.e. without hacks or margin-left, since I need to make the site responsive later with media queries and I have to change the image with other resolution images for each device)?

  • beginner web designer trying to tackle the horror of responsive websites -

HTML:

<div class="header"></div> <div class="header-right"></div> 

CSS:

.header{     float:left;     background-image: url('img/header.png');     background-repeat: no-repeat;     width: 240px;     height: 100px;     }  .header-right{     float:left;      overflow:hidden;      background-color:#000;     width: 100%;     height: 100px;     } 
like image 506
Anamaria Miehs Avatar asked Oct 04 '12 10:10

Anamaria Miehs


People also ask

How do I make a div fill the remaining width?

The width property is used to fill a div remaining horizontal space using CSS. By setting the width to 100% it takes the whole width available of its parent. Example 1: This example use width property to fill the horizontal space. It set width to 100% to fill it completely.

How do I display the div content on the right side?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.


1 Answers

Try removing the float:left and width:100% from .header-right — the right div then behaves as requested.

.header {    float: left;    background: #efefef;    background-repeat: no-repeat;    width: 240px;    height: 100px;  }    .header-right {    overflow: hidden;     background-color: #000;    height: 100px;  }
<div class="header"></div>  <div class="header-right"></div>
like image 91
caitriona Avatar answered Sep 18 '22 12:09

caitriona