当游戏开始时,flexbox居中对静态对象非常有效。在游戏进行过程中,标题和剩余的div会改变它们的值/大小,这会导致flexbox不断调整中心位置(header中的所有div都在移动)。
我希望header中的每个div在游戏过程中都能保持“固定”。
使用flexbox是否可能实现这一点,或者我应该采用另一种方法?我应该单独定位每个元素吗?
您可以在远程服务器上观察header的行为: https://stacho163.000webhostapp.com/firstLevel.html
我希望header中的每个div在游戏过程中都能保持“固定”。
使用flexbox是否可能实现这一点,或者我应该采用另一种方法?我应该单独定位每个元素吗?
您可以在远程服务器上观察header的行为: https://stacho163.000webhostapp.com/firstLevel.html
body {
margin: 0;
width: 100%;
height: 100%;
}
header {
display: flex;
justify-content: space-around;
align-items: center;
background-color: white;
}
#game-window {
position: absolute;
width: 90vw;
height: 90vw * 16/9;
top: 50%;
left: 50%;
transform: translate(-50%, -46%);
background-color: gray;
}
<body>
<header>
<div id="lifes">
Life1 Life2 Life3
</div>
<div id="title">
Title (changes when you win)
</div>
<div id="remain">
Remaining: (from 100 to 0)
</div>
</header>
<canvas id="game-window"></canvas>
</body>
https://jsfiddle.net/nfzj183t/14/
我想问一下,因为我在网页方面没有太多经验,我想使用正确的方法来解决这个简单的问题。
非常感谢您的提示 :)