html Safari for Desktop忽略CSS

ui7jx7zq  于 2024-01-04  发布在  其他
关注(0)|答案(1)|浏览(91)

我正在尝试修复一些CSS/(HTML/JS?)我的Safari网站上的错误,特别是桌面版。由于我自己没有Safari桌面版,我使用浏览器堆栈在Safari上查看我的网站。问题是我页面上的两个按钮都有背景,但只有一个按钮有焦点类(这应该会添加背景,但在Safari上却被部分忽略了,因为有时候它没有添加,我不得不手动添加它)。有人知道为什么会发生这种情况吗?它看起来很简单,只是添加一个类,添加一个背景颜色。

CSS

  1. @media (max-width: 1000px) {
  2. .container {
  3. width: 90%;
  4. }
  5. }
  6. @media (max-height: 600px) {
  7. .wrapper {
  8. height: 70%;
  9. }
  10. }
  11. p {
  12. margin: 0;
  13. padding: 0;
  14. }
  15. body {
  16. width: 100vw;
  17. height: 100vh;
  18. margin: 0;
  19. padding: 0;
  20. background-color: #121212;
  21. }
  22. /* Portfolio Header */
  23. #header {
  24. display: -webkit-box;
  25. display: -ms-flexbox;
  26. display: flex;
  27. -webkit-box-pack: center;
  28. -ms-flex-pack: center;
  29. justify-content: center;
  30. font-family: "Poppins-ExtraBold", sans-serif;
  31. font-weight: 700;
  32. font-size: 60px;
  33. margin-bottom: 10px;
  34. background-image: -o-linear-gradient(
  35. 45deg,
  36. #4158d0 -10%,
  37. #c850c0 40%,
  38. #ffb116 100%
  39. );
  40. background-image: linear-gradient(
  41. 45deg,
  42. #4158d0 -10%,
  43. #c850c0 40%,
  44. #ffb116 100%
  45. );
  46. -webkit-background-clip: text;
  47. background-clip: text;
  48. color: transparent;
  49. text-align: center;
  50. }
  51. #subtitle {
  52. display: -webkit-box;
  53. display: -ms-flexbox;
  54. display: flex;
  55. -webkit-box-pack: center;
  56. -ms-flex-pack: center;
  57. justify-content: center;
  58. font-family: "Poppins-Bold", sans-serif;
  59. -ms-grid-row-align: center;
  60. align-self: center;
  61. font-size: 30px;
  62. margin-bottom: 75px;
  63. color: white;
  64. }
  65. /* Container */
  66. .flex-container {
  67. display: -webkit-box;
  68. display: -ms-flexbox;
  69. display: flex;
  70. -webkit-box-pack: center;
  71. -ms-flex-pack: center;
  72. justify-content: center;
  73. -webkit-box-align: center;
  74. -ms-flex-align: center;
  75. align-items: center;
  76. height: 100%;
  77. }
  78. .container {
  79. background-color: #282c34;
  80. border-radius: 25px;
  81. text-align: center;
  82. width: 750px;
  83. }
  84. /* Tabs */
  85. /* Style the tab */
  86. .tab {
  87. overflow: hidden;
  88. border: 3px solid #1c1b1b;
  89. border-top-left-radius: 25px;
  90. border-top-right-radius: 25px;
  91. background-color: #f1f1f1;
  92. }
  93. /* Style the buttons that are used to open the tab content */
  94. .tab button {
  95. font-weight: 700;
  96. font-size: 26px;
  97. font-family: Consolas, monospace;
  98. float: left;
  99. border: none;
  100. outline: none;
  101. cursor: pointer;
  102. padding: 14px 18px;
  103. -webkit-transition: 0.3s;
  104. -o-transition: 0.3s;
  105. transition: 0.3s;
  106. color: black;
  107. }
  108. /* reset pre tag */
  109. pre {
  110. margin: 0;
  111. padding: 0;
  112. }
  113. .tab button:focus {
  114. background-color: rgb(197, 197, 197);
  115. }
  116. /* Change background color of buttons on hover */
  117. .tab button:hover {
  118. background-color: rgb(197, 197, 197);
  119. }
  120. /* Create an active/current tablink class */
  121. .tab button.active {
  122. background-color: rgb(197, 197, 197);
  123. }
  124. /* Style the tab content */
  125. .tabcontent {
  126. display: none;
  127. height: 396px;
  128. font-size: 22px;
  129. border: 3px solid #121212;
  130. border-bottom-right-radius: 25px;
  131. border-bottom-left-radius: 25px;
  132. font-family: Consolas, monospace;
  133. text-align: left;
  134. padding: 6px 12px;
  135. border-top: none;
  136. }
  137. .console {
  138. padding: 10px 22px 2px 22px;
  139. }
  140. #Console,
  141. #Code {
  142. position: relative;
  143. }
  144. /* adjusting stack overflow style */
  145. #Code pre code.hljs {
  146. padding: 1em 1em 0 1em;
  147. }
  148. /* Gets added whenever a tab button is pressed */
  149. .focused {
  150. background-color: rgb(197, 197, 197);
  151. }
  152. /* Run Code Button */
  153. .run {
  154. background-color: rgb(44, 156, 0);
  155. }
  156. .stop {
  157. background-color: rgb(204, 2, 2);
  158. }
  159. .stop .button__icon {
  160. width: 28px;
  161. }
  162. .button {
  163. /* position: absolute; */
  164. /* bottom: 8%; */
  165. display: -ms-inline-flexbox;
  166. display: inline-flex;
  167. width: 130px;
  168. height: 40px;
  169. margin-left: 1.5%;
  170. border: none;
  171. outline: none;
  172. border-radius: 5px;
  173. overflow: hidden;
  174. font-family: "Arial", sans-serif;
  175. font-size: 24px;
  176. font-weight: 500;
  177. cursor: pointer;
  178. position: absolute;
  179. bottom: 25px;
  180. left: 12px;
  181. }
  182. .run:hover {
  183. background-color: rgb(40, 139, 0);
  184. }
  185. .run:active {
  186. background-color: rgb(40, 139, 0);
  187. }
  188. .stop:hover {
  189. background-color: rgb(187, 7, 7);
  190. }
  191. .stop:active {
  192. background-color: rgb(187, 7, 7);
  193. }
  194. .button__text,
  195. .button__icon {
  196. font-size: 24px;
  197. display: -ms-inline-flexbox;
  198. display: inline-flex;
  199. -webkit-box-align: center;
  200. -ms-flex-align: center;
  201. align-items: center;
  202. color: #fff;
  203. height: 100%;
  204. }
  205. .button__text {
  206. padding: 0 20px 0 10px;
  207. width: 35px;
  208. }
  209. .button__icon {
  210. padding: 0 18px 0 12px;
  211. width: 34px;
  212. font-size: 5em;
  213. background: rgba(0, 0, 0, 0.08);
  214. }
  215. /* Text */
  216. .textHeadline {
  217. font-weight: 1000;
  218. font-size: 24px;
  219. color: rgb(255, 255, 255);
  220. font-family: "Consolas", sans-serif;
  221. }
  222. .text {
  223. font-size: 18px;
  224. color: rgb(255, 255, 255);
  225. font-family: "Poppins-Regular", sans-serif;
  226. }
  227. /* Social Media Icons Container */
  228. .social-profiles {
  229. display: -webkit-box;
  230. display: -ms-flexbox;
  231. display: flex;
  232. -webkit-box-align: center;
  233. -ms-flex-align: center;
  234. align-items: center;
  235. /* text-align: center; */
  236. -webkit-box-pack: center;
  237. -ms-flex-pack: center;
  238. justify-content: center;
  239. }
  240. /* Social Media Icons */
  241. .icons {
  242. color: white;
  243. margin-top: 10px;
  244. padding: 10px;
  245. -webkit-transition: color 0.2s;
  246. -o-transition: color 0.2s;
  247. transition: color 0.2s;
  248. text-decoration: none;
  249. font-size: 4em;
  250. }
  251. .icons:hover {
  252. color: #b6b6b6;
  253. }
  254. /* Href */
  255. #link {
  256. color: #aaa;
  257. }

