本文主要包含CSS3,气泡,对话框等相关知识,颜海镜 希望在学习及工作中可以帮助到您
创建一个100%CSS的气泡,我们从下面的标记考试。
- <div class="speech-bubble">Hi there!</div>
接下来,应用一些基本样式。
- .speech-bubble {
- position: relative;
- background-color: #292929;
- width: 200px;
- height: 150px;
- line-height: 150px; /* 垂直居中 */
- color: white;
- text-align: center;
- }
箭头将通过after伪元素实现。
- .speech-bubble:after {
- content: '';
- }
- :before和:after伪元素可以用来在元素内容之前或之后插入生成内容。 接下来,只是简单复制箭头,并定位到适当的位置。我们开始通过绝对定位的内容,重置宽度和高度,并应用边界颜色。
- .speech-bubble:after {
- content: '';
- position: absolute;
- width: 0;
- height: 0;
- border: 10px solid;
- border-color: red green blue yellow;
- }
因为我们知道我们想要向下的箭头,上面的图片表明,除了红色(或上)边境其他的都应该被省略,或者设置为透明。
- .speech-bubble:after {
- content: '';
- position: absolute;
- width: 0;
- height: 0;
- border: 10px solid;
- border-top-color: red;
- }
当创建CSS形状是,因为我们不能使用width属性来指定箭头的宽度,而是应该使用border-width属性。在这种情况下,箭头应该更大点;所以border-width可以增加到15px。我们将箭头定位到容器的底部居中,通过利用top和left属性。
- .speech-bubble:after {
- content: '';
- position: absolute;
- width: 0;