0

I would like to make the blue element sit halfway up the green circle and behind it. How can I do that? Also, why is there a random marginal-space between the green circle and the blue element?

enter image description here

#profile-circle {
    margin-right: auto; margin-left: auto;
    height: 164px; width: 164px;
    border-radius: 84px 84px 84px 84px;
}

#main-container {
    margin-right: auto; margin-left: auto;
    height: 400px; width: 450px;
}

http://jsfiddle.net/LqJ79/

2
  • You shouldn't rely on 3rd party sites in order to demonstrate your problem. Add the important code to the question, in case jsfiddle goes down. Commented Jul 5, 2012 at 18:39
  • Thank you for using jsfiddle to demonstrate your problem. Commented Jul 5, 2012 at 18:43

5 Answers 5

2

position: relative will help you here. It allows you to use z-index to put the circle over the box, and also you can use top which will move the box relative to its current position. The problem with position: absolute is that it takes the element out of the flow, which is not what you need here I think.

#profile-circle {
    position: relative;
    z-index: 100;
}

#main-container {
    position: relative;
    z-index: 50;
    top: -100px;
}

See the demo

Sign up to request clarification or add additional context in comments.

Comments

0

Use attributes "position: absolute;" in the second box, I updated js fiddle CSS with the following:

#main-container {
    margin-right: auto;
    margin-left: auto;
    height: 400px;
    width: 450px;
    background-color: blue;
    position: absolute;
    top: 80px;
}

Comments

0

The easiest way to move the blue element up is to set a negative top margin:

margin-top: -82px;

However, with your current markup, the blue element will sit on top.

You can either put the green element below the blue one in your HTML, then use CSS to slide it up, or you can:

  1. use position: relative; on both elements
  2. set a z-index on the blue and green elements to determine which appears on top (give the green element a higher number so it appears on top)
  3. set top: -82px; on the blue element to slide it up under the green one

The space between them is due to your margins:

margin-top: 15px;
margin-bottom: 5px;

Comments

0

you can make the position: fixed; top:10px; left: 10px; z-index: 1; and what not in the css to move them around. like this:

http://jsfiddle.net/LqJ79/

Comments

0

The 'magical' space between the two is due to the margin in the div user-info. I changed the CSS to the following:

#user-info {
height: auto;
width: 380px;
margin-right: auto;
margin-left: auto;
}

This will removed the space.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.