首页 > 解决方案 > 如何在图像边框上放置导航箭头

问题描述

我有一个“灯箱”类型的图像查看器,用于浏览一些图像。

图像具有不同的纵横比,我需要将箭头放在边缘。当我调整网页大小时,图像会跟随网页的大小,这非常好

然而,箭头只是漂浮在图像之外:(有什么想法吗?

body {
    background-image: url("../img/bg-masthead.jpg");
    height: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    background-attachment: fixed;
    margin: 0;
}

.modal {
    position: fixed;
    width: 100%;
    height: 1000%;
    background-color: rgba(0, 0, 0, 0.4);
    /* display: none; */
}

.modal-content {
    display: inline-block;
    width: 95%;
    height: 95%;
    position: fixed;
    top: 40px;
    left: 50%;
    transform: translate(-50%, 0);
}

img {
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.prev {
    top: 50%;
    left: 8px;
}

.close {
    top: 4px;
    right: 8px;
}

.next {
    top: 50%;
    right: 8px;
}

.arrow {
    position: absolute;
    color: white;
    font-weight: bold;
    font-size: 50px;
    cursor: pointer;
}
<!DOCTYPE html>
<html>
<title>Bilde galleri</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<head>
    <link rel="stylesheet" type="text/css" href="css/test.css">
</head>

<body>

<div id="lightBox" class="modal">
	<div class="modal-content" id="img_container">
		<img id="largeImg" src="images/2007/Malayisa/IMG_0243.jpg">
		<div class="prev arrow" onclick="plusSlides(-1)">&#10094;</div>
		<div class="next arrow" onclick="plusSlides(1)">&#10095;</div>
		<div class="close arrow" onclick="document.getElementById('lightBox').style.display='none'">&times;</div>
	</div>
</div>
	
</body>
</html>

标签: htmlcss

解决方案


推荐阅读