style.css 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* 视口规则建议放在CSS最前面 */
  2. @viewport {
  3. width: device-width;
  4. zoom: 1.0;
  5. }
  6. body,
  7. html {
  8. margin: 0;
  9. padding: 0;
  10. width: 100%;
  11. height: 100%;
  12. overflow: hidden;
  13. background: #000;
  14. touch-action: none;
  15. }
  16. #unity-container {
  17. position: absolute;
  18. width: 100%;
  19. height: 100%;
  20. display: flex;
  21. justify-content: center;
  22. align-items: center;
  23. background: #000;
  24. /* 确保初始状态就居中 */
  25. left: 0;
  26. right: 0;
  27. margin: 0 auto;
  28. /* 添加过渡效果避免闪动 */
  29. transition: opacity 0.3s ease;
  30. opacity: 0;
  31. /* 初始不可见 */
  32. }
  33. /* 基础竖屏尺寸(9:16比例) */
  34. #unity-canvas {
  35. width: 360px;
  36. /* 基准宽度 */
  37. height: 640px;
  38. /* 基准高度 */
  39. background: url('https://cdn.goufuguiwxw.com/ResWebGlTest/gfg/Build/webgl.jpg') center / cover;
  40. /* 确保canvas初始位置正确 */
  41. position: relative;
  42. left: 0;
  43. margin: 0 auto;
  44. }
  45. /* 高质量渲染 */
  46. #unity-canvas {
  47. image-rendering: -webkit-optimize-contrast;
  48. image-rendering: crisp-edges;
  49. -webkit-font-smoothing: subpixel-antialiased;
  50. }
  51. /* 移动端适配 */
  52. @media (max-width: 768px) {
  53. #unity-canvas {
  54. width: 100vw !important;
  55. /* 精确匹配视口宽度 */
  56. height: calc(100vw * 16/9) !important;
  57. /* 强制按比例计算高度 */
  58. max-height: 100vh !important;
  59. /* 确保不超过屏幕高度 */
  60. position: absolute;
  61. left: 0 !important;
  62. right: 0 !important;
  63. }
  64. #unity-container {
  65. width: 100vw !important;
  66. /* 使用视口单位确保精确 */
  67. overflow: hidden;
  68. /* 隐藏任何可能的溢出 */
  69. }
  70. /* 修复iOS Safari的视口问题 */
  71. @supports (-webkit-touch-callout: none) {
  72. #unity-canvas {
  73. height: -webkit-fill-available !important;
  74. }
  75. }
  76. }
  77. /* PC端特殊适配 */
  78. @media (min-width: 769px) {
  79. #unity-canvas {
  80. height: 100vh !important;
  81. /* 独占高度 */
  82. width: calc(100vh * 9/16) !important;
  83. /* 按比例计算宽度 */
  84. }
  85. }