如何在图像中制作带有下一个/上一个箭头的幻灯片弹出窗口?

问题描述 投票:0回答:1

我想制作一个带有幻灯片的弹出窗口,但我有一个问题,我无法将导航箭头放置在图像容器内,因此当调整网站大小时,它们会保留在同一位置。

我想将导航箭头移动到此处(紫色表示我想要它们的位置)

这就是我想要的样子

网站显示我现在拥有的内容

HTML 片段:

<div id="popup" class="popup hidden">
  <div class="popup-content">
    <span id="closePopup" class="close">&times;</span>
    <button id="prevImage" class="nav-button">&lt;</button>
    <img id="popupImage" src="" alt="Project Image">
    <button id="nextImage" class="nav-button">&gt;</button>
    <div class="popup-text">
      <p id="popupName"></p>
      <p id="popupDescription"></p>
    </div>
  </div>
</div>

CSS 片段:

/* Popup */
.popup {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  overflow: auto;
  background-color: rgba(0,0,0,0.5);
}

.popup-content {
  background-color: #494949;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px;
  padding-top: 30px;
  padding-bottom: 30px;
  padding-left: 30px;
  border-radius: 20px;
  width: 70vw;
  max-width: 1600px;
  height: auto;
  max-height: 1000px;
  text-align: left;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  position: relative;
}

#popupImage {
  width: 55%; 
  height: auto;
  border-radius: 20px;
  margin-right: 8%;
  position: relative;
}

#popupName {
  font-size: 3vh;
  font-weight: bold;
  margin-bottom: 10px;
}

#popupDescription {
  font-size: 2vh;
}


/* Navigation Buttons */
.nav-button {
  background-color: transparent;
  border: none;
  color: #fff;
  font-size: 2em;
  cursor: pointer;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
}

#prevImage {
  left: 1.5%;
}

#nextImage {
  right: 1.5%;
}
javascript html css popup web-frontend
1个回答
0
投票

与将弹出窗口名称和描述放入包含

div
元素的方式类似,您可以将下一个/上一个按钮和图像放入另一个
div
容器中,并相对于 it 而不是整体内容绝对定位按钮容器。

示例:

<div id="popup" class="popup hidden">
  <div class="popup-content">
    <span id="closePopup" class="close">&times;</span>

    <div id="image-container">
      <button id="prevImage" class="nav-button">&lt;</button>
      <img
        id="popupImage"
        src="...."
        alt="Project Image"
      />
      <button id="nextImage" class="nav-button">&gt;</button>
    </div>

    <div class="popup-text">
      <p id="popupName">....</p>
      <p id="popupDescription">....</p>
    </div>
  </div>
</div>
...

.popup-content {
  color: #dddddd;
  background-color: #494949;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 20px;
  padding-top: 30px;
  padding-bottom: 30px;
  padding-left: 30px;
  border-radius: 20px;
  width: 70vw;
  max-width: 1600px;
  height: auto;
  max-height: 1000px;
  text-align: left;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  position: relative;
  gap: 8%; /* <-- add "padding" here */
}

...

#popupImage {
  border-radius: 20px;
  /* margin-right: 8%; remove */
  position: relative;
}

...

#image-container {
  height: auto;
  position: relative;
}

...

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.