繁体   English   中英

如何迫使内容不被压低以显示div?

[英]How to force content to be not pushed down on showing a div?

当我单击按钮时,如何强制图像和内容不被按下?

  showRedDiv = () => { const el = document.querySelector('#redDiv'); el.style.display = "block"; }; 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div style=" border: 3px solid gold; height: 50px;"></div> <div style=" border: 3px solid red; height: 50px; display: none;" id="redDiv">This should be overlayed on the image </div> <img src="https://image.shutterstock.com/image-photo/white-transparent-leaf-on-mirror-260nw-577160911.jpg"> <br> <button onclick="showRedDiv()"> Show Red Div </button> </body> </html> 

#redDiv {
  position: absolute;
}

确实还有更多CSS问题,但postion: absolute会导致它overlay

 showRedDiv = () => { const el = document.querySelector('#redDiv'); el.style.display = "block"; }; 
 #redDiv { position: absolute; } 
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div style=" border: 3px solid gold; height: 50px;"></div> <div style=" border: 3px solid red; height: 50px; display: none;" id="redDiv">This should be overlayed on the image </div> <img src="https://image.shutterstock.com/image-photo/white-transparent-leaf-on-mirror-260nw-577160911.jpg"> <br> <button onclick="showRedDiv()"> Show Red Div </button> </body> </html> 

暂无
暂无

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

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