javascript - 将按钮放在图像 html 的顶部
问题描述
我有这个:
var myIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 3000); // Change image every 2 seconds
}
.mySlides {
/* max-width: 540px; */
display: none;
height: 100vh;
width: 100%;
background: repeat scroll center center / cover;
}
@media only screen and (max-width: 600px) {
.mySlides {
display: none;
max-width: 540px;
height: 50vh;
background: repeat scroll center center / cover;
}
}
<div id="headerr" class="home">
<div class="w3-content w3-section">
<img class="mySlides" src="https://images.unsplash.com/photo-1629199022827-eede3c3df471?ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60" style="width:100%">
<img class="mySlides" src="https://images.unsplash.com/photo-1629220608817-0802c373e110?ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzfHx8ZW58MHx8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60" style="width:100%">
</div>
</div>
基本上,我想要的是learn more
在图像上放一个按钮,就像左下角一样。我只尝试了一个标准按钮,但它就在图像的正上方。我该怎么做呢?
解决方案
将您的图像放入单独的div
并给 div 一个position: relative
现在将您的按钮放在该 div 和其 CSS 中,将其位置设置为position: absolute
. 这将根据容器 div 调整您的按钮。
现在,您可以随意设置按钮的位置,例如在您的按钮类中添加以下 CSStop: 5px; right: 50px
推荐阅读
- javascript - 如何在 javascript 中拆分此字符串?
- c - 为什么要区分 BSS 和 COMMON 部分?
- swift - 如何从 macOS APP 在 LaunchAgents 中创建守护进程?
- javascript - 如何将 javascript 函数添加到 QML 属性?
- google-chrome - 每个站点设置的第三方 cookie?
- android - React Native - App Registry 未注册模块和未定义 NavigationTabs 错误 - 顶级导航器教程
- android - 小部件在模拟器中改变位置
- authentication - 如何让 Delphi 从默认浏览器读取登录的网页 - 而不是 twebbrowser
- c# - 如何在 blazor wabassembly 应用程序中找到错误(很难找到错误)
- python - Python - 在 google colab 中使用多线程播放音频