html - 在元素的左右放置箭头
问题描述
我在中心有一个图标,左右有两个箭头来滚动浏览现有的图标。我希望图标两侧的箭头水平定位在图标本身的中心。我能怎么做?这样,箭头位于右上角和左上角,图标显示在中间但较低的位置。
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
.increase {
float: right;
cursor: pointer;
}
.decrease {
float:left;
margin: 0px 15px 15px 0px;
cursor: pointer;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#contenitore {
width: 60%;
background-color: blue;
}
img {
max-width: 100%;
height: auto;
}
img:hover {
width: 310px;
height: auto;
}
.mySlides {
display:flex;
width: 300px;
height: 300px;
border-radius: 50%;
margin: auto;
top:250px;
left:0;
right:0;
bottom:0;
position: absolute;
}
<!-- Icons fontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<header class="ricerca">
<div class="container">
<div class="row">
<div class="col-sm-12 align-self-center">
<span class="decrease" onclick="plusDivs(-1)" value="Decrease Value"><i class="fas fa-chevron-circle-left" style="font-size:50px;"></i></span>
<div class="w3-tooltip">
<img class="mySlides" shadow-lg p-3 mb-5 src="https://image.flaticon.com/icons/png/512/945/945170.png" ";>
</div>
<span class="increase" onclick="plusDivs(1)" value="Increase Value"><i class="fas fa-chevron-circle-right" style="font-size:50px;"></i></span>
</div>
</div>
</div>
</header>
解决方案
在您的情况下,我认为position: abosolute
在图标上进行样式设置不是一个明智的主意。我将其更改为.icon-container
. 你可以看看它是否有帮助。
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
.increase {
float: right;
cursor: pointer;
}
.decrease {
float:left;
margin: 0px 15px 15px 0px;
cursor: pointer;
}
span {
display: inline-block;
vertical-align: middle;
line-height: normal;
}
#contenitore {
width: 60%;
background-color: blue;
}
img {
max-width: 100%;
height: auto;
}
img:hover {
width: 310px;
height: auto;
}
.icon-container {
display: flex;
align-items: center;
justify-content: space-between;
}
.mySlides {
width: 300px;
height: 300px;
border-radius: 50%;
margin: auto
}
<!-- Icons fontAwesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<header class="ricerca">
<div class="container">
<div class="row">
<div class="icon-container col-sm-12 align-self-center">
<span class="decrease" onclick="plusDivs(-1)" value="Decrease Value"><i class="fas fa-chevron-circle-left" style="font-size:50px;"></i></span>
<div class="w3-tooltip">
<img class="mySlides shadow-lg p-3 mb-5" src="https://image.flaticon.com/icons/png/512/945/945170.png">
</div>
<span class="increase" onclick="plusDivs(1)" value="Increase Value"><i class="fas fa-chevron-circle-right" style="font-size:50px;"></i></span>
</div>
</div>
</div>
</header>
推荐阅读
- r - 如何使用 R DBI 保护数据库用户名和密码?
- java - 在 Word with Java 中将页码设置为从给定数字开始
- javascript - js 代码在 html 中不能作为单独的文件工作(没有 jQuery)
- r - R中组之间的平均值
- javascript - swal警报后jquery引导模式关闭
- angular - 获取 Promise 在 ionic 框架上返回的元素数量
- ruby-on-rails - 通过 Rails 中的方法查询 SQL 或 AREL
- ssl - ssl_bump 在wireshark 中应该看起来有多成功?
- python - 大查询数据流加载到 NULL 分区
- python - 异常处理——整个脚本的最终例程