利用純CSS製作冒泡提示框效果

來源:互聯網
上載者:User

先看2張效果圖:

CSS:

 代碼如下 複製代碼

/*
   對話氣泡
   用法:使用.speech-bubble和.speech-bubble-DIRECTION類
   <div class="speech-bubble speech-bubble-top">Hi there</div>
*/
 
.speech-bubble {
  position: relative;
  background-color: #292929;
 
  width: 200px;
  height: 150px;
  line-height: 150px; /* 垂直置中 */
  color: white;
  text-align: center;
  border-radius: 10px;
  font-family: sans-serif;
}
 
.speech-bubble:after {
  content: '';
  position: absolute;
 
  width: 0;
  height: 0;
 
  border: 15px solid;
}
 
/* 箭頭的位置 */
.speech-bubble-top:after {
  border-bottom-color: #292929;
  left: 50%;
  bottom: 100%;
  margin-left: -15px; 
}
.speech-bubble-right:after {
  border-left-color: #292929;
 
  left: 100%;
  top: 50%;
  margin-top: -15px;  
}
 
.speech-bubble-bottom:after {
  border-top-color: #292929;
  top: 100%;
  left: 50%;
  margin-left: -15px; 
}
 
.speech-bubble-left:after {
  border-right-color: #292929;
  top: 50%;
  right: 100%;
  margin-top: -15px;  
}
 

HTML:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="maopao.css">
        <title>Test</title>
    </head>
    <body>
        <div class="speech-bubble speech-bubble-top">
            箭頭在頂部
        </div>
         <br/>
        <div class="speech-bubble speech-bubble-bottom">
            箭頭在底部
        </div>
        <br/>
        <div class="speech-bubble speech-bubble-left">
            箭頭在左側
        </div>
         <br/>
        <div class="speech-bubble speech-bubble-right">
            箭頭在右側
        </div>
    </body>
</html>

 
這個只用到了css沒用到有圖片哦。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.