Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css] 第330天 使用css实现对话气泡的效果 #2039

Open
haizhilin2013 opened this issue Mar 10, 2020 · 4 comments
Open

[css] 第330天 使用css实现对话气泡的效果 #2039

haizhilin2013 opened this issue Mar 10, 2020 · 4 comments
Labels
css css

Comments

@haizhilin2013
Copy link
Collaborator

第330天 使用css实现对话气泡的效果

我也要出题

@haizhilin2013 haizhilin2013 added the css css label Mar 10, 2020
@cxwht
Copy link

cxwht commented Mar 11, 2020

一个带圆角的长方形/椭圆 加上before伪类贴在左边或者右边的小三角形三角形

@jasonzhouu
Copy link

jasonzhouu commented Mar 11, 2020

将气泡分为2个部分:

部分 描述
矩形 主体部分
箭头 用before/after伪元素创建的正方形

箭头的创建方法:将正方形旋转45°,并移到矩形边缘,露出一半的尖角。

移动方法是用 absolute position,设置其相对矩形的位置,距离矩形顶部 50% - 0.5em,距离矩形右侧边缘 0.5em(设置right为负数,表示移到外面)。

image

image

@lincimy
Copy link

lincimy commented Mar 11, 2020

方法:使用圆角矩形作为对话的主体框,左侧或右侧增加附加三角形,三角形使用border样式设置来实现,相对定位和绝对定位结合使三角形附于圆角矩形左侧或右侧;
html:
<div class="dialog-box">测试对话框</div>
css:

.dialog-box{
      display: inline-block;
      background-color: #ccc;
      font-size: 14px;
      padding: 10px;
      border-radius: 5px;
      color: #fff;
      position: relative;
    }
    .dialog-box:before{
      content: "";
      width: 0;
      height: 0;
      border-width: 6px;
      border-style: solid;
      border-color: transparent #ccc transparent transparent;
      position: absolute;
      left: -12px;
      top: 50%;
      margin-top: -6px;
    }

@longhui520
Copy link

   p.speech{
           position: relative;
           width: 50px;
           border:1px solid #666;
           padding: 2px;
           border-radius: 4px; 
       }
   p.speech::before{
       position: absolute;
       content: "";
       top:9px;
       left:-12px;
       width: 0;
       border:6px solid;
       border-color:transparent #666  transparent transparent;
   }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css css
Projects
None yet
Development

No branches or pull requests

5 participants