字符串

JS

  1. // Ein Großteil des Scripts habe ich von: https://www.w3schools.com/howto/howto_js_tabs.asp
  2. function onLoadFunctions(){
  3. document.getElementById("codeBtn").classList.add('focused');
  4. document.getElementsByClassName("run")[0].addEventListener("click", function (){
  5. openTab("Console")
  6. })
  7. document.getElementsByClassName("stop")[0].addEventListener("click", function (){
  8. openTab("Code")
  9. })
  10. document.getElementById("codeBtn").addEventListener("click", function (){
  11. openTab("Code")
  12. })
  13. document.getElementById("consoleBtn").addEventListener("click", function (){
  14. openTab("Console")
  15. })
  16. }
  17. window.onload = onLoadFunctions;
  18. function openTab(tabName) {
  19. event.preventDefault();
  20. const codeBtn = document.getElementById("codeBtn");
  21. const consoleBtn = document.getElementById("consoleBtn");
  22. const tabContent = document.getElementsByClassName("tabcontent");
  23. const tabLinks = document.getElementsByClassName("tablinks");
  24. // Reset all tabs and buttons
  25. codeBtn.classList.remove('focused');
  26. codeBtn.offsetWidth;
  27. consoleBtn.classList.remove('focused');
  28. consoleBtn.offsetWidth;
  29. for (let i = 0; i < tabContent.length; i++) {
  30. tabContent[i].style.display = "none";
  31. }
  32. for (let i = 0; i < tabLinks.length; i++) {
  33. tabLinks[i].className = tabLinks[i].className.replace(" active", "");
  34. }
  35. // Show the selected tab and add "active" class to the button
  36. document.getElementById(tabName).style.display = "block";
  37. let button;
  38. if (tabName === "Code") {
  39. button = codeBtn;
  40. } else {
  41. button = consoleBtn;
  42. }
  43. button.classList.add('focused');
  44. void button.offsetWidth;
  45. }

