div盒子下面有一个小三角,类似于提示框,css怎么实现
时间: 2024-03-05 14:48:41 浏览: 74
这种带有小三角的提示框通常被称为气泡提示框,可以使用 CSS 中的伪元素 `::before` 或 `::after` 来实现。
以下是一个简单的实现气泡提示框的 CSS 代码:
```css
.tooltip {
position: relative;
display: inline-block;
}
.tooltip::before {
content: "";
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
border-width: 10px;
border-style: solid;
border-color: transparent transparent #333 transparent;
}
.tooltip .tooltip-content {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 10px;
background-color: #333;
color: #fff;
line-height: 1.5;
font-size: 14px;
border-radius: 5px;
white-space: nowrap;
}
```
在 HTML 中,可以这样使用:
```html
<div class="tooltip">
<div class="tooltip-content">这是一个提示框</div>
</div>
```
其中,提示框的内容放在一个内部的 `div` 元素中,而外部的 `div` 元素则是用于定位和显示小三角的容器。通过设置 `::before` 伪元素的样式,可以让其显示一个三角形,并定位到容器的下方居中位置。同时,通过设置 `::after` 伪元素,也可以实现在右侧显示小三角的提示框。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)