CSS-带尖角的对话框

效果图:

 

box1的代码:

复制代码
.box{
    position: relative;
    width: 200px;
    height: 200px;
    border: 2px solid #000;
    background-color: #fff;
}
.box:before{
    position: absolute;
    content: "";
    width: 0;
    height: 0;
    left: 200px;
    top: 20px;
    border-left: 10px solid #000;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
}
.box:after{
    position: absolute;
    content: "";
    width: 0;
    height: 0;
    left: 200px;
    top: 23px;
    border-left: 7px solid #fff;
    border-top: 7px solid transparent;
    border-bottom: 7px solid transparent;
}
复制代码

box2的代码:

复制代码
.box2{
    position: relative;
    width: 200px;
    height: 200px;
    border: 2px solid #000;
    background-color: #fff;
}
.box2:before{
    position: absolute;
    content: "";
    width: 0;
    height: 0;
    left: 200px;
    top: 20px;
    border-bottom: 20px solid transparent;
    border-left: 20px solid #000;
}
.box2:after{
    position: absolute;
    content: "";
    width: 0;
    height: 0;
    left: 200px;
    top: 22px;
    border-bottom: 15px solid transparent;
    border-left: 15px solid #fff;
}
复制代码

伪元素中的top值和border的宽度值需要根据对话框的边框宽度计算得到。

posted @   ZhangCui  阅读(10762)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示