HTML格式

  1. <!DOCTYPE html>
  2. <html lang="de">
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <title>Gabriel | Homepage</title>
  6. <link rel="icon" href="assets/logo-github.svg">
  7. <link rel="stylesheet" href="style.css">
  8. <link rel="stylesheet"
  9. href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/styles/atom-one-dark.min.css">
  10. <script src="script.js"></script>
  11. </head>
  12. <body>
  13. <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.5.0/highlight.min.js"></script>
  14. <script>hljs.highlightAll();</script>
  15. <script type="module" src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js"></script>
  16. <script nomodule src="https://unpkg.com/[email protected]/dist/ionicons/ionicons.js"></script>
  17. <div class="flex-container">
  18. <div class="wrapper">
  19. <!--Ueberschrift-->
  20. <h1 id="header">Gabriel | Portfolio</h1>
  21. <p id="subtitle">Mein Portfolio in einem Code/Console-Style</p>
  22. <!--Ueberschrift Ende-->
  23. <!--Container Start; Tab Buttons-->
  24. <div class="container">
  25. <div class="tab">
  26. <button id="codeBtn" class="tablinks">Code</button>
  27. <button id="consoleBtn" class="tablinks">Console</button>
  28. </div>
  29. <!--Tab Buttons Ende-->
  30. <!--Java Code und 'Run Code' Button-->
  31. <div id="Code" class="tabcontent" style="display: block;">
  32. <pre><code class="java">public class Main{
  33. public static void main(String[] args) {
  34. Person gabriel = new Person();
  35. System.out.println(gabriel.toString());
  36. // TODO: Implement spaghetti code method 🍝
  37. }
  38. }
  39. </code><br>&nbsp;</pre>
  40. <button type="button" class="button run">
  41. <span class="button__text">Run</span>
  42. <span class="button__icon">
  43. <ion-icon name="caret-forward-outline"></ion-icon>
  44. </span>
  45. </button>
  46. </div>
  47. <!--Java Code und 'Run Code' Button Ende-->
  48. <!--Konsole Output-->
  49. <div id="Console" class="tabcontent console">
  50. <p>
  51. <span class="textHeadline">📌About Me</span>
  52. <br><span class="text">
  53. Ich bin Java Backend Entwickler, möchte mich in Zukunft jedoch vor allem auf
  54. C++ und Rust konzentrieren.
  55. </span>
  56. </p>
  57. <br>
  58. <p>
  59. <span class="textHeadline">📌Projekte</span>
  60. <span class="text">
  61. <br>Alle meine Projekte sind auf meinem
  62. <a id="link" href="https://github.com/github-gabriel" target="blank">GitHub</a>
  63. auffindbar.
  64. </span>
  65. </p>
  66. <button type="button" class="button stop">
  67. <span class="button__text">Stop</span>
  68. <span class="button__icon">
  69. <ion-icon name="stop"></ion-icon>
  70. </span>
  71. </button>
  72. </div>
  73. </div>
  74. <!--Konsole Output Ende-->
  75. <!--Social Media Links-->
  76. <div class="social-profiles">
  77. <a class="icons" href="https://github.com/github-gabriel" target="blank">
  78. <span title="GitHub">
  79. <ion-icon name="logo-github" style="pointer-events:none"></ion-icon>
  80. </span>
  81. </a>
  82. <!--https://mail.google.com/mail/u/0/?fs=1&[email protected]&tf=cm-->
  83. <a class="icons" href="mailto:[email protected]" target="blank">
  84. <span title="E-Mail">
  85. <ion-icon name="mail-outline" style="pointer-events:none"></ion-icon>
  86. </span>
  87. </a>
  88. </div>
  89. <!--Social Media Links Ende-->
  90. </div>
  91. </div>
  92. </body>
  93. </html>


下面是问题的屏幕截图:x1c 0d1x
正如您所看到的,一个类附加了“focused”类,而另一个类没有,但它们仍然都有背景颜色,即使只有带有“focused”类的按钮应该有背景颜色。

准确的预期行为

我希望所有浏览器的按钮都是这样的(这是Chrome的截图,它是基于chromium的)



正如你所看到的按钮有相同的背景颜色作为顶部栏

我所尝试的

我尝试过使用Autoprefixer CSS的供应商前缀,

  1. void button.offsetWidth;


在我的脚本中,在类更改后重新绘制,但没有任何效果。这种行为对我来说似乎很奇怪,也许是Safari中的一个bug?
以下是测试网站:https://dev.gabriel-haberlach.de/
这是网站的repo:https://github.com/github-gabriel/dev-portfolio/tree/master

62lalag4

62lalag41#

在Safari上默认为user agent stylesheet。尝试包括CSS重置,如meyerweb CSS resetnormalize.css,以删除这些默认值。Google“CSS重置与正常化”查看差异。
在这里查看答案:https://stackoverflow.com/a/12582723/4053359


的数据

相关问题