0

I would want to code a box in HTML like the one I have added in the picture with the blue box cut at the top right corner.

box

I would like to know if I can do this or if this has to be taken as an image. Kindly do let me know.

Sirko
  • 72,589
  • 19
  • 149
  • 183
vikky114
  • 87
  • 1
  • 1
  • 8

4 Answers4

2

You can make it with css: http://jsfiddle.net/Cqnaa/

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Hello</title>
        <style>
        body{
                margin: 20px;
        }

        .box:after {
                content: "";
                position: absolute;
                top: 0px;
                right: 0px;
                border-width: 20px 20px 0 0;
                border-style: solid;
                border-color: #fff transparent;
                display: block;
                width: 0;
        }

        .box {
                color: #fff;
                background-color: #bbd0ed;
                position: relative;
                height: 80px;
                width: 150px;
                padding: 10px;
        }
        </style>
    </head>
    <body>
        <p class="box">
                Hello!
        </p>
    </body>
</html>

gl hf

0

This can be done with CSS:

.box-corner {
   /* You would prefer a png for the transparent background where the corner is */
   background-image: url('box-background.jpg');
   padding: 10px 10px 0 0; /* Assuming the corner is 10x10 */
}

And then instantiate it like this:

<div class="box-corner">Content</div>
Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
0

Take a DIV with some height and width with some background color. Then add a child div with background as the crop is there in image. Set the position of the child div as relative and set top and right to 0. Like below

  #childDiv{
       position : relative;
       background-image : url("cropedMark.png)"
       width : "Some width";
       height : "Some height";
       top : 0;
       right : 0
  }

Hope this helps.

Exception
  • 8,111
  • 22
  • 85
  • 136
  • Hello. Thanks a lot. This works too. But am looking for one where I don not want to have an image. Kindly scroll down for a working solution. – vikky114 Sep 28 '12 at 08:16
0

Here is an exact answer. http://jsfiddle.net/swGvr/

<style>
#target {
border-top: 30px solid transparent;
border-left: 30px solid #4c4c4c; 
border-right: 30px solid #4c4c4c; 
border-bottom: 30px solid #4c4c4c;
width:200px;
height:100px;
}
#target > div {
background-color:#4c4c4c;
width:230px;
height:130px;
margin-top:-30px;
margin-left:-30px;
position:absolute;
}
</style>
<div id="target"><div></div></div>

There are two CSS sharing width and height. You can generate another automatically using jQuery as well.

Won
  • 1,795
  • 2
  • 12
  • 22