0

I have a game going where i'm doing hitsplats to show up over your picture as you hit your opponent. I"m using the absolute position and this works but I encountered a problem. The problem being that if I resize the window or I am in another resolution, these spots are not how I orginally setup them up. Putting my hit splats in relative mode only moves stuff around. So how can I get my hitsplats in the center like they are now with Absolute, but yet not make them absolutely absolute? So they flow with the document?

#npchitbox {
    width: 50px;
    height: 50px;
    position: absolute;
    background-color:blue;
    z-index: 11;
    top: 100px;
    left: 1050px;
    text-align: center;
    font-weight: bold;
    font-size: 50px;
    color: red;
    }

Here is HTML code

<div id="playerbox">
    <div id="hitbox"> </div>
4

3 回答 3

0

尝试将其添加到 hitsplat/hitbox div 的容器 CSS 中:

position:relative;

它应该使 hitbox 的位置绝对指向容器而不是窗口。

从理论上讲,它应该将容器从浏览器窗口转移到您分配位置的任何 div/容器:相对。

于 2013-10-31T03:36:30.003 回答
0

你能显示 html 并且你试图只将 hisplate 居中吗?如果是这样,请这样做

{
margin: auto;
position: absolute;
top: 0; bottom:0; right:0; left:0;
}
于 2013-10-31T02:14:50.293 回答
0

调整窗口大小时,在 jquery 中使用 resize 事件将其调整到确切位置

$( window ).resize(function() {
  $( "#hitbox" ).attr( "top", ($( window ).height()-50) +"px" ); 
//since 50 is the size of the box you are using
});
于 2013-10-31T05:45:05.140 回答