.image-container { position: relative; display: inline-block; } .navigation-buttons { position: absolute; top: 50%; transform: translateY(-50%); width: 100%; text-align: center; } .prev-button, .next-button { background-color: #333; color: #fff; padding: 10px 20px; border: none; border-radius: 4px; margin: 0 10px; cursor: pointer; } .prev-button:hover, .next-button:hover { background-color: #555; } echo " <div class='image-container'> <img src='data:image/jpeg;base64,$show_image' alt='图片'> <div class='navigation-buttons'> <button class='prev-button'>上一张</button> <button class='next-button'>下一张</button> </div> </div> ";怎么使图片也居中显示
时间: 2024-02-14 08:16:47 浏览: 61
react-navigation-header-buttons:轻松呈现标题按钮以进行react-navigation
要让图片也居中显示,可以在 `.image-container` 中添加 `text-align: center;` 属性,这样图片就会水平居中显示了。修改后的 CSS 代码如下:
```css
.image-container {
position: relative;
display: inline-block;
text-align: center;
}
.navigation-buttons {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
text-align: center;
}
.prev-button,
.next-button {
background-color: #333;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 4px;
margin: 0 10px;
cursor: pointer;
}
.prev-button:hover,
.next-button:hover {
background-color: #555;
}
```
这样就可以让图片和导航按钮同时居中显示了。
阅读全文