[英]Vue.js: Setting div position and size using scoped CSS
I'm working on a web application using Vue.js that has the following structure: 我正在使用具有以下结构的Vue.js开发Web应用程序:
<App>
<HomePage>
<ErrorPage/>
<StartPage/>
<ExitPage/>
</HomePage>
<Game>
<GameScreen/>
</Game>
</App>
<HomePage>
and <Game>
are going to be conditionally rendered and will not be visible at the same time. <HomePage>
和<Game>
将有条件地渲染,并且不会同时显示。 The same applies also for their child components. 它们的子组件也是如此。
Now I would like the currently displayed child component (or the root <div>
of the child component) to fill the whole browser window. 现在,我希望当前显示的子组件(或子组件的根
<div>
)填充整个浏览器窗口。 So for example <ErrorPage/>
or <GameScreen/>
should be stretched to full size. 因此,例如
<ErrorPage/>
或<GameScreen/>
应该拉伸到完整大小。
I've been trying all kinds of combinations using position: absolute
, width
, height
etc., but still the child components only take up a small part of the window. 我一直在尝试使用
position: absolute
各种组合position: absolute
, width
, height
等,但是子组件仍然只占窗口的一小部分。 This has probably something to do with the way <style scoped>
works in Vue.js, because in an old prototype of my application (which didn't use Vue.js) things worked fine. 这可能与
<style scoped>
在Vue.js中的工作方式有关,因为在我的应用程序的旧原型(未使用Vue.js)中,一切正常。 But just removing the scoped
attribute doesn't help. 但是仅仅删除
scoped
属性是没有帮助的。
Does anyone have an idea where to place the right CSS to make things work? 有谁知道在哪里放置合适的CSS来使事情工作?
Try something along these lines: 尝试以下方法:
.game-div {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
}
Replace .game-div
with the selector for your <Game>
element. 将
.game-div
替换为<Game>
元素的选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.