views:

372

answers:

3

I have a which is in the center of my page, but now i need to add a div which will be to the right of the center box, i am sure you can do this with CSS but can't think of a solution.

So for example div#container{margin-left: auto;margin-right: auto;width: 396px;display:block;margin-top: 110px;}

the div i need would be the same as that kinda? but with +396px to clear the div thats already there? Is this possible ?

A: 

You are looking for the float css property.

http://www.w3schools.com/css/pr_class_float.asp

e.g.

<div>
  <div style="float:left"> Lorem Ipsum</div>
</div>
chris
+1  A: 

Position the #container relative, and #inner absolutely.

div#container {
    margin-left: auto;
    margin-right: auto;
    width: 396px;
    display: block;
    margin-top: 110px;
    position: relative;
}

div#inner {
    position: absolute;
    right: 0px;
}
Alan Haggai Alavi
This would work if i minus the right property, is this an okey way to do it or is this bad practise?
for example:div#inner { position: absolute; right: -230px;top:0px; background:#EEEEEE; width: 200px;}
I do not think my solution is good. I mistook your question. I thought you wanted an inner div.
Alan Haggai Alavi
+1  A: 

Float the right div to the right. Be sure it is in your html before the div#container.

div#container{margin:100px auto 0;width: 396px;height:396px;margin-top: 110px;background-color:#ccc;}
div#right{float:right; width:200px;height:200px;background-color:#c6c;}

<div id="right"></div>
<div id="container"></div>
Emily