【发布时间】:2020-01-25 23:34:36
【问题描述】:
我试图让这个 div 可点击:
<a href="{{ url_for('germany') }}">
<div class="item item--germany">
<div class="item__details">
Germany
</div>
</div>
</a>
div 是一个背景图像,当我尝试像上面那样链接它时,图像变成了它的 1/8 大小,并且文本中有一条时髦的线条。这是 CSS:
.item {
position: relative;
display: -webkit-box;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
flex-direction: column;
-webkit-box-pack: end;
justify-content: flex-end;
box-sizing: border-box;
background: #0c9a9a;
color: #fff;
grid-column-start: auto;
grid-row-start: auto;
color: #fff;
background: url("https://images.unsplash.com/photo-1470124182917-cc6e71b22ecc?dpr=2&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop=");
background-size: cover;
background-position: center;
box-shadow: -2px 2px 10px 0px rgba(56, 41, 41, 0.4);
-webkit-transition: -webkit-transform 0.3s ease-in-out;
transition: -webkit-transform 0.3s ease-in-out;
transition: transform 0.3s ease-in-out;
transition: transform 0.3s ease-in-out, -webkit-transform 0.3s ease-in-out;
cursor: pointer;
counter-increment: item-counter;
}
.item:after {
content: '';
position: absolute;
width: 100%;
height: 100%;
background-color: black;
opacity: 0.3;
-webkit-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
.item:hover {
-webkit-transform: scale(1.05);
transform: scale(1.05);
.item--germany {
background-image: url("../images/germany.jpg");
a {
color: inherit;
text-decoration: none; /* no underline */
}
我读到我可以执行<a href><img="image.jpg></a> 之类的操作,但这会删除我的 div,而且我认为悬停效果不会仍然有效。
【问题讨论】: