我想在项目的Flexbox图像网格的顶部放置一个图标(有点像this),但是我不知道该怎么做。如果图标是可单击的,那将是更可取的,这样在单击或类似图标时图像会变大。有人可以帮忙吗? 谢谢!
这是我的代码:
@import url('https://fonts.googleapis.com/css?family=Montserrat');
.heading {
display: inline-block;
font-family: "Montserrat";
font-weight: lighter;
text-align: left;
margin-left: 20vw;
line-height: 30vw;
}
body {
width: 100%;
margin: auto;
font-family: 'Montserrat', sans-serif;
background-color: white;
}
.container {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: center;
margin-top: 30px;
flex-flow: row wrap;
margin-top: -10vw;
}
.galleryimg {
margin: 9px;
transition: filter 0.2s;
filter: brightness(100%);
display: inline-block;
min-height: 100px;
height: 50vh;
}
.galleryimg:hover {
filter: brightness(80%);
}
.responsive:hover {
}
header {
position: relative;
height: 50vh;
background-image: linear-gradient(rgb(50, 50, 50), rgb(30, 30, 30));
margin-top: -20px;
transform: skewY(-5deg);
transform-origin: top left;
}
.fullwidth {
width: 100%;
}
.headertitle {
margin-top: -36vh;
margin-left: 12vw;
position: absolute;
font-size: calc(13px + 2.5vw);
color: white;
font-family: 'Montserrat';
font-weight: lighter;
}
/* navbar */
nav {
background: rgb(52, 52, 52);
position: relative;
z-index: 1;
height: calc(18px + 6vh);
box-shadow: 0 3px 3px -1px rgba(0, 0, 0, 0.065);
overflow: auto;
width: 100vw;
}
nav ul {
margin: 0;
padding: 0;
text-align: left;
margin-left: 3.2vw;
}
nav ul li {
display: inline-block;
list-style: none;
font-size: 1.2em;
padding: 1vh;
}
.navul a {
text-decoration: none;
color: white;
line-height: 5.5vh;
height: 5.5vh;
font-size: calc(15px + 0.25vh + 0.15vw);
}
.navuul a:visited, a:link, a:active
{
text-decoration: none;
color: white;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
.navuul a:hover
{
text-decoration: none;
color: grey;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
.submit {
float: right;
margin-right: 1.5vw;
}
.submit a {
color: white;
border-radius: 5px;
}
.navimgdiv img {
width: 0.8vw;
}
.navimgdiv {
padding: 5px 0;
padding-left: 0.5vw;
float: left;
margin-left: 1vw;
}
.navimgdiv img :hover {
filter: brightness(100%);
}
.navimgdiv a:visited, a:link, a:active {
text-decoration: none;
color: grey;
font-weight: 200;
line-height: 5.5vh;
height: 5.5vh;
}
/* navbar end */
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="pgallerystyles.css">
<title> Photo Gallery </title>
<link rel="shortcut icon" href="logo.png">
</head>
<body>
<div class="fullwidth"></div>
<nav>
<a href="#" class="navimgdiv"><img src="logo.svg">Lumastock</a>
<ul class="navul">
<li><a href="#">Photos</a></li>
<li><a href="#">Featured</a></li>
<li><a href="#"> Contact</a></li>
<li><a href="#">Pricing</a></li>
<li><a href="#">Assesment Requirements</a></li>
<li class="submit"><a href="#">Submit a photo</a></li>
</ul>
</nav>
<header></header>
<h1 class="headertitle">Image Gallery</h1>
<main class="site-wrapper">
<div class="container">
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/600x400.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/400x600.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/400x600.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/600x400.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/600x400.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/600x400.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/600x400.jpg"></div>
<div class="responsive"><img class="galleryimg" src="https://via.placeholder.com/600x400.jpg"></div>
</div>
</main>
</body>
</html>
网站的屏幕截图:
答案 0 :(得分:2)
您的图片没有显示,因此很难使用提供的代码,因此,这是一个应该有用的简单示例。
包裹图像的div需要position: relative
,然后可以将position: absolute
添加到被单击的图标上,方向规则使您可以精确地指定相对于容器div的位置。
.image-wrapper {
display: inline-block;
position: relative;
}
.clickable-icon {
display: inline-block;
position: absolute;
right: 20px;
bottom: 20px;
color: white;
font-size: 40px;
cursor: pointer;
}
.clickable-icon:hover {
color: red;
}
<div class="image-wrapper">
<img src="https://picsum.photos/200" />
<span onClick="alert('ya clicked me!')" class="clickable-icon">X</span>
</div>