javascript - 图像未在弹出窗口中显示(CSS、HTML、Javascript)

标签 javascript html css

目前,我正在构建一个网站,但遇到了一个问题。我对 CSS、HTML、Javascript 的世界相当陌生,所以也许这对你们大多数人来说都是轻而易举的事,但我面临以下问题。 我想在弹出窗口中显示一张图片,但是图片没有显示(在代码片段中称为“ErrorImage”)。我检查了图像的文件路径是否正确,是的。请查看下面的片段。有帮助吗?

// When the user clicks on div, open the popup
function myFunction() {
  var popup = document.getElementById("myPopup");
  popup.classList.toggle("show");
}
/* Popup container - can be anything you want */
.popup {
  position: relative;
  display: inline-block;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* The actual popup */
.popup .popuptext {
  visibility: hidden;
  width: 500px;
  background-color: #555;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 10px;
  position: absolute;
  z-index: 1;
  bottom: 60px;
  left: -50%;
  right: -50%;
  margin-left: -80px;
    opacity: 0.98;
    text-align: justify;
}

/* Toggle this class - hide and show the popup */
.popup .show {
  visibility: visible;
  -webkit-animation: fadeIn 1s;
  animation: fadeIn 1s;
}

/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
  from {opacity: 0;} 
  to {opacity: 1;}
}

@keyframes fadeIn {
  from {opacity: 0;}
  to {opacity:1 ;}
}   
<div class="popup" onclick="myFunction()">
    <a title="More about us">
        <img src="About.JPG" alt="About">
    </a>
    <span class="popuptext" id="myPopup"><img src="ErrorImage.JPG"<
        <p>Example text</p>
    </span>
</div> 

最佳答案

它正在显示,但您的左边是 -50%,这就是它超出屏幕的原因。我已经相应地调整了它,所以它显示在屏幕上。希望这可以帮助。谢谢

// When the user clicks on div, open the popup
function myFunction() {
  var popup = document.getElementById("myPopup");
  popup.classList.toggle("show");
}
/* Popup container - can be anything you want */
.popup {
  position: relative;
  display: inline-block;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* The actual popup */
.popup .popuptext {
  visibility: hidden;
  width: 500px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 10px;
    position: absolute;
    z-index: 1;
    bottom: 0;
    left: 0;
    right: 0;
    margin-left: 0;
    opacity: 0.98;
    text-align: justify;
    top: 100px;
    height: 40px;
}

/* Toggle this class - hide and show the popup */
.popup .show {
  visibility: visible;
  -webkit-animation: fadeIn 1s;
  animation: fadeIn 1s;
}

/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
  from {opacity: 0;} 
  to {opacity: 1;}
}

@keyframes fadeIn {
  from {opacity: 0;}
  to {opacity:1 ;}
}
<div class="popup" onclick="myFunction()">
            <a title="More about us">
                               about
            </a>
        <span class="popuptext" id="myPopup"><p>Example text</p></span>
</div>

关于javascript - 图像未在弹出窗口中显示(CSS、HTML、Javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54514652/

相关文章:

html - IE、Firefox 和 Google Chrome 的表格行 CSS 样式问题

html - 表格单元格显示的 div 宽度

html - 如何对 HTML 元素进行分组,以便它们在具有 "columns"样式的 div 中一起移动?

javascript - 通过祖 parent 的父类选择一个 css3 元素

javascript - Django 中的通用进度条

javascript - 如何在 javascript 中创建一个随机生成器,它将重定向到随机网站?

javascript - 在javascript中如何更改以下日期格式

javascript - Jquery Slider 左右滑动的问题

Android - Html.fromHtml 句柄背景颜色

asp.net - CSS 列表奇怪的行为