0

i created a maze and i want to center the smily div ("highlight_lose") to the maze ("main")

#highlight_lose {
    width: 550px;
    height:550px;
    position: absolute;
    margin: 0 auto;
    top: 50%;
    bottom: 375px;


}

here is the fiddle link: http://jsfiddle.net/uqcLn/30/

alonblack
  • 925
  • 2
  • 13
  • 31

2 Answers2

1

New Answer

Based on what you gave me, this is the required CSS code, using the old faithful position absolute method.

#highlight_lose {
    height: 300px;
    width: 100%;
    position: absolute;
    top: 50%;
    margin-top: -150px;
}
div.sad_smileyface {
    width: 300px;
    height: 100%;
    position: relative;
    margin: 0 auto;
    ...
    [your graphic styling code here]
}

One point to note, is I set the containing div's width to 100% and centered it vertical. I then centered the child smileyface div horizontally. This isn't required, just the method I did it in. If the height changes, adjust the #highlight_lose, if the width changes, update sad_smileyface

Original Answer

If the height is at least decalred (which yours is), set the parent container as position: relative (just to make sure), you should be able to use margin: auto; on your child div's. This should work cross-browser to IE 6.

Other options include doing your method, by setting the margin to negative half the height and width. margin: -275px -275px;.

Also, CSS3's Flexbox model will fix this as well, but is heavily prefixed and not supported everywhere.

CP510
  • 2,297
  • 15
  • 15
-1

http://jsfiddle.net/uqcLn/34/

Here is the new updated version, you can also set margin instead of transform for older browsers