温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

css3实现尖角的方法

发布时间:2020-12-11 14:14:49 来源:亿速云 阅读:352 作者:小新 栏目:web开发

这篇文章给大家分享的是有关css3实现尖角的方法的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

css3做尖角的方法:首先创建一个HTML示例文件;然后确定尖角的位置;最后通过给指定div设置属性为“top:6px;left:-3px;border-top:0px;border-bottom...”来实现尖角效果即可。

尖角在上面

代码:

<html>
<head>
<title>尖角p</title>
<style type="text/css">
#top
{
  width:400px;
  height:250px;
  border:3px solid;   /* 边框宽度为3px */
  position:relative;
}
.sp1,.sp2
{
  display:block;
  height:0px;
  width:0px;
  position:absolute;
  font-size:0;
  line-height:0;
}
.sp1
{
  top:-9px;    /* 它的绝对值加上span的边框宽度等于p边框宽度的5倍 */
  left:40px;   /* 它来确定尖角的位置 */
  border-top:0px;
  border-bottom:6px solid black;  /* 注意颜色的变化 */
  border-right:6px solid white;
  border-left:6px solid white;
}
.sp2
{
  top:6px;  /* 是自身边框宽度的2倍 */
  left:-3px; /* 是自身边框宽度的-1倍  */
  border-top:0px;
  border-bottom:3px solid white;
  border-right:3px solid black;
  border-left:3px solid black;
}

</style>
</head>

<body>
<p id="top">
<span class="sp1">
<span class="sp2"></span>
</span>
</p>
</body>

</html>


尖角在下面

代码:

<html>
<head>
<title>尖角p</title>
<style type="text/css">
#bottom
{
  width:400px;
  height:250px;
  border:3px solid;   /* 边框宽度为3px */
  position:relative;
}
.sp1,.sp2
{
  display:block;
  height:0px;
  width:0px;
  position:absolute;
  font-size:0;
  line-height:0;
}
.sp1
{
  bottom:-9px;    /* 它的绝对值加上span的边框宽度等于p边框宽度的5倍 */
  left:40px;   /* 它来确定尖角的位置 */
  border-bottom:0px;
  border-top:6px solid black;  /* 注意颜色的变化 */
  border-right:6px solid white;
  border-left:6px solid white;
}
.sp2
{
  bottom:6px;  /* 是自身边框宽度的2倍 */
  left:-3px; /* 是自身边框宽度的-1倍  */
  border-bottom:0px;
  border-top:3px solid white;
  border-right:3px solid black;
  border-left:3px solid black;
}

</style>
</head>

<body>
<p id="bottom">
<span class="sp1">
<span class="sp2"></span>
</span>
</p>
</body>

</html>


尖角在左边

代码:

<html>
<head>
<title>尖角p</title>
<style type="text/css">
#left
{
  width:400px;
  height:250px;
  border:3px solid;   /* 边框宽度为3px */
  position:relative;
}
.sp1,.sp2
{
  display:block;
  height:0px;
  width:0px;
  position:absolute;
  font-size:0;
  line-height:0;
}
.sp1
{
  left:-9px;    /* 它的绝对值加上span的边框宽度等于p边框宽度的5倍 */
  top:40px;   /* 它来确定尖角的位置 */
  border-left:0px;
  border-top:6px solid white;  /* 注意颜色的变化 */
  border-right:6px solid black;
  border-bottom:6px solid white;
}
.sp2
{
  left:6px;  /* 是自身边框宽度的2倍 */
  top:-3px; /* 是自身边框宽度的-1倍  */
  border-left:0px;
  border-top:3px solid black;
  border-right:3px solid white;
  border-bottom:3px solid black;
}

</style>
</head>

<body>
<p id="left">
<span class="sp1">
<span class="sp2"></span>
</span>
</p>
</body>

</html>


尖角在右边

代码:

<html>
<head>
<title>尖角p</title>
<style type="text/css">
#right
{
  width:400px;
  height:250px;
  border:3px solid;   /* 边框宽度为3px */
  position:relative;
}
.sp1,.sp2
{
  display:block;
  height:0px;
  width:0px;
  position:absolute;
  font-size:0;
  line-height:0;
}
.sp1
{
  right:-9px;    /* 它的绝对值加上span的边框宽度等于p边框宽度的5倍 */
  top:40px;   /* 它来确定尖角的位置 */
  border-right:0px;
  border-top:6px solid white;  /* 注意颜色的变化 */
  border-bottom:6px solid white;
  border-left:6px solid black;
}
.sp2
{
  right:6px;  /* 是自身边框宽度的2倍 */
  top:-3px; /* 是自身边框宽度的-1倍  */
  border-right:0px;
  border-top:3px solid black;
  border-bottom:3px solid black;
  border-left:3px solid white;
}

</style>
</head>

<body>
<p id="right">
<span class="sp1">
<span class="sp2"></span>
</span>
</p>
</body>

</html>

感谢各位的阅读!关于css3实现尖角的方法就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI