Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a div whose size is relative to a fixed width div and containing area?

Tags:

html

css

I have a containing div (contentBody) that is N% wide. Within that div I have two other divs, contentLeft and contentRight.

contentLeft is always 205px. I want contentRight to automatically fill the remaining space in contentBody. How can I achieve this?

#div contentLeft{
  width:205px;
  float:left;
}

#div contentRight{
  width:<**100% - 205px**>;
  float:left;
}

Edit: Sorry, I meant to write "N%" instead of 100%, this needs to work for a containing area of any percentage or size.

like image 573
djdd87 Avatar asked Dec 14 '22 03:12

djdd87


2 Answers

The following should do it:

#contentBody{
  width:N%
}
#div contentLeft{
  width:205px;
  float:left;
}

#div contentRight{
  margin-left:205px;
}
like image 174
wheresrhys Avatar answered Jan 19 '23 04:01

wheresrhys


the easiest thing to do is to position them both absolutely then set contentleft to the desired with and add margin-left equal to that same width - as follows:

#div contentLeft{
  position:absolute;
  top:0;
  left:0;
  width:205px;
}

#div contentRight{
  position:absolute;
  width:100%;
  top:0;
  left:0;
  margin-left:205px;
}
like image 43
Josh Avatar answered Jan 19 '23 04:01

Josh