Speech balloon with pure CSS--One step further

  Pi Ke        2013-03-16 04:11:58       4,429        0    

Many of us want to add cool features to our websites to make our websites user friendly ad more attractive. Especially in Web2.0 era. Today we are talking about adding speech balloon feature to our webpage so that we can display beautiful help windows while users mouse over some help icons on our page.

First, let me introduce one post written by named "How to create a speech balloon with pure CSS". He also explains how this works. You can also refer Magic CSS shape for more information. This is a brilliant idea. He uses the border property to construct the triangle without using any images. We all know that use of image is costly. This is really a good example you can use in you design.

But there is one small issue with it, this example requires the border color of the arrow div and the background color of the balloon div to be the same. Imagine if we want to have a border for the balloon div which has a different color with the div background color, then the arrow div will not have a border which has the same color as the balloon div's border color, this will introduce inconsistency. So how to solve this problem? You get it. We can add one more arrow div. The outer arrow div has the border width one more pixel larger than the inner arrow. div Then these two arrows overlaps, we will then get the arrow which has border effect.

The HTML code will be :

<div class="balloon"><div class="outer_arrow"></div>
<div class="inner_arrow"></div>But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?</div>

The CSS code can be :

  1. .balloon {  
  2.     background#FFFFFF;  
  3.   
  4.     border-radius: 4px;  
  5.     -moz-border-radius: 4px;  
  6.     -webkit-border-radius: 4px;  
  7.   
  8.     padding20px;  
  9.     positionrelative;  
  10.     font-size12px;  
  11.     width300px;  
  12.     text-alignjustify;  
  13.     color#3a3a3a;  
  14. }  
  15.   
  16. .balloon .outer_arrow {  
  17.     border-colortransparent #CCCCCC transparent transparent;  
  18.     border-stylesolid;  
  19.     border-width10px;  
  20.     displayblock;  
  21.     height: 0;  
  22.     left: -22px;  
  23.     positionabsolute;  
  24.     top21px;  
  25.     width: 0;  

  26. .balloon .inner_arrow {
  27.     border-colortransparent #FFFFFF transparent transparent
  28.     border-stylesolid
  29.     border-width: 10px
  30.     displayblock
  31.     height: 0; 
  32.     left: -20px
  33.     positionabsolute;
  34.     top: 20px
  35.     width: 0; 
  36. }

Basically, the inner arrow will overlap with the outer arrow and since the inner arrow has a background color of white and the outer arrow has a border of gray. So it looks like there is a one pixel gray color border around the inner arrow. This width can be adjusted accordingly.

Hope this small trick is helpful to you.

 

BORDER  SPEECH BALLOON  PURE CSS 

       

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

God : It's shut