jquery - 凹凸形状div

标签 jquery html css

我正在处理 div 的凹凸形状。我想要一个凹形,鼠标悬停时它会变成凸形。谁能指出我正确的方向?到目前为止,这是我在下面尝试过的示例代码是图像

.section {
  position: relative;
  overflow: hidden;
  padding: 50px 0;
}

.inner {
  position: relative;
  background: black;
  height: 120px;
}
.inner:after {
  box-shadow: 0 0 0 80px #000;
  border-radius: 100%;
  position: absolute;
  height: 150px; 
  content: '';
  right: -20%;
  left: -20%;
  top: 100%;
	transition: all 0.4s ease-in-out;
}

.inner:after {
  bottom: 100%;
  top: auto;
}

.inner:hover:after {
	height: 0;
}
<div class="section">
  <div class="inner"></div>
</div>

最佳答案

你很接近。您可以使用 :before 和 ':after' 来实现该功能。 :before 与':after' 几乎相同,只是top 位置不同。

.card {
    height: 100px;
    background-color: tomato;
}
.section {
  top: 50px;
  position: relative;
  overflow: hidden;
  padding: 50px 0 0;
}

.inner {
  position: relative;
  background: black;
  height: 120px;
}
.inner:after {
  box-shadow: 0 0 0 80px #000;
  border-radius: 100%;
  position: absolute;
  height: 150px; 
  content: '';
  right: -20%;
  left: -20%;
  top: -150px;
	transition: all 0.4s ease-in-out;
}

.inner:hover:after {
	top: -120px;
}

.inner:before {
    box-shadow: 0 0 0 80px #000;
  border-radius: 100%;
  position: absolute;
  height: 150px; 
  content: '';
  right: -20%;
  left: -20%;
  top: 130px;
	transition: all 0.4s ease-in-out;
}

.inner:hover:before {
	top: 50px;
}
<div class='card'>
  <div class="section">
    <div class="inner"></div>
  </div>
</div>

关于jquery - 凹凸形状div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52522686/

相关文章:

html - 在网站中插入谷歌地图应该使用 IFRAME 还是 IMG

javascript - 圆环图 Vanilla JS 和 HTML Canvas

css - Firefox CSS float 错误?

html - 改变下拉指针的位置?

javascript - 如何使用 ngStyle (angular2) 添加背景图像?

javascript - 数据表:通过 DOM 数据源中的名称引用列

javascript - 如何重置选择下拉列表的值

jquery - 单击 DIV 时选中单选按钮

c# - 如何在点击时交换图像?

html - 在 css 列内分布