简体   繁体   English

CSS Grid 在实际移动设备上无法正常工作的问题。 在 Chrome/Firefox 开发工具中进行测试时,代码运行良好

[英]Having an issue with CSS Grid not working properly on actual mobile device. The code works perfectly when testing within Chrome/Firefox dev tools

EDIT: Guys, I figured it out.编辑:伙计们,我想通了。 As the comments have suggested that I try debugging using Safari, which I hadn't done, I found that for whatever reason in my live code my.gallery-grid class in CSS had a "height: 100%" that was throwing things off for whatever reason.由于评论建议我尝试使用 Safari 进行调试,但我没有这样做,我发现无论出于何种原因,在我的实时代码中我的实时代码 my.gallery-grid class 中的 Z2C56C360580420D293172F42D850DFB61DZ 都让事情大吃一惊:“呵呵”无论出于何种原因。 So I erased that and changed my.card to have a height of auto instead of leaving the "max-height: 100%".所以我删除了它并将 my.card 更改为 auto 的高度,而不是离开“max-height: 100%”。 That seemed to work perfectly and is now working within Safari iOS, Chrome, and Firefox.这似乎工作得很好,现在正在 Safari iOS、Chrome 和 Firefox 中工作。 Thank you Ben Souchet for the suggestion!谢谢本·苏切特的建议!

I recently finished creating an image gallery that uses CSS Grid and works perfectly fine when I use the dev tools on Firefox and within Chrome.我最近完成了创建一个使用 CSS 网格的图像库,并且当我在 Firefox 和 Chrome 中使用开发工具时工作得非常好。 It's only when I test the site on my actual phone (iPhone) when the gallery seems to crash.只有当我在我的实际手机(iPhone)上测试网站时,画廊似乎崩溃了。 Works great on desktop.在桌面上工作得很好。

Here's what it looks like on actual mobile这是它在实际手机上的样子

Here's what it's supposed to look like and how it looks when viewed through chrome/firefox dev tools这是它的外观以及通过 chrome/firefox 开发工具查看时的外观

My HTML code:我的 HTML 代码:

            <div id="trigger-view-button" class="gallery-grid">
                <div class="card">
                    <img src="css/images/gallery/gallery-img1.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img2.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img3.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img4.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img5.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img6.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img7.jpg" alt="">
                </div>
                <div class="card">
                    <img src="css/images/gallery/gallery-img8.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img9.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img10.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img11.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img12.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img13.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img14.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img15.jpg" alt="">
                </div>
                <div class="card-hidden">
                    <img src="css/images/gallery/gallery-img16.jpg" alt="">
                </div>
            </div>

My CSS code:我的 CSS 代码:

/*------- Gallery Photos -------*/

.gallery-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    grid-auto-rows: auto;
    padding: 0 1.5em;
}

.card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #353535;
    font-size: 3rem;
    color: #fff;
    box-shadow: rgba(3, 8, 20, 0.1) 0px 0.15rem 0.5rem, rgba(2, 8, 20, 0.1) 0px 0.075rem 0.175rem;
    max-height: 100%;
    width: 100%;
    border-radius: 4px;
    transition: all 500ms, opacity 1200ms;
    overflow: hidden;

    object-fit: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.card:hover {
    box-shadow: rgba(2, 8, 20, 0.1) 0px 0.35em 1.175em, rgba(2, 8, 20, 0.08) 0px 0.175em 0.5em;
    transform: translateY(-3px) scale(1.1);
}

.card-hidden {
    height: 0;
    visibility: hidden;
    opacity: 0;
}

.card-fade-in {
    height: auto;
    visibility: visible;
    opacity: 1;
}

My JS code (this allows the user to load about 8 more pictures onto the grid after clicking on a load more button. This explains why there's a card-hidden/card-fade-in class):我的 JS 代码(这允许用户在单击加载更多按钮后将大约 8 张图片加载到网格上。这解释了为什么有一个卡片隐藏/卡片淡入类):

$("#loadMore").click(function () {
    $(".card-hidden").toggleClass("card-hidden card card-fade-in");
    $("#loadMore").fadeOut("slow");
});

I've been looking around for a solution but it seems to be really tricky to find something when the dev tools show the grid working great while actual mobile does not.我一直在寻找解决方案,但是当开发工具显示网格运行良好而实际移动设备却没有时,似乎很难找到一些东西。 I have also checked for compatibility and safari seems to be compatible with the grid settings I'm using.我还检查了兼容性,safari 似乎与我正在使用的网格设置兼容。

Any suggestions would be great.任何建议都会很棒。 Thanks in advance.提前致谢。

I placed an edit on the question but I'll place the answer here too in order to "solve" the question.我对问题进行了编辑,但我也会将答案放在这里以“解决”问题。

I figured out the issue.我弄清楚了这个问题。 As the comments have suggested, I tried debugging using Safari, which I hadn't done, and I found that for whatever reason in my live code my.gallery-grid class in CSS had a "height: 100%" that was throwing things off for whatever reason.正如评论所建议的那样,我尝试使用 Safari 进行调试,但我没有这样做,我发现无论出于何种原因,在我的实时代码 my.gallery-grid class 中的 Z2C56C360580420D293172F42D100D293172F42D1000DFB 中都出现了“扔东西”出于任何原因关闭。 So I erased that and changed my.card to have a height of auto instead of leaving the "max-height: 100%".所以我删除了它并将 my.card 更改为 auto 的高度,而不是离开“max-height: 100%”。 That seemed to work perfectly and is now working within Safari iOS, Chrome, and Firefox.这似乎工作得很好,现在正在 Safari iOS、Chrome 和 Firefox 中工作。 Thank you Ben Souchet for the suggestion!谢谢本·苏切特的建议!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CSS可在chrome开发人员工具中使用,但不能在实际的移动设备上使用 - CSS works in chrome developer tools but not on actual mobile device CSS过滤器属性无法在Google Chrome上正常运行,但在Mozilla Firefox上可完美运行 - CSS filter Property not working properly on Google Chrome, but works perfectly on Mozilla Firefox JQuery&#39;.css&#39;在Firefox上无法正常运行-在Google Chrome上完美运行 - JQuery '.css' not functioning properly on Firefox - works perfectly on Google Chrome 移动网站在实际的 iPhone 12 VS chrome/firefox 开发工具上看起来不同? - Mobile site looks different on an actual iPhone 12 VS chrome/firefox dev tools? 按钮在开发工具上正确对齐,但在实际移动设备上不正确 - Button is aligned correctly on Dev tools, but incorrectly on actual mobile device Firefox的CSS问题,但可在Chrome中使用 - CSS issue with Firefox but works in Chrome Div在IE中无法正确对齐-在Firefox / Chrome中完美运行 - Div not aligning properly in IE - Works perfectly in Firefox/Chrome Chrome/Firefox 开发工具中没有模拟设备像素比? - Device pixel ratio not simulating in Chrome/Firefox dev tools? 在 Chrome Dev Tools 中模拟移动设备时,HTML 和 body 的大小有什么关系? - What is the deal with the size of HTML and body when simulating a mobile device in Chrome Dev Tools? Chrome 奇怪的 CSS 问题,在 Firefox 上工作正常 - Chrome weird CSS issue, works fine on Firefox
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM