html5+css3气泡组件的实现

2020-04-24 19:37:58易采站长站整理

</ul>

当然这里要有相关的css

复制代码
.cui-bubble-layer {
background: #f2f2f2;
border: #bcbcbc 1px solid;
border-radius: 3px
}

至此形成的效果是酱紫滴:

复制代码
<!doctype html>
<html>
<head>
<meta charset=”utf-8″ />
<title>Blade Demo</title>
<meta name=”viewport” content=”width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no”>
<meta content=”telephone=no” name=”format-detection” />
<meta name=”apple-mobile-web-app-capable” content=”yes” />
<style type=”text/css”>
body, button, input, select, textarea { font: 400 14px/1.5 Arial, “Lucida Grande” ,Verdana, “Microsoft YaHei” ,hei; }
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, textarea, p, blockquote, th, td, hr, button, article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { margin: 0; padding: 0; }
body { background: #f5f5f5; }
ul, ol { list-style: none; }

.cui-bubble-layer { background: #f2f2f2; border: #bcbcbc 1px solid; border-radius: 3px; }
</style>
</head>
<body>
<ul class=”cui-bubble-layer” style=”position: absolute; top: 110px; left: 220px;”>
<li data-index=”0″ data-flag=”c”>价格:¥35</li>
<li data-index=”1″ data-flag=”c”>评分:80</li>
<li data-index=”2″ data-flag=”c”>级别:5</li>
</ul>
</body>
</html>

这个时候在为其加一个伪类,做点样式上的调整,便基本实现了,这里用到了伪类的知识点:

复制代码
cui-bubble-layer:before {
position: absolute; content: “”; width: 10px; height: 10px; -webkit-transform: rotate(45deg);
background: #f2f2f2;
border-top: #bcbcbc 1px solid;
border-left: #bcbcbc 1px solid;
top: -6px; left: 50%; margin-left: -5px; z-index: 1;
}

这里设置了一个绝对定位的矩形框,为其两个边框设置了值,然后变形偏斜45度形成小三角,然后大家都知道了

复制代码
<!doctype html>
<html>
<head>
<meta charset=”utf-8″ />
<title>Blade Demo</title>
<meta name=”viewport” content=”width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no”>
<meta content=”telephone=no” name=”format-detection” />