css - div 容器内的图像高度

标签 css

我在 div 中的图像有问题。 这个带有 swiper__content 类的 div 为图像提供了一种底部填充,我看不出是什么导致了这种效果。我有一个 100% 的高度,没有填充或边距,所以它可能适合 div enter image description here

.no-padding{
  padding: 0px 0px !important;
}
.swiper {
  margin: 0 auto 50px;
  width: 40%;
  text-align: center;
  padding: 10px 20px;
  font-size: 10vw;
  line-height: 1;
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  font-family: "Impact";
  cursor: pointer;
}

.swiper__content {
  color: transparent;
  display: block;
  
}
.swiper .swiper__content img{
  opacity: 0;
   width: 100%;
  height: 100%;
  

transition: opacity 0s ease-in 0.5s;
-moz-transition: opacity 0s ease-in 0.5s;
-webkit-transition: opacity 0s ease-in 0.5s;
-o-transition: opacity 0s ease-in 0.5s;
  
}
.swiper__bar, .swiper__bar--right {
  width: 100%;
  height: 100%;
  background: orange;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(-100%);
  transition: 1s ease-in-out;
}

.swiper__bar--right {
  transform: translateX(100%);
}

.swiper.revealed .swiper__content {
  animation-name: kf-font-reveal;
  animation-duration: 1s;
  color: orange;
}

.swiper.revealed .swiper__content img{
  opacity: 1;


}
<div class="swiper no-padding revealed">
<div class="swiper__content">
<img src="http://lorempicsum.com/futurama/350/200/1">
</div>
<span class="swiper__bar--right"></span>
</div>
有没有办法去除它?

最佳答案

为您的 swiper 类设置 line-height: 0

.no-padding{
  padding: 0px 0px !important;
}
.swiper {
  margin: 0 auto 50px;
  width: 40%;
  text-align: center;
  padding: 10px 20px;
  font-size: 10vw;
  line-height: 0;
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  font-family: "Impact";
  cursor: pointer;
}

.swiper__content {
  color: transparent;
  display: block;
  
}
.swiper .swiper__content img{
  opacity: 0;
   width: 100%;
  height: 100%;
  

transition: opacity 0s ease-in 0.5s;
-moz-transition: opacity 0s ease-in 0.5s;
-webkit-transition: opacity 0s ease-in 0.5s;
-o-transition: opacity 0s ease-in 0.5s;
  
}
.swiper__bar, .swiper__bar--right {
  width: 100%;
  height: 100%;
  background: orange;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  transform: translateX(-100%);
  transition: 1s ease-in-out;
}

.swiper__bar--right {
  transform: translateX(100%);
}

.swiper.revealed .swiper__content {
  animation-name: kf-font-reveal;
  animation-duration: 1s;
  color: orange;
}

.swiper.revealed .swiper__content img{
  opacity: 1;


}
<div class="swiper no-padding revealed">
<div class="swiper__content">
<img src="http://lorempicsum.com/futurama/350/200/1">
</div>
<span class="swiper__bar--right"></span>
</div>

关于css - div 容器内的图像高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45517338/

相关文章:

html - CSS vertical-align 不做任何事情

JavaFx CSS 错误解析意外 token ':' 在 [15,21]

css - multinavibar 在 Bootstrap 中不工作

html - 一个表占用其他表中单元格的可用高度

javascript - 如何在刷新时保留点击卡片的背景颜色?

php - 仅在 div 中加载 php 内容

css - Webkit 浏览器呈现的 CSS 与 Mozilla Firefox 不同......为什么?

html - 使 a :after show when the page is active

css - CSS 辅助类的使用

javascript - React Native 边框半径制作轮廓