html - CSS3 : How can I get something that works like "absolute" but isn't?

标签 html css

我有一个游戏正在进行中,我正在做 hitsplats 以在你击中对手时出现在你的照片上。我使用的是绝对位置,但我遇到了一个问题。问题是,如果我调整窗口大小或者我在另一个分辨率下,这些点不是我最初设置它们的方式。将我的命中 splats 置于相对模式只会移动东西。那么我怎样才能像现在使用 Absolute 一样让我的 hitsplats 位于中心,但又不使它们绝对绝对?所以它们会随文档一起流动?

#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;
    }

这是HTML代码

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

最佳答案

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

{
margin: auto;
position: absolute;
top: 0; bottom:0; right:0; left:0;
}

关于html - CSS3 : How can I get something that works like "absolute" but isn't?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19697190/

相关文章:

JavaScript:获取从页面顶部到任何标签的距离

css - 未呈现 Tizen SDK CSS ID

css - 如何添加一个:hover css function to this code?

jquery - jQuery 如何找到动态生成的表中单击的按钮的行号?

javascript - 使用 jquery 克隆行

HTML/CSS - 滚动时固定背景

html - Bootstrap 崩溃太快

css - 强制正确的最大宽度

jquery - 获取 jquery 中 div 的宽度,其宽度为 auto

jquery - 将 AJAX 功能添加到 anchor 行为,但保留 href 用于 SEO