css实现特殊的按钮形状-四个拐角空四边形

Posted JackieDYH

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了css实现特殊的按钮形状-四个拐角空四边形相关的知识,希望对你有一定的参考价值。

效果演示 

 

<div class="box">
	<div class="button">
		按钮
	</div>
</div>
<div class="box1">
	哈哈
	<span></span>
	<span></span>
	<span></span>
	<span></span>
</div>
<div class="box2">
	哈哈
	<span></span>
	<span></span>
	<span></span>
	<span></span>
</div>
.box {
	width: 100px;
	margin: 0 auto;
	margin-bottom: 20px;
}

.box .button {
	width: 100px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;

	/* border: 1px solid #18324C; */
	padding: 2px;
	background: linear-gradient(to left, #fff, #fff) no-repeat left top,
				linear-gradient(to left, #fff, #fff) no-repeat right top,
				linear-gradient(to left, #fff, #fff) no-repeat left bottom,
				linear-gradient(to left, #fff, #fff) no-repeat right bottom,
				#9EE7FF;
	background-size: 8px 8px, 8px 8px, 8px 8px, 8px 8px;
}
.box1{
	position: relative;
	width: 100px;
	height: 100px;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #006DB7;
	margin: 0 auto;
	margin-bottom: 20px;
}
.box1 span{
	display: block;
	width: 8px;
	height: 8px;
	background-color: #fff;
}
.box1 span:nth-child(1){
	position: absolute;
	top: 0;
	left: 0;
}
.box1 span:nth-child(2){
	position: absolute;
	top: 0;
	right: 0;
}
.box1 span:nth-child(3){
	position: absolute;
	bottom: 0;
	left: 0;
}
.box1 span:nth-child(4){
	position: absolute;
	bottom: 0;
	right: 0;
}
/* -------------------------- */
.box2{
	position: relative;
	width: 100px;
	height: 100px;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #fff;
	border: 1px solid #006DB7;
	margin: 0 auto;
	margin-bottom: 20px;
}
.box2 span{
	display: block;
	width: 8px;
	height: 8px;
	background-color: #fff;
}
.box2 span:nth-child(1){
	position: absolute;
	top: -1px;
	left: -1px;
	z-index: 2;
	border-right: 1px solid #006DB7;
	border-bottom: 1px solid #006DB7;
}
.box2 span:nth-child(2){
	position: absolute;
	top: -1px;
	right: -1px;
	z-index: 2;
	border-left: 1px solid #006DB7;
	border-bottom: 1px solid #006DB7;
}
.box2 span:nth-child(3){
	position: absolute;
	bottom: -1px;
	left: -1px;
	z-index: 2;
	border-top: 1px solid #006DB7;
	border-right: 1px solid #006DB7;
}
.box2 span:nth-child(4){
	position: absolute;
	bottom: -1px;
	right: -1px;
	z-index: 2;
	border-top: 1px solid #006DB7;
	border-left: 1px solid #006DB7;
}

 使用css3属性或者自己裁切实现

以上是关于css实现特殊的按钮形状-四个拐角空四边形的主要内容,如果未能解决你的问题,请参考以下文章

如何在 CSS 中创建这种形状(带圆角的四边形)?

Css:菜单悬停创建自定义形状背景图像?(使用css的平行四边形)

具有多边形形状的 XAML UWP 按钮

具有六边形触摸边界的 Android Hexagon 形状按钮

在GLSL ES中的片段着色器上旋转纹理

#yyds干货盘点#探索 CSS Paint API:多边形边框