Jitendra Vyas
Jitendra Vyas

Reputation: 152657

How to keep border inside to take ribbon over to div?

In this example http://jsfiddle.net/aNmvc/15/ the red ribbon should touch the the edges of div which has border. How to achieve that? Is there a way to get border inside or something else?

HTML

<div class="box">
  <div class="corner">
  <span href="#">Best Ribbon around</span>  
   </div>
   <img src="http://lorempixel.com/250/300/sports/1/">
</div>

CSS

.box {border:2px solid green; position:relative;padding:3%; width:260px; background:#ccc; overflow:hidden;}

.corner {
    background-color: #a00;
    overflow: hidden;
    position: absolute;
    left: -3em;
    top: 2.5em;
    -moz-transform: rotate(-45deg);
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg);

}
.corner span {
    border: 1px solid #faa;
    color: #fff;
    display: block;
    font-size:.8em;
    font-weight:bold;
    padding: 0.5em 4em;
    text-align: center;
    text-decoration: none;
    text-shadow: 1px 1px 1px #000;
}

enter image description here

Upvotes: 3

Views: 1121

Answers (3)

sandeep
sandeep

Reputation: 92803

I know you accept @inderanil answers but you can do this with box-shadow property like this:

.box {
    position:relative;
    padding:3%;
    width:260px;
    background:#ccc;
    overflow:hidden;
    -moz-box-shadow: 0 0 0 2px green inset;
    -webkit-box-shadow: 0 0 0 2px green inset;
    box-shadow: 0 0 0 2px green inset;
}

http://jsfiddle.net/aNmvc/18/

Upvotes: 2

Nate Cook
Nate Cook

Reputation: 93276

I would remove the border, padding, and background color from the box class and add it to the image inside:

.box { position:relative; overflow:hidden;}
.box img { 
    border:2px solid green;
    padding: 10px;
    background:#ccc;
}

Upvotes: 0

Indranil
Indranil

Reputation: 2471

Try this fiddle:

http://jsfiddle.net/aNmvc/16/

Basically, move the border and the background and padding to the image, and that way, the div.box can display till the edge and hide the rest.

Upvotes: 1

Related Questions