簡體   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