首页 > 解决方案 > 曲线形状的 div 边框

问题描述

我正在尝试在凸形中实现 div 边框,并且在悬停时它应该是正常的方形。我已经在底部添加了我想在顶部添加我之前尝试使用但无法达到结果的相同。谁能帮助我下面是我到目前为止所做的代码。任何帮助将不胜感激 在此处输入图像描述

* {
	box-sizing: border-box;
}
.services {
	position: relative;
	width: 500px;
	height: 420px;
	margin: 100px;
	background-color: #cccccc;
	transition: all 0.2s ease;
	animation: down-bump 0.4s ease;
}
.services:before {
     
}
.serv_section {
  top: 83%;
  position: relative;
  overflow: hidden;
  padding: 50px 0 0;
}

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

.services:hover .serv_inner:after {
	top: -120px;
}

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

span.image_caption {
	position: absolute;
	color: red;
	padding: 10px 20px;
	font-size: 30px;
	z-index: 10;
	animation-duration: 2.5s;
     animation-fill-mode: both;
}
span.image_caption p {
    font-size: 32px;
    font-weight: 900;
    font-family: 'Dancing Script', cursive;
    color: cadetblue;	
}
	
<div class='services'>
  <div class="serv_section">
    <div class="serv_inner">
	   
	    
	  </div>
  </div>
</div>

标签: htmlcss

解决方案


您可以使用之前和之后的元素来制作曲线,悬停时隐藏元素后面的伪元素并像这样删除曲线:

.services {
  position: relative;
  width: 100px;
  height: 60px;
  margin: 100px;
  background-color: #cccccc;
  z-index: 0;
}
.services:hover:before{
  top: 0px;
  border-radius: 0;
}
.services:hover:after{
  bottom: 0px;
  border-radius: 0;
}
.services:before, .services:after{
  content: ' ';
  position: absolute;
  width: 100%;
  height: 40px;
  background-color: #cccccc;
  border-radius: 50%;
  z-index: -1;
  transition: all .4s;
}
.services:before {
  top: -20px;
}
.services:after {
  bottom: -20px;
 }
<div class='services'>
  
</div>


推荐阅读