我有一个 div
模拟一个小微调器的块,一切正常但是使用 css
配置我有它位于右上翼,我试图将它居中但是当我从移动设备上看到它从某个位置移动..如何在不改变不同尺寸设备位置的情况下将它居中?
.spinner {
display: block;
position: fixed;
z-index: 1031;
top: 15px;
right: 15px;
}
原文由 FeRcHo 发布,翻译遵循 CC BY-SA 4.0 许可协议
我有一个 div
模拟一个小微调器的块,一切正常但是使用 css
配置我有它位于右上翼,我试图将它居中但是当我从移动设备上看到它从某个位置移动..如何在不改变不同尺寸设备位置的情况下将它居中?
.spinner {
display: block;
position: fixed;
z-index: 1031;
top: 15px;
right: 15px;
}
原文由 FeRcHo 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果您希望微调器覆盖整个视口:
.spinner {
border: 1px solid;
position: fixed;
z-index: 1;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 50 50'%3E%3Cpath d='M28.43 6.378C18.27 4.586 8.58 11.37 6.788 21.533c-1.791 10.161 4.994 19.851 15.155 21.643l.707-4.006C14.7 37.768 9.392 30.189 10.794 22.24c1.401-7.95 8.981-13.258 16.93-11.856l.707-4.006z'%3E%3CanimateTransform attributeType='xml' attributeName='transform' type='rotate' from='0 25 25' to='360 25 25' dur='0.6s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E") center / 50px no-repeat;
}
<div class="spinner"></div>
如果你希望它只是 gif/svg 的大小:
.spinner {
border: 1px solid;
position: fixed;
z-index: 1;
left: 0;
right: 0;
top: 0;
bottom: 0;
width: 50px;
height: 50px;
margin: auto;
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 50 50'%3E%3Cpath d='M28.43 6.378C18.27 4.586 8.58 11.37 6.788 21.533c-1.791 10.161 4.994 19.851 15.155 21.643l.707-4.006C14.7 37.768 9.392 30.189 10.794 22.24c1.401-7.95 8.981-13.258 16.93-11.856l.707-4.006z'%3E%3CanimateTransform attributeType='xml' attributeName='transform' type='rotate' from='0 25 25' to='360 25 25' dur='0.6s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E") center / contain no-repeat;
}
<div class="spinner"></div>
原文由 Stickers 发布,翻译遵循 CC BY-SA 3.0 许可协议
3 回答920 阅读✓ 已解决
4 回答1.3k 阅读✓ 已解决
2 回答929 阅读✓ 已解决
2 回答1.5k 阅读✓ 已解决
2 回答1.3k 阅读✓ 已解决
2 回答902 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
由于它是固定的,
top|left|right|bottom
属性是相对于窗口的。所以百分比位置,在这种情况下,50% 应该可以解决问题。替代方案,由 Utkanos 在评论中给出