简体   繁体   English

图片未显示在弹出窗口中(CSS,HTML,Javascript)

[英]Image not showing in pop-up (CSS,HTML,Javascript)

Currently, I am building a website and I am running into a problem. 目前,我正在建立网站,但遇到了问题。 I am fairly new to the world of CSS, HTML, Javascript so perhaps this is a no brainer for most of you but I face the following problem. 我对CSS,HTML,Javascript领域还不是很陌生,所以对于大多数人来说,这也许毫无道理,但我面临以下问题。 I would like to have an image in a pop-up, however the image is not showing (called 'ErrorImage' in the snippet). 我想在弹出窗口中显示图片,但是该图片未显示(在代码段中称为“ ErrorImage”)。 I've checked whether the file-path of the image is correct, and it is. 我检查了图像的文件路径是否正确。 Please view the snippets below. 请查看下面的片段。 Any help? 有什么帮助吗?

 // 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> 

It's working but your image is off screen. 它正在工作,但是图像不在屏幕上。 Just make a few changes in your CSS: 只需在CSS中进行一些更改即可:

 // 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; left: 0; z-index: 1; 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="https://placeholdit.imgix.net/~text?txtsize=63&bg=FF6347&txtclr=ffffff&txt=About-Image&w=350&h=250" alt="About"> </a> <span class="popuptext" id="myPopup"><img src="https://placeholdit.imgix.net/~text?txtsize=63&bg=FF6347&txtclr=ffffff&txt=Error-Image&w=350&h=250"><p>Example text</p></span> </div> 

It was showing but your left was -50% that is why it was going out of the screen. 它正在显示,但是您的左边是-50%,这就是它离开屏幕的原因。 i have adjusted it accordingly so it shows on the screen. 我已经对其进行了相应的调整,使其在屏幕上显示。 hope this helps. 希望这可以帮助。 thanks 谢谢

 // 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> 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM