Gabe
Gabe

Reputation: 971

Object with z-index child

I have a CSS ribbon that uses z-index for its sides. http://jsfiddle.net/2nMe9/

enter image description here

I want to place that object over a container, however, since the depth of the container is assumably set to 0 the margins of the ribbon will not show. http://jsfiddle.net/Ws4CD/

<center><div style="background: black;width: 500px; height:600px;">
<img src="http://m3.i.pbase.com/u45/gaocus/upload/34638653.160x160hawk1301b.jpg" alt="" style="position:absolute;" />
<div id="ribbon">
    <div id="r_content">Text</div>
</div>

How can I make the ribbon show completely?

Upvotes: 2

Views: 90

Answers (1)

Hardy
Hardy

Reputation: 5631

Change z-indexes from negative to positive (see the code). Problem was that background's z-index is 0 which is the default value for all elements. So putting z-index under 0 sends your ribbon parts behind that black background.

#ribbon {
        padding: .34em 1em;
        width: 129px;
        margin-top: 130px;
        position:relative;
        color: #ffffff;
        font: 16px 'Patua One', sans-serif;
        text-align: center;
        letter-spacing:0.1em;
        text-shadow: 0px -1px 0px rgba(0,0,0,0.3);
        box-shadow: inset 0px 1px 0px rgba(255,255,255,.3),
                    inset 0px 0px 20px rgba(0,0,0,0.1),
                    0px 1px 1px rgba(0,0,0,0.4);
         background: #1eb2df;
        display: inline-block;
    }

#ribbon:before, #ribbon:after {
        content: "";
        width:.2em;
        bottom:-.5em;
        position:absolute;
        display:block;
        border: .9em solid #1eb2df;
        box-shadow:0px 1px 0px rgba(0,0,0,0.4);
        z-index:0;
    }

#ribbon:before {
        left:-1.35em;
        border-right-width: .75em;
        border-left-color:transparent;
    }

#ribbon:after {
        right:-1.35em;
        border-left-width: .75em;
        border-right-color:transparent;
    }

#r_content:before, #r_content:after {
        content:"";
        bottom:-.5em;
        position:absolute;
        display:block;
        border-style:solid;
        border-color: #0675b3 transparent transparent transparent;
        z-index:1;
    }

#r_content:before {
      left: 0;
      border-width: .5em 0 0 .5em;
    }

#r_content:after {
      right: 0;
      border-width: .5em .5em 0 0;
    }

Fiddle: http://jsfiddle.net/mB3rn/

Upvotes: 1

Related Questions