Search code examples
cssdegrees

define css arrow's degree


How would I define the degree of an arrow created with css follows

<div class="bubble"></div>

.bubble
{
   background: none repeat scroll 0 0 #FF7401;
   border: 3px solid silver;
   border-radius: 25px;
   bottom: 18px;
   float: right;
   height: 63px;
   margin-right: 10px;
   padding: 0;
   position: relative;
   width: 250px;
}

.bubble:after
{
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 29px 16px 0;
  border-color: #ff7401 transparent;
  display: block;
  width: 0;
  z-index: 1;
  bottom: -29px;
  left: 47px;
}

.bubble:before
{
  content: '';
  position: absolute;
  border-style: solid;
  border-width: 31px 18px 0;
  border-color: silver transparent;
  display: block;
  width: 0;
  z-index: 0;
  bottom: -34px;
  left: 45px;
}

div.bubble p {
  color: #FFFFFF;
  font-size: 21px;
  font-weight: bold;
  margin-top: 10px;
  text-align: center;
}

http://jsfiddle.net/lgtsfiddler/GpUpZ/1/

What I want is that the arrow's right edge right should be longer and not equal to the left edge. In particular, the left edge should be perpendicular to the text-bubble, and the right edge should come to meet it. For better visualization, here is an example of what I'm trying to achieve:

enter image description here


Solution

  • The shape and direction of the arrow is determined by the individual border widths and colors

    A simple adjustment of individual values makes it easy to experiment. It's often also useful to write out the individual values for both widths and colors so see what's what.

    JSfiddle Demo

    CSS

    .bubble {
        background: none repeat scroll 0 0 #FF7401;
        border: 3px solid silver;
        border-radius: 25px;
        bottom: 18px;   
        height: 63px;
        margin: 50px;
        padding: 0;
        position: relative;
        width: 250px;
    }
    
    .bubble:after {
        content: '';
        position: absolute;
        border-style: solid;
        display: block;
        width: 0;
        z-index: 1;
        top:100%;
        left: 47px;
    }
    
    .bubble.one:after { /* straight left side */
        border-width: 29px 29px 29px 0;
        border-color: #ff7401 transparent transparent transparent; 
    }
    
    
    .bubble.two:after { /* straight right side */
        border-width: 29px 0px 29px 29px;
        border-color: #ff7401 transparent transparent transparent ; 
    }