2-1 通过阴影

image.png

  1. <style>
  2. .overlay {
  3. /* 用于遮挡背景 */
  4. position: fixed;
  5. top: 0;
  6. right: 0;
  7. bottom: 0;
  8. left: 0;
  9. background: rgba(0, 0, 0, .8);
  10. }
  11. .lightbox {
  12. /* 需要吸引用户注意的元素 */
  13. position: absolute;
  14. z-index: 1;
  15. /* [其余样式] */
  16. width: 200px;
  17. height: 100px;
  18. background-color: white;
  19. top:50%;
  20. left:50%;
  21. transform: translate(-50%,-50%);
  22. }
  23. </style>