- 的覆蓋比在底部的圖像稍大。即使在使用不同的圖像時,這仍然存在。
問題出在圖像本身上,它的高度比容器小。嘗試將一些background-color
放在容器上,您會看到覆蓋層高度與其父層相同。
- 轉換不起作用;懸停效果突然顯示並隱藏。
無法實現對CSS display
過渡,其他替代將使用opacity
。我修改了你的代碼,請嘗試。
html {
\t box-sizing:border-box;
}
*, *:before, *:after {
\t box-sizing:inherit;
}
body {
\t background-color:honeydew;
\t font-size: 16px;
\t line-height: 120%;
\t color: #333;
\t margin: 0;
\t padding: 0;
}
.wrapper {
\t min-height: 100vh;
\t width: 80vw;
\t max-width:1200px;
\t margin: auto;
\t border: 0;
\t padding: 0;
\t column-count: 3;
\t column-gap: 20px;
}
.item {
\t display:block;
\t margin: 0 0 20px;
\t border:0;
\t width:100%;
\t position:relative;
background-color: black;
}
.item-overlay {
\t position:absolute;
\t top:0;
\t left:0;
\t bottom:0;
\t width:100%;
\t background-color: rgba(51,51,51,0.6);
\t color:white;
\t opacity:0;
\t transition:300ms ease opacity;
display: flex;
\t flex-direction:column;
\t justify-content:center;
\t align-items:center;
}
.item:hover .item-overlay {
\t opacity: 1;
\t background-color: rgba(51,51,51,0.6);
}
.project-img {
\t width:100%;
\t margin:0;
\t border:0;
\t padding:0;
}
.project-name {
\t font-weight:bold;
}
.project-category {
\t font-size:0.75em;
\t text-transform:uppercase;
<body>
\t <div class="wrapper">
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t \t <div class="item">
\t \t \t <img class="project-img" src="https://images.pexels.com/photos/297755/pexels-photo-297755.jpeg?w=1260&h=750&auto=compress&cs=tinysrgb"/>
\t \t \t <div class="item-overlay">
\t \t \t \t <p class="project-name">Project Name</p>
\t \t \t \t <p class="project-category">Commercial</p>
\t \t \t </div>
\t \t </div>
\t </div>
</body>
來源
2017-04-21 04:21:00
nvl
謝謝! 'vertical-align:top'修復了它。但是,爲什麼沒有它的原始代碼工作? –
圖像被視爲內嵌內容,並且內嵌內容的底部有空間用於字符上的小尾跡(如p,j,q等)。 'vertical-align:top'或'display:block'將刪除該空間。 @NatTan –