出于某种原因,当我输入 id“enterGame”时,position: absolute
div 消失了。即使我添加到 body 或 html 标签 position: relative
我仍然看不到 div。
相关代码:
html {
height: 100vh;
}
body {
background-image: linear-gradient(lightblue, pink);
margin: 0 auto;
}
* {
font-family: 'Oswald', sans-serif;
letter-spacing: 1vw;
}
h1 {
font-size: 5vw;
text-align: center;
margin: 0 auto;
cursor: default;
}
#enterGame {
height: 50vh;
background-color: white;
border-top: 5px solid black;
border-bottom: 5px solid black;
}
<body>
<h1>Tic Tac Toe</h1>
<div id="enterGame"></div>
<script src="script.js"></script>
</body>
最佳答案
一旦添加 position: absolute
它就会消失,因为它没有宽度。尝试设置 width: 100vw
它再次出现。
关于html - 即使 parent 是相对的,也不能定位绝对 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59427183/