css 某些移动的设备上的响应式网页布局中断-需要确保跨设备兼容性

von4xj4u  于 2023-06-25  发布在  其他
关注(0)|答案(1)|浏览(169)

尽管实现了CSS媒体查询,我在某些移动的设备上实现主页的响应**困难。虽然该网站在某些手机上运行良好,但在其他手机上,元素重叠,文本被切断,按钮被扭曲,整体布局变得无法使用。我需要帮助,以确定根本原因和潜在的解决方案,以确保跨设备兼容我的网页。

验证码:

  1. <!DOCTYPE html>
  2. <html lang='eng'>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <title>FITIFY || Fitness Tracker</title>
  6. <!--Bootstrap Scripts(CSS)-->
  7. <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css' rel='stylesheet' integrity='sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65' crossorigin='anonymous'>
  8. <!--Awesome Fonts-->
  9. <script src="https://kit.fontawesome.com/fd6cc398e6.js" crossorigin="anonymous"></script>
  10. <!--Google Fonts-->
  11. <link rel="preconnect" href="https://fonts.googleapis.com">
  12. <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  13. <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@800&family=Roboto+Mono&family=Instrument+Sans&display=swap" rel="stylesheet">
  14. <!--CSS Styling-->
  15. <style>
  16. h1 {
  17. color: gold;
  18. font-family: 'Open Sans', sans-serif;
  19. font-weight: bolder;
  20. }
  21. h2,
  22. h3 {
  23. color: white;
  24. margin: 6%;
  25. text-align: center;
  26. font-family: 'Instrument Sans', sans-serif;
  27. font-size: 40px;
  28. font-weight: bold;
  29. }
  30. h5 {
  31. background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
  32. -webkit-background-clip: text;
  33. -webkit-text-fill-color: transparent;
  34. background-clip: text;
  35. }
  36. a {
  37. text-decoration: none;
  38. color: white;
  39. margin: 3%;
  40. }
  41. .nav-brand {
  42. margin: 1%;
  43. color: white;
  44. }
  45. .btn {
  46. background-color: #19376D;
  47. }
  48. .btn:hover {
  49. background-color: green;
  50. font-weight: bold;
  51. }
  52. .nav-links {
  53. width: 40%;
  54. margin-right: 0%;
  55. }
  56. .dropdown {
  57. display: inline-block;
  58. }
  59. .main-box {
  60. background: linear-gradient(to bottom right, #3d97ce 0%, #12debb 100%);
  61. width: 100%;
  62. height: 500px;
  63. border-bottom: solid black 3px;
  64. margin-top: 7%;
  65. position: relative;
  66. }
  67. .main-text-box {
  68. float: left;
  69. width: 50%;
  70. height: 100%;
  71. }
  72. #main-para {
  73. color: white;
  74. text-align: left;
  75. margin: 2% 2% 2% 10%;
  76. font-size: 22px;
  77. visibility: hidden;
  78. font-weight: 400;
  79. }
  80. .main-image-box {
  81. float: right;
  82. width: 50%;
  83. height: 100%;
  84. }
  85. #main-img {
  86. width: 80%;
  87. height: 80%;
  88. margin: 5%;
  89. border: white solid 3px;
  90. }
  91. #to-features {
  92. background-color: black;
  93. color: white;
  94. border: solid 2.5px;
  95. border-image-slice: 1;
  96. border-image-source: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
  97. width: 10%;
  98. height: 10%;
  99. position: absolute;
  100. margin: 0% 40% 0% 20%;
  101. bottom: 10%;
  102. font-family: 'Instrument Sans', sans-serif;
  103. font-size: 20px;
  104. font-weight: bold;
  105. }
  106. .feature-box {
  107. background: linear-gradient(to top right, #3d97ce 0%, #12debb 100%);
  108. background-size: cover;
  109. height: auto;
  110. }
  111. .card {
  112. color: black;
  113. background-color: white;
  114. width: 21%;
  115. height: 250px;
  116. margin: 14% 2% 10% 2%;
  117. }
  118. .row {
  119. margin-right: 0%;
  120. }
  121. .cards-btn {
  122. background-color: black;
  123. color: white;
  124. border: solid 3px;
  125. border-image-slice: 1;
  126. border-image-source: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet);
  127. padding: 2%;
  128. margin: 50px 10% 2% 20%;
  129. font-family: 'Instrument Sans', sans-serif;
  130. font-size: 13px;
  131. font-weight: bold;
  132. }
  133. .cards-btn:hover {
  134. color: green;
  135. }
  136. @media screen and (min-width: 300px) and (max-width: 650px) {
  137. /*targets mobile devices */
  138. h1 {
  139. font-size: 1.4rem;
  140. }
  141. h2 {
  142. font-size: 2rem;
  143. margin-bottom: 10%;
  144. }
  145. .nav-brand {
  146. width: 10%;
  147. }
  148. a {
  149. margin: 0.5%;
  150. font-size: 0.7rem;
  151. }
  152. .nav-links {
  153. width: 75%;
  154. }
  155. .btn {
  156. font-size: 45%;
  157. }
  158. .main-box {
  159. margin-top: 12%;
  160. height: 100vh;
  161. }
  162. .main-text-box {
  163. width: 100%;
  164. }
  165. #main-para {
  166. font-size: 1.3rem;
  167. }
  168. .main-image-box {
  169. display: none;
  170. }
  171. #to-features {
  172. width: 40%;
  173. height: 6%;
  174. padding: 1%;
  175. margin: 10% 20% 0% 30%;
  176. bottom: 17%;
  177. }
  178. .card {
  179. width: 60%;
  180. margin: 15% 20% 5% 20%;
  181. }
  182. #goal-btn {
  183. padding: 1%;
  184. margin-left: 10%;
  185. }
  186. }
  187. @media screen and (min-width: 651px) and (max-width: 1200px) {
  188. h1 {
  189. font-size: 3rem;
  190. }
  191. h2 {
  192. font-size: 4rem;
  193. }
  194. a {
  195. margin: 2%;
  196. font-size: 1.5rem;
  197. }
  198. .nav-links {
  199. margin: 0%;
  200. width: 75%;
  201. }
  202. .btn {
  203. font-size: 1.5rem;
  204. margin-right: 1%;
  205. }
  206. .main-box {
  207. margin-top: 8%;
  208. height: 100vh;
  209. }
  210. .main-text-box {
  211. width: 100%;
  212. }
  213. #main-para {
  214. font-size: 40px;
  215. }
  216. .main-image-box {
  217. display: none;
  218. }
  219. #to-features {
  220. width: 30%;
  221. height: 9%;
  222. padding: 1%;
  223. margin: 8% 20% 0% 35%;
  224. }
  225. .card {
  226. width: 30%;
  227. margin: 15% 10% 5% 35%;
  228. }
  229. #goal-btn {
  230. margin-left: 10%;
  231. }
  232. }
  233. @media screen and (min-width: 1800px) and (max-width: 2600px) {
  234. /* 4k */
  235. h1 {
  236. font-size: 6rem;
  237. }
  238. h2 {
  239. font-size: 5rem;
  240. font-weight: bolder;
  241. }
  242. a {
  243. margin: 5%;
  244. font-size: 3rem;
  245. }
  246. .nav-links {
  247. margin: 0%;
  248. width: 55%;
  249. }
  250. .btn {
  251. font-size: 3rem;
  252. margin-right: 10%;
  253. }
  254. .main-box {
  255. margin-top: 6%;
  256. height: 100vh;
  257. }
  258. #main-para {
  259. font-size: 60px;
  260. }
  261. #to-features {
  262. width: 20%;
  263. height: 9%;
  264. padding: 1%;
  265. font-size: 40px;
  266. margin: 10% 0% 0% 15%;
  267. }
  268. .card {
  269. width: 20%;
  270. margin: 15% 10% 5% 35%;
  271. }
  272. .card {
  273. width: 20%;
  274. height: 250px;
  275. margin: 15% 3% 10% 2%;
  276. }
  277. #goal-btn {
  278. margin-left: 10%;
  279. }
  280. }
  281. </style>
  282. </head>
  283. <body>
  284. <header>
  285. <nav class="navbar bg-dark fixed-top" data-bs-theme="dark">
  286. <div class="nav-brand">
  287. <h1>FITIFY</h1>
  288. </div>
  289. <div class="nav-links">
  290. <a href="./index.html">HOME</a>
  291. <div class="dropdown">
  292. <button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
  293. FEATURES
  294. </button>
  295. <ul class="dropdown-menu gap-1 p-2 rounded-3 mx-0 shadow w-220px" data-bs-theme="light">
  296. <li><a class="dropdown-item rounded-2" href="./bmi.html">BMI CALCULATOR</a></li>
  297. <li><a class="dropdown-item rounded-2" href="./calories.html">TRACK CALORIES</a></li>
  298. <li><a class="dropdown-item rounded-2" href="./goal.html">KNOW YOUR GOAL</a></li>
  299. <li><a class="dropdown-item rounded-2" href="./basic_redirect.html">STORE YOUR DETAILS</a></li>
  300. </ul>
  301. </div>
  302. <a href="./about.html">ABOUT US</a>
  303. <a href="./contacts.html">CONTACT US</a>
  304. </div>
  305. </nav>
  306. </header>
  307. <main>
  308. <div class="main-box">
  309. <div class="main-text-box">
  310. <h2>Transform yourself today.</h2>
  311. <p id="main-para">"Welcome to Fitify, your ultimate fitness companion! We are dedicated to helping you on your fitness journey by providing powerful tools to track your progress. With our user-friendly interface achieving your health and fitness goals has never
  312. been easier. Join our community today and take the first step towards a healthier, fitter you!"</p>
  313. <button id="to-features">GET FIT</button>
  314. </div>
  315. <div class="main-image-box"> //This div will be hidden on mobile devices
  316. <img src="./nutri.webp" id="main-img" alt="Display Image">
  317. </div>
  318. </div>
  319. <div class="feature-box">
  320. <div class="row">
  321. <div class="card">
  322. <i class="fa-sharp fa-solid fa-dumbbell"></i>
  323. <div class="card-body">
  324. <h5 class="card-title">CALCULATE YOUR BMI</h5>
  325. <p class="card-text">Calculate your Body Mass Index (BMI) to know your health status right away.</p><br>
  326. <a href="./bmi.html" class="cards-btn">CALCULATE</a>
  327. </div>
  328. </div>
  329. <div class="card">
  330. <i class="fa-solid fa-utensils"></i>
  331. <div class="card-body">
  332. <h5 class="card-title">TRACK YOUR CALORIES</h5>
  333. <p class="card-text">Track your calories for the day and know how much you consumed today.</p>
  334. <a href="./calories.html" class="cards-btn">TRACK NOW</a>
  335. </div>
  336. </div>
  337. <div class="card">
  338. <i class="fa-solid fa-person-dress"></i>
  339. <div class="card-body">
  340. <h5 class="card-title">YOUR IDEAL WEIGHT</h5>
  341. <p class="card-text">Calculate your ideal weight by entering your measurements.</p><br>
  342. <a href="./goal.html" class="cards-btn" id="goal-btn">KNOW YOUR GOAL</a>
  343. </div>
  344. </div>
  345. <div class="card">
  346. <i class="fa-solid fa-info"></i>
  347. <div class="card-body">
  348. <h5 class="card-title">STORE YOUR BASIC DETAILS</h5>
  349. <p class="card-text">Keep a log of your basic information in our secure database.</p>
  350. <a href="./basic_redirect.html" class="cards-btn">STORE DETAILS</a>
  351. </div>
  352. </div>
  353. </div>
  354. </div>
  355. </main>
  356. <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js" integrity="sha384-oBqDVmMz9ATKxIep9tiCxS/Z9fNfEXiDAYTujMAeBAsjFuCZSmKbSSUnQlmh/jp3" crossorigin="anonymous"></script>
  357. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha2/dist/js/bootstrap.min.js" integrity="sha384-heAjqF+bCxXpCWLa6Zhcp4fu20XoNIA98ecBC1YkdXhszjoejr5y9Q77hIrv8R9i" crossorigin="anonymous"></script>
  358. <script>
  359. const button = document.getElementById('to-features');
  360. window.onload = function() {
  361. var para = document.getElementById("main-para");
  362. var para_text = para.innerHTML;
  363. var speed = 15;
  364. var i = 0;
  365. para.innerHTML = "";
  366. function typeWriter_para() {
  367. if (i < para_text.length) {
  368. para.innerHTML += para_text.charAt(i);
  369. i++;
  370. setTimeout(typeWriter_para, speed);
  371. }
  372. }
  373. setTimeout(typeWriter_para, 100); // Delay before starting the paragraph animation
  374. para.style.visibility = "visible"; // Make the paragraph visible
  375. };
  376. const feature_box = document.querySelector('.feature-box');
  377. button.addEventListener('click', function() {
  378. feature_box.scrollIntoView();
  379. });
  380. </script>
  381. </body>
  382. </html>
mi7gmzs6

mi7gmzs61#

您可以通过使用媒体查询和纵横比来处理响应问题。请参见下面的语法。根据纵横比,您的Web应用程序的响应速度将通过使用以下格式来覆盖。

  1. @media (min-aspect-ratio: 2/3) and (orientation: portrait) {}
  2. @media (min-aspect-ratio: 2/3) and (orientation: landscape) {}
  3. @media (min-aspect-ratio: 9/16) and (orientation: landscape) {}
  4. @media (min-aspect-ratio: 9/16) and (orientation: portrait) {}

相关问题