html - 位置:与宽视口绝对重叠
问题描述
我有一个稍微旋转的 div,在我的起始页上创建了一个不对称的图形。我overflow: hidden
用来隐藏该div的重叠。一切都使用绝对定位来准确地将元素放在我想要的位置,并使用 vw 和 vh 使其响应。纵横比“正常”时看起来很棒,但当窗口接近 2 或 3:1 纵横比时(如超宽显示器),一切都会重叠。窄纵横比不是问题,因为我在它成为问题之前将其切换到移动视图。
我考虑过使用overflow: auto
它,这样它就不会被迫适应视口,但可以看到旋转的 div 的边缘。
是否有解决方案,或者这可能是不好的做法,应该以不同的方式进行?
html, body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#body {
overflow: hidden;
background: red;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.shape {
position: absolute;
right: -10%;
top: -50%;
height: 200%;
width: 45%;
transform: rotate(350deg);
background: white;
}
#welcome {
position: absolute;
color: black;
z-index: 999;
margin-left: 65vw;
margin-top: 10vh;
}
#welcome h1 {
margin-bottom: 0;
font-size: 7vw;
}
#welcome p {
font-size: 4vw;
margin-top: 0;
}
#startbtn {
position: absolute;
font-size: 3vw;
padding: 4vh 5.5vw 4vh 5.5vw;
background: blue;
color: white;
border: none;
margin-left: 65vw;
margin-top: 70vh;
}
<body id="body">
<div class="shape"></div>
<div class="wrapper">
<div id="welcome" autofocus>
<h1>Welcome</h1>
<p>More Text Here</p>
</div>
</div>
<div class="wrapper">
<input type="button" id="startbtn" onclick="getstarted()" value="Get Started">
</div>
</body>
</html>
谢谢!
解决方案
欢迎来到 Stackoverflow。将形状放入同一个容器(我使用第一个包装器)作为您的内容应该可以解决问题。为什么会这样:因为白色形状应该与您的内容相关。我也确实将按钮放在同一个容器中。
而且你的身体不需要背景尺寸,因为它只是纯红色。
我可能弄乱了您的原始尺寸,但这应该可以解决问题。
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
body {
overflow: hidden;
background: red;
}
.wrapper {
position: relative;
height: 100%;
}
.shape {
position: absolute;
margin-top: -50%;
margin-right: -50%;
right: 0;
height: 300%;
width: 100%;
transform: rotate(350deg);
background: white;
}
#welcome {
position: absolute;
color: black;
z-index: 999;
margin-left: 65vw;
margin-top: 10vh;
}
#welcome h1 {
margin-bottom: 0;
font-size: 7vw;
}
#welcome p {
font-size: 4vw;
margin-top: 0;
}
#startbtn {
position: absolute;
font-size: 3vw;
padding: 4vh 5.5vw 4vh 5.5vw;
background: blue;
color: white;
border: none;
margin-left: 65vw;
margin-top: 70vh;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
#body {
overflow: hidden;
background: red;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
.wrapper {
position: relative;
height: 100%;
}
.shape {
position: absolute;
margin-top: -50%;
margin-right: -50%;
right: 0;
height: 300%;
width: 100%;
transform: rotate(350deg);
background: white;
}
#welcome {
position: absolute;
color: black;
z-index: 999;
margin-left: 65vw;
margin-top: 10vh;
}
#welcome h1 {
margin-bottom: 0;
font-size: 7vw;
}
#welcome p {
font-size: 4vw;
margin-top: 0;
}
#startbtn {
position: absolute;
font-size: 3vw;
padding: 4vh 5.5vw 4vh 5.5vw;
background: blue;
color: white;
border: none;
margin-left: 65vw;
margin-top: 70vh;
}
<div class="wrapper">
<div class="shape"></div>
<div id="welcome" autofocus>
<h1>Welcome</h1>
<p>More Text Here</p>
</div>
<input type="button" id="startbtn" onclick="getstarted()" value="Get Started">
</div>
推荐阅读
- pandas - 如何在pandas groupby之后将行旋转到列
- oracle - 当 Oracle Function 没有输入值时,Spring Boot SimpleJdbcCall 失败
- java - 如何替换特定位置的特殊字符
- mysql - 从一个表中提取记录,其中 1 个变量存在于第二个表中?非常大的桌子
- kotlin - 为什么在 Intellij IDEA 中代码中存在 ENQ/ESA unicode 字符会导致它显示错误的多字符文字错误?
- javascript - 如何在新选项卡中打开链接而不在新选项卡中看到 URL?
- android - 如何使用 Android 28 (Pie) 将 sqlite 数据库直接存储在 sdcard 上
- postgresql - 如何指定生成的数字范围?
- python - PackagesNotFoundError:当前频道不提供以下软件包:- 管理
- java - Java Process Builder 不执行多个命令