How can I make the left div expand while the right div has a constant width?


annoying

So, as the title says, I want to place two divs next to each other, and if the window is expanded, make the left div expand while the right div maintains a constant width.

This is what I got so far:

<body>
    <div id="content" style="background-color: red">
        <div id="left" style="margin-right: 100px; background-color: blue">
            This</br>is</br>left.
        </div>
        <div id="right" style="float: right; width: 100px; height: 100px; background-color: green">
            This</br>is</br>right.
        </div>
        <div style="clear:both"></div>
    </div>
</bod>

produces the following results:

It's very sad if you can't see this :(

Ideally, the tops of the green and blue squares should line up with each other. One solution I've found is to set a negative margin-top setting on the green div, which works... but only if the blue div's height never changes. Unfortunately in my case the blue div can actually change height.

Any ideas on how to fix this? I'm having some trouble understanding the intricacies of CSS positioning :(

Brandon wins

If it works position:absolute, you can do the following:

<div class="left">This is the left box.</div>
<div class="right">This is the right box.</div>

and CSS:

.left {
  position: absolute;
  left: 0px;
  right: 100px;
}

.right {
  position: absolute;
  right: 0px;
  width: 100px;
}

http://jsfiddle.net/Q2TKU/

Related


Left div has fixed width and right div has fluid width

ChaniLastnamé I have a situation where I can't change the HTML and have to do everything with CSS. ****In the image below, you can see that the input box has text on both sides. I need to put all text on the left. The span containing the text has a fixed width

Left div has fixed width and right div has fluid width

ChaniLastnamé I have a situation where I can't change the HTML and have to do everything with CSS. ****In the image below, you can see that the input box has text on both sides. I need to put all text on the left. The span containing the text has a fixed width

How to make div container width increase from left to right

Sarah I have a container that holds some buttons in the top right corner of the page. I have set its position to fixed and given it the specific width and height I want. The problem is when the text on the button increases, it leaves the page. I can set overfl

How can I make the div go to the right?

User 12655615 I have an image in a div and I want it to go to the right. Right now it just keeps sticking to the left, overlapping another image in the div. Any idea how to do this? Himanshu Singh You can use text-align: rightalign the image to the right. .myD

How to make a div expand 100% width responsively?

main I have two divs (left, right). For some pages/requests, the content in the left div will be empty; I want to hide the left div for such requests. I want the right div to fill the entire page when the left div is hidden/removed. For this I am using table-c

How to make a wrapped div expand to full width

Hank I have the following UI: When I make the window thinner, the wrapping of the div can fit like this: What I would like to see is that when it does wrap, the div expands to 100% of its available width. The actual "div.row" is 100% width in the browser, so t

How to make a div expand 100% width responsively?

main I have two divs (left, right). For some pages/requests, the content in the left div will be empty; I want to hide the left div for such requests. I want the right div to fill the entire page when the left div is hidden/removed. For this I am using table-c

How to make a wrapped div expand to full width

Hank I have the following UI: When I make the window thinner, the wrapping of the div can fit like this: What I would like to see is that when it does wrap, the div expands to 100% of its available width. The actual "div.row" is 100% width in the browser, so t

How to make a wrapped div expand to full width

Hank I have the following UI: When I make the window thinner, the wrapping of the div can fit like this: What I would like to see is that when it does wrap, the div expands to 100% of its available width. The actual "div.row" is 100% width in the browser, so t