gpt4 book ai didi

html - 定位位置为 :fixed side-by-side each other 的元素

转载 作者:行者123 更新时间:2023-11-27 23:06:27 26 4
gpt4 key购买 nike

对于用于移动浏览器的 Web 应用程序,我想集成 this简单而优雅的预加载器。它将驻留在半透明覆盖层之上。它上面还会有一些文字(例如“请稍候...”或“稍等...”等)。

我尝试整合所有这些。结果如下(运行代码片段)。它有 3 个不同的问题(你能帮我解决所有问题吗):

1) 我无法定位预加载器 + 它是半透明覆盖层顶部的文本(尽管我使用了高 z-index)。

2) 此外,预加载器图形会随着上面句子的长度而倾斜。我希望它独立于此。

3) 最后,它们没有位于正中间(垂直而言)。

body{background:#ECF0F1}

.parent{
position:fixed;
z-index:1;
top:50%;
left:50%;
transform:translate(-50%, -50%);
}

.caption{
margin-bottom:1em;
color:gray;
position:relative;
z-index:10;
}

.load{
width:50px;
height:50px;
position:relative;
z-index:10;

}
.load hr{border:0;margin:0;width:40%;height:40%;position:fixed;border-radius:50%;animation:spin 2s ease infinite}

.load :first-child{background:#19A68C;animation-delay:-1.5s}
.load :nth-child(2){background:#F63D3A;animation-delay:-1s}
.load :nth-child(3){background:#FDA543;animation-delay:-0.5s}
.load :last-child{background:#193B48}

@keyframes spin{
0%,100%{transform:translate(0)}
25%{transform:translate(160%)}
50%{transform:translate(160%, 160%)}
75%{transform:translate(0, 160%)}
}

.overlay{
position:fixed;
width:100%;
height:100%;
top:0;
left:0;
opacity:0.6;
z-index:100;
background-color:#FFFFFF;
}

body {

background: #E8F5E9;
background: repeating-linear-gradient(
to right,
#FAFAFA,
#FAFAFA 50px,
#E8F5E9 50px,
#E8F5E9 100px
);
}
<body>
<div class="overlay">
<div class="parent">
<div class="caption">Lorem ipsum dolor sit amet ...</div>
<div class="load">
<hr><hr><hr><hr>
</div>
</div>
</div>
<body>

注意:我希望使用纯 CSS 解决方案,不涉及 JS。我还想避免 flex-box,并寻求通用的东西(在向后兼容的意义上)。例如。 flex-box 支持在旧版本的 Android 浏览器中减少(根据 caniuse.com)。我也想尊重这些版本,因此最好坚持使用受良好支持的 CSS 2.1 属性。

最佳答案

问题在于 hr 元素,它们被固定放置并且它们应该是绝对的以保持它们与父容器的关系。然后只需将 margin:auto 添加到 load 即可使它们居中。

并且由于 parentoverlay 元素都是固定位置的,您可以将它们分开以便能够正确使用 z-index 并避免叠加应用的不透明度:

body {
background: #ECF0F1
}

.parent {
position: fixed;
z-index: 1000;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.caption {
margin-bottom: 1em;
color: gray;
position: relative;
z-index: 10;
}

.load {
width: 50px;
height: 50px;
position: relative;
z-index: 10;
margin: auto;
}

.load hr {
border: 0;
margin: 0;
width: 40%;
height: 40%;
position: absolute;
border-radius: 50%;
animation: spin 2s ease infinite
}

.load :first-child {
background: #19A68C;
animation-delay: -1.5s
}

.load :nth-child(2) {
background: #F63D3A;
animation-delay: -1s
}

.load :nth-child(3) {
background: #FDA543;
animation-delay: -0.5s
}

.load :last-child {
background: #193B48
}

@keyframes spin {
0%,
100% {
transform: translate(0)
}
25% {
transform: translate(160%)
}
50% {
transform: translate(160%, 160%)
}
75% {
transform: translate(0, 160%)
}
}

.overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
opacity: 0.6;
z-index: 100;
background-color: #FFFFFF;
}

body {
background: #E8F5E9;
background: repeating-linear-gradient( to right, #FAFAFA, #FAFAFA 50px, #E8F5E9 50px, #E8F5E9 100px);
}
<div class="overlay">
</div>
<div class="parent">
<div class="caption">Lorem ipsum dolor sit amet ...</div>
<div class="load">
<hr>
<hr>
<hr>
<hr>
</div>
</div>

关于html - 定位位置为 :fixed side-by-side each other 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48713940/

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