曲线形状的Div边框

时间:2018-09-28 08:01:15

标签: html5 css3

我正在尝试将div边框设置为凸形,并且将其悬停时应为普通正方形。我已经在底部添加了相同的内容,我想在之前尝试使用的顶部添加但无法实现结果。谁能帮我以下是到目前为止我完成的代码。 任何帮助将不胜感激 enter image description here

* {
	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>

2 个答案:

答案 0 :(得分:1)

您可以使用before和after元素制作曲线,将鼠标悬停在psuedo元素之后,将其隐藏在该元素后面,然后像这样删除曲线:

.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>

答案 1 :(得分:0)

如果我理解正确,那么您可以通过简单地对 border-radius 属性的水平和垂直尺寸使用不同的值来实现此目的(有关更多信息,请访问https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius):

div {
  background: grey;
  
  height: 100px;
  width: 200px;
  
  transition: border-radius .15s ease-out;
}

/* border-radius on default state */
div {
  border: 4px solid black;
  border-radius: 50%/20px;
}

div:hover {
  border-radius: 0;
}
<div></div>