views:

98

answers:

6

I have three divs:

<div class="A">A</div>
<div class="B">B</div>
<div class="C">C</div>

I want them to be positioned like this:

A     C
B

Where C should always be in the top right corner of the container they're in. How do I go about this in CSS using only the three divs and in that order?

I've tried a lot of different combinations of the float, display and clear properties to no avail.

A: 

Have you tried floating a,b to the left and c to the right? Also setting widths for your elements should help. Post some markup so we know what you have tried and how to fix it. very hard guessing these stuff.

Iznogood
+2  A: 

This should work... if not please post a screenshot of the issue you have.

Thanks!

EDIT

Initial response was flawed. I have amended to the below - there will be some browser restrictions but there are work-arounds to get the correct behaviour:

div {
    display:block;
    width:49%;
    float:left;   
    clear:left;
    }

div.C {
    display:inline-block;
    float:none;
    }
lnrbob
A: 

It would be simpler to rearrange them and have A float to the right: http://jsfiddle.net/78NnN/

Nikita Rybak
Unfortunately, I can't move the divs around. I don't have control over the HTML content.
Adam Lindberg
A: 
<html>
<body>
<style type="text/css">
.a {
    float:left;
}

.b {
    clear:both;
}

.c {
    float: left;
    margin-left: 10px;
}

</style>
<div class="a">A</div>
<div class="c">C</div>
<div class="b">B</div>

</body>
</html>
Gary Green
This is not working because you've defined the classes A, B and C all upper case and setting the value to the lower case classes a, b and c.
Octavian Damiean
@MAINERROR I've tested in FF 3.6, Chrome 6.0, Opera 10.61, IE6, IE7, IE8, all display as required. Of course it's good practise to always keep things in lowercase, though classname sensitivity isn't such an issue as e.g. id case.
Gary Green
Well I just wanted to point it out as it wasn't working that way trying it on http://jsfiddle.net.
Octavian Damiean
Ah jsfiddle. That thing is so buggy its almost unusable at times. Be very careful when using it. Certainly don't take anything on there as gospel! ;)
Gary Green
+1  A: 

Hi,

it can't be done by float, because it's no valid flow.

Try this:

<style type="text/css">
.A {
  background: green;
}

.B {
  background: yellow;
  position: relative;
}

.C {
  background: red;
  position: absolute;
  top: 0;
  right: 0;
}

.container {
  position: relative;
}

</style>




<div class="container">
  <div class="A">A</div>
  <div class="B">B</div>
  <div class="C">C</div>
</div>

Example: http://jsfiddle.net/YGw3E/

sled
spend attention on the height, the C <div> could overlap the B <div>...
sled
`position: relative` on `.B` seems not to be needed?
Adam Lindberg
However, this is the solution I went for! Thanks!
Adam Lindberg
Hi, please note that C overlaps A, this might be a problem. You can fix it by giving the element A and C fixed widths like 80% and 20% etc. See here: http://jsfiddle.net/9phGH/
sled
+1  A: 

If inrbob's example doesn't work for you, an alternative to float might be the following HTML;

<div id="container">
    <div class="A">A</div>
    <div class="B">B</div>
    <div class="C">C</div>
</div><!-- /container -->

With this CSS;

#container {
    position: relative;
}

div.C {
    position: absolute;
    top: 0;
    right: 0;
}

Let me know if that helps.

Josiah Sprague
I do have a container, so that works! Thanks! (sled posted first, though)
Adam Lindberg