gpt4 book ai didi

css - 将JS生成的侧边栏旁边的内容向右移动

转载 作者:行者123 更新时间:2023-11-28 01:24:34 25 4
gpt4 key购买 nike

我用 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>

enter image description here

编辑:我刚刚在 JS 中为创建游戏板的 Canvas 元素添加了一个类,并在 CSS 中为其添加了左边距。

最佳答案

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>

关于css - 将JS生成的侧边栏旁边的内容向右移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51316373/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com