Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent border and box-shadow woes

Tags:

html

css

border

Consider the following:

HTML

<div class="info_bubble">
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque ornare ligula et nulla auctor vitae tincidunt erat congue.</p>
</div>

CSS

.info_bubble {
    padding: 0 15px;
    margin: 1em 0 3em;
    border: 5px solid #FFF;
    background: #A6CE39;
    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;
    width: 200px;
    box-shadow: 0 0 10px #000;
    color: #FFF;
    position: absolute;
    left: 50px;
    top: 50px;
}

.info_bubble::before {
    content: "";
    position: absolute;
    bottom: -20px;
    left: 40px;
    border-width: 20px 20px 0;
    border-style: solid;
    display: block;
    width: 0;
    top: 10px;
    bottom: auto;
    left: -23px;
    border-width: 15px 23px 15px 0;
    border-color: transparent #FFF;
}

.info_bubble::after {
    content: "";
    position: absolute;
    bottom: -13px;
    left: 47px;
    border-width: 13px 13px 0;
    border-style: solid;
    display: block;
    width: 0;
    top: 16px;
    bottom: auto;
    left: -15px;
    border-width: 9px 15px 9px 0;
    border-color: transparent #A6CE39;
}​

An example: http://jsfiddle.net/ysqQV/2/

The above generates a "Speech bubble" with a triangular "arrow" from the left-hand side. The arrow is created from borders, part transparent and part opaque.

I would like to use a box-shadow behind the speech bubble but this goes a little funky around the arrow as it drops a shadow from the whole element and not just the opaque section.

Example: http://jsfiddle.net/ysqQV/1/

I know this is normal behaviour and not an error but I would love to be able to clip the box-shadow to the opaque section of the arrow.

I can't use a single image for the speech bubble as the content could be of any height and I'd like to avoid using multiple images pieced together just because this solution is SO much cleaner.

Can anyone think of a viable work-around?

like image 712
Turnip Avatar asked Jun 18 '12 10:06

Turnip


People also ask

What does transparent border mean?

CSS Transparent border means that the behind object can be seen if we apply the border as transparent or rgba. Transparent border property beautifies the HTML page by making behind objects distinctly visible.

Can you set the border color to transparent?

Defines the color of the element's borders. default border-color: transparent; Applies a transparent color to the borders. The borders will still take up the space defined by the border-width value.

What is the difference between drop shadow and box-shadow?

Note: This function is somewhat similar to the box-shadow property. The box-shadow property creates a rectangular shadow behind an element's entire box, while the drop-shadow() filter function creates a shadow that conforms to the shape (alpha channel) of the image itself.

Can we apply transform property to box-shadow?

Using transforms on the box-shadow (& transform ) property, we can create the illusion of an element moving closer or further away from the user.


3 Answers

Use drop-shadow filter:

filter: drop-shadow(0 0 30px #333);
like image 84
Jake Avatar answered Nov 08 '22 22:11

Jake


What you are after isn't possible. However, I know a few workarounds:

First and easiest, loose the drop shadow from the arrow. It will still look good.

Secondly, use an image and bake in the shadow for the arrow. Might not be ideal, but it works.

Third option, just make a 20 by 20 square, with all those styles and then rotate it with a transform. You'll get a diamond, so next step is to use a mask to hide the edge you don't need. I've done this before, but it definitely goes a bit fuzzy in the process so I actually ended up going with the first option. If you can't use a mask, you can wrap the arrow in a div/span or something and set that to overflow hidden. Extra code, but same result.

I can provide an example for the final option if you need, but it'll be tonight before I get a chance.

Personally, I'd go with the first option though.

Hope that helps :)

like image 22
will Avatar answered Nov 08 '22 23:11

will


Its too late, but I have used your code to make it work for my site. So, here I am sharing it.

It needs just one additional like in the HTML, and some CSS changes:

<div class="arrow_mask"></div>

http://jsfiddle.net/ysqQV/123/

like image 42
Hamid Sarfraz Avatar answered Nov 08 '22 23:11

Hamid Sarfraz