我用自己喜欢的页面制作了一个带有JavaScript和侧边栏的游戏,但是我不确定如何使游戏(已加载JavaScript)移到侧边栏的右侧。可以使用CSS完成吗?
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
height: 100%;
}
body {
text-align: center;
background: #ececec;
font-family: Josefin Sans, sans-serif;
}
.info-panel {
background-color: #fff;
/* Allows game to display next to panel rather than below it */
position: absolute;
left: 0;
width: 30%;
height: 100vh;
}
<div class="info-panel">
<h2>Arcade Game</h2>
<p>Use the arrow keys to get to the water.</p>
<h4>Score: <span id="score"></span></h4>
</div>
编辑:我刚刚在canvas元素中添加了一个类,以在JS中创建游戏板,并在CSS中为其添加了一个左空白。
答案 0 :(得分:0)
CSS:
* {
box-sizing: border-box;
}
html, body {
margin: 0;
height: 100%;
}
body {
text-align: center;
background: #ececec;
font-family: Josefin Sans, sans-serif;
}
.info-panel {
background-color: #fff;
/* Allows game to display next to panel rather than below it */
position: absolute;
right:0px;
width: 30%;
height: 100vh;
}
<div class="info-panel">
<h2>Arcade Game</h2>
<p>Use the arrow keys to get to the water.</p>
<h4>Score: <span id="score"></span></h4>
</div>
<script src="js/resources.js"></script>
<script src="js/app.js"></script>
<script src="js/engine.js"></script>