CSS伪类选择器实现气泡

  • 气泡-实心
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>CSS伪类选择器实现气泡-实心</title>
		<style type="text/css">
			.pop_top,
			.pop_right,
			.pop_bottom,
			.pop_left {
                float: left;
				width: 150px;
				height: 100px;
				background: #CCC;
				border-radius: 5px;
				margin: 50px;
				position: relative;
			}
			
			/* 三角形在上边 */
			.pop_top:before {
				content: "";
				width: 0;
				height: 0;
				border-left: 10px solid transparent;
				border-right: 10px solid transparent;
				border-bottom: 10px solid #CCC;
				position: absolute;
				top: -10px;
				left: 65px;
			}
			
			/* 三角形在右边 */
			.pop_right:before {
				content: "";
				width: 0;
				height: 0;
				border-top: 10px solid transparent;
				border-bottom: 10px solid transparent;
				border-left: 10px solid #CCC;
				position: absolute;
				top: 40px;
				left: 150px;
			}
			
			/* 三角形在下边 */
			.pop_bottom:before {
				content: "";
				width: 0;
				height: 0;
				border-top: 10px solid #CCC;
				border-left: 10px solid transparent;
				border-right: 10px solid transparent;
				position: absolute;
				top: 100px;
				left: 70px;
			}
			
			/* 三角形在左边 */
			.pop_left:before {
				content: "";
				width: 0;
				height: 0;
				border-top: 10px solid transparent;
				border-bottom: 10px solid transparent;
				border-right: 10px solid #CCC;
				position: absolute;
				top: 40px;
				left: -10px;
			}
		</style>
	</head>
	<body>
		<!--三角形在上边-->
		<div class="pop_top"></div>
 
		<!--三角形在右边-->
		<div class="pop_right"></div>
 
		<!--三角形在下边-->
		<div class="pop_bottom"></div>
 
		<!--三角形在左边-->
		<div class="pop_left"></div>
	</body>
</html>

效果图

  •  气泡-边框

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>CSS伪类选择器实现气泡-边框</title>
		<style type="text/css">
			.pop_top,
			.pop_right,
			.pop_bottom,
			.pop_left {
				float: left;
				width: 150px;
				height: 100px;
				border: 1px solid #CCC;
				border-radius: 5px;
				margin: 50px;
				position: relative;
			}
			
			/* 三角形在上边 */
			.pop_top:before {
				content: '';
				width: 0;
				height: 0;
				border-left: 10px solid transparent;
				border-right: 10px solid transparent;
				border-bottom: 10px solid #CCC;
				position: absolute;
				top: -11px;
				left: 65px;
			}

			.pop_top:after {
				content: '';
				width: 0;
				height: 0;
				border-left: 9px solid transparent;
				border-right: 9px solid transparent;
				border-bottom: 9px solid #FFFFFF;
				position: absolute;
				top: -9px;
				left: 66px;
			}
			
			/* 三角形在右边 */
			.pop_right:before {
				content: '';
				width: 0;
				height: 0;
				border-top: 10px solid transparent;
				border-bottom: 10px solid transparent;
				border-left: 10px solid #CCC;
				position: absolute;
				top: 34px;
				left: 150px;
			}

			.pop_right:after {
				content: '';
				width: 0;
				height: 0;
				border-top: 9px solid transparent;
				border-bottom: 9px solid transparent;
				border-left: 9px solid #FFFFFF;
				position: absolute;
				top: 35px;
				left: 149px;
			}
			
			/* 三角形在下边 */
			.pop_bottom:before {
				content: '';
				width: 0;
				height: 0;
				border-top: 10px solid #CCC;
				border-left: 10px solid transparent;
				border-right: 10px solid transparent;
				position: absolute;
				top: 100px;
				left: 69px;
			}

			.pop_bottom:after {
				content: '';
				width: 0;
				height: 0;
				border-top: 9px solid #FFFFFF;
				border-left: 9px solid transparent;
				border-right: 9px solid transparent;
				position: absolute;
				top: 99px;
				left: 70px;
			}
			
			/* 三角形在左边 */
			.pop_left:before {
				content: '';
				width: 0;
				height: 0;
				border-top: 10px solid transparent;
				border-bottom: 10px solid transparent;
				border-right: 10px solid #CCC;
				position: absolute;
				top: 40px;
				left: -11px;
			}

			.pop_left:after {
				content: '';
				width: 0;
				height: 0;
				border-top: 9px solid transparent;
				border-bottom: 9px solid transparent;
				border-right: 9px solid #FFFFFF;
				position: absolute;
				top: 41px;
				left: -9px;
			}
		</style>
	</head>
	<body>
		<!--三角形在上边-->
		<div class="pop_top"></div>
		
		<!--三角形在右边-->
		<div class="pop_right"></div>
		
		<!--三角形在下边-->
		<div class="pop_bottom"></div>
		
		<!--三角形在左边-->
		<div class="pop_left"></div>
	</body>
</html>

效果图

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

 康 

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值