【问题标题】:Picture Tag Not Showing Image, Reads "Source 0x0"图片标签不显示图像,读取“源 0x0”
【发布时间】:2019-03-24 21:27:23
【问题描述】:

我的客户强调他们网站中的图像模糊,因此我正在尝试解决此问题。根据我的研究,一种方法是使用<picture> 标签为每个设备(小、中、大)创建不同大小的图像。但是,在使用开发人员工具时,我的图像根本不显示,"Source 0x0." 说,在移动设备或平板设备上,总是选择默认图像而不是适当的图像。我已经研究过这个问题,但找不到适合我的案例的适当答案。我什至试图改变我的道路,没有。我只在这部分使用 HTML。任何帮助表示赞赏。

另外,如果有人可以推荐一种更有效的方法来使图像更清晰、更模糊,请指出正确的方向。我听说过使用 SVG,但我找不到关于这种方法的可靠建议。

HTML

    <div class="view3">
        <div class="content5_items">
            <h1 class="text-center">Sign Up</h1>
            <br>
            <p class="text-center">Join Wanzeru Now</p>
            <br>
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-6 col-sm-6 d-flex justify-content-end">
                        <picture>
                             <source media="(max-width: 480px)" srcset="img/sign_upSmall.png">
                             <source media="(max-width: 768px)" srcset="img/sign_upMed.png">
                            <img src="img/sign_up.png" alt="pic"> <!--this image is only being applied -->
                        </picture>

                    </div>
                    <div class="col-md-6 justify-content-md-start justify-content-center d-flex text-center" style="margin-top: 50px;">
                        <form>
                            <div class="form-group">
                                <input type="name" class="form-control" id="exampleInputName" aria-describedby="emailHelp" placeholder="Name">
                            </div>
                            <div class="form-group">
                                <input type="email" class="form-control" id="exampleInputEmail" placeholder="Email">
                            </div>
                            <button type="submit" class="btn" style="background-color: #D34ED5; color:#fff; margin-bottom: 70px; width: 190px;">Sign up</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

【问题讨论】:

    标签: html image responsive-design responsive


    【解决方案1】:

    由于这一行,您会收到该错误:

    <!--<img src="img/sign_up.png" alt="pic">-->
    

    必须在你的picture 中有一个img 标签,否则什么都不会渲染。如果您取消注释该行,它应该可以工作。另外,您在上面的几行中有错字:

    <source media="(max-with: 480px)" srcset="img/sign_upSmall.png">
    

    应该是:

    <source media="(max-width: 480px)" srcset="img/sign_upSmall.png">
    

    来自HTML spec

    picture 元素内容模型: 零个或多个 &lt;source&gt; 元素,后跟一个 &lt;img&gt; 元素。

    下面的工作 sn-p 与上面的代码几乎相同的简单示例:

    <picture>
      <source
        media="(max-width: 480px)"
        srcset="https://source.unsplash.com/random/200x200"
      >
      <source
        media="(max-width: 768px)"
        srcset="https://source.unsplash.com/random/400x400"
      >
      <img src="https://source.unsplash.com/random/600x600">
    </picture>

    在 devtools 中检查 sn-p 上方,清除显示最小图像 (200x200) 并且 source 标记仍然具有 0 宽度和 0 高度:

    【讨论】:

    • 感谢您的回复。我注释掉了那个代码,因为我想看看那些小的,med 图像是否甚至注册。现在我知道需要 标记,我取消了它的注释。然而,正在发生的事情是小的,med 图像甚至没有用于 ipad 或移动设备,它仅用于 图像。我会更新我的帖子
    • @Alexandra 您的代码中仍有错字。另外,您的代码完全没问题,我认为您很困惑,因为您看到的是“source | 0x0”,但您的源标签将始终具有 0 宽度和 0 高度。源标签永远不会在页面上呈现,它们只是替换图片标签中 img 元素的源。
    • 但是,当我在开发工具中单击图像时,它会显示默认图像的尺寸。当我突出显示小的中型图像的代码时,它显示源 0x0。
    • 它总是说“source | 0x0”,包括它工作的时间。 source 标签永远不会在页面上呈现。我已经用工作的 sn-p 更新了我的答案,请运行工作的 sn-p 并在 devtools 中检查它以亲自查看。
    猜你喜欢
    • 2019-02-22
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多