【问题标题】:Background URL, only one images works背景网址,只有一张图片有效
【发布时间】:2018-07-23 05:35:39
【问题描述】:

我仍在学习 HTML/CSS/Js 并在 youtube 上关注本教程。

https://www.youtube.com/watch?v=7MDJtw3ZF-4&t=893s

我的问题是在 20:15 左右的时间戳,我的 eyes.png 没有出现。我觉得这很奇怪,因为我的 face.png 显示得非常好,它位于同一个文件夹中。

<p class="location"></p>

<div class="container">
    <div class="face_body">
        <div class="face">
            <div class="eye_pan">
                <div class="pan_area">

                        <div class="eye eye_l">
                            <div class="eye eye_r">

                            </div>
                        </div>


                </div>
            </div>
        </div>
    </div>
</div>

还有我的css

    html,body, .container{
  height: 100%;
  width: 100%;
  outline: 0px;
  margin: 0px;
  padding: 0px;
  border: 0px;
}

.location{
  position: fixed;
  top: 0px;
  right: 0px;
  margin: 0px;
  background: rgba(255,255,255,0.4);
  padding: 10px;
}

.container{
  display: table;
  background: rgb(251,220,0);
  background: -webkit-linear-gradient(rgb(251,220,0), rgb(255,197,17));
  background: -o-linear-gradient(rgb(251,220,0), rgb(255,197,17));
  background: -moz-linear-gradient(rgb(251,220,0), rgb(255,197,17));;
  background: linear-gradient(rgb(251,220,0), rgb(255,197,17));
}

.face_body{
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  width: 100%;
}

.face{
  height: 200px;
  width: 200px;
  margin: auto;    
  background: url(images/face1.1.png);
  background-size: 173px 200px;
  background-repeat: no-repeat;
}

.eye_pan{
  display: table;
  padding: 30px 50px;
}

.pan_area{
  width: 70px;
  height: 55px;
  position: relative;
}

.eye{
  height: 20px;
  width: 20px;
  border-radius: 5px;
  position: absolute;
  margin-left: 5px;
  transition: .5s height ease-in-out;
  border: 1px solid red;
  background: url(images/eyes.png);
}

.eye_r{
  top: 0px;
  left: 20px;
}

.eye_l{
  top: 50px;
  left: 25px;
}

我的 eye.png 没有显示的任何原因都很好。谢谢。

【问题讨论】:

  • 检查显而易见的。您的代码和文件中的拼写是否相同?眼睛png是否在预期的位置。使用浏览器开发人员工具 (F12) 及其网络选项卡查看资源是否已找到。然后使用元素检查工具检查“眼睛”元素,看看应用了哪些样式。

标签: javascript jquery html css image


【解决方案1】:

您的.eye 网址背景可能链接到错误的网址文件,或者它根本不在视图中。

尝试插入 background-size: cover; 或将其设置为 background-size(如果图像加载正常)。

html,body, .container{
  height: 100%;
  width: 100%;
  outline: 0px;
  margin: 0px;
  padding: 0px;
  border: 0px;
}

.location{
  position: fixed;
  top: 0px;
  right: 0px;
  margin: 0px;
  background: rgba(255,255,255,0.4);
  padding: 10px;
}

.container{
  display: table;
  background: rgb(251,220,0);
  background: -webkit-linear-gradient(rgb(251,220,0), rgb(255,197,17));
  background: -o-linear-gradient(rgb(251,220,0), rgb(255,197,17));
  background: -moz-linear-gradient(rgb(251,220,0), rgb(255,197,17));;
  background: linear-gradient(rgb(251,220,0), rgb(255,197,17));
}

.face_body{
  display: table-cell;
  vertical-align: middle;
  text-align: center;
  width: 100%;
}

.face{
  height: 200px;
  width: 200px;
  margin: auto;    
  background: url(https://images.vexels.com/media/users/3/134743/isolated/preview/97ae591756f3dc69db88c09fd097319a-sad-face-emoji-emoticon-by-vexels.png);
  background-size: 173px 200px;
  background-repeat: no-repeat;
}

.eye_pan{
  display: table;
  padding: 30px 50px;
}

.pan_area{
  width: 70px;
  height: 55px;
  position: relative;
}

.eye{
  height: 20px;
  width: 20px;
  border-radius: 5px;
  position: absolute;
  margin-left: 5px;
  transition: .5s height ease-in-out;
  border: 1px solid red;
  background: url(//cdn.playbuzz.com/cdn/e732686f-35b2-4be6-a5fa-52f388bb0d0d/3637262a-2c14-43b0-9be2-b2174055f790_560_420.jpg);
  background-size:cover;
}

.eye_r{
  top: 0px;
  left: 20px;
}

.eye_l{
  top: 50px;
  left: 25px;
}
<p class="location"></p>

<div class="container">
    <div class="face_body">
        <div class="face">
            <div class="eye_pan">
                <div class="pan_area">

                        <div class="eye eye_l">
                            <div class="eye eye_r">

                            </div>
                        </div>


                </div>
            </div>
        </div>
    </div>
</div>

【讨论】:

    【解决方案2】:

    检查您的拼写是否正确,例如“eye”而不是“eyes”,如果文件格式是“jpg”而不是“png”,请检查文件格式。

    尝试清除浏览器缓存,以防浏览器未加载新文件

    【讨论】:

    【解决方案3】:

    background属性应用正确的CSS语法并检查你的图片路径是否正确。

    background: url('images/eyes.png');
    

    试试这个,如果问题仍然存在,请告诉我。

    祝你有美好的一天,干杯!!!

    【讨论】:

    • 我的第一个图像背景实际上遇到了同样的问题,因为图像路径不是从我的 CSS 文件所在的位置开始的。所以在我修复了我的 face.png 之后终于出现了。由于我的 eyes.png 和 face.png 在同一个文件夹中,我不明白为什么它不会显示,我相信语法是正确的。即使有和没有引号。
    • 您好,您可以在浏览器上检查并检查您的 eye.png 是否正确加载。从中您可以确认您的图像路径是否正确。检查并给我留言。
    猜你喜欢
    • 2020-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多