How can I show only corner borders?

pierreaurelemartin picture pierreaurelemartin · Jan 17, 2013 · Viewed 52.8k times · Source

I'm wondering if it's possible in CSS or jQuery to make a border but only for corner. Something like this:

****                         ****
*                               *
*                               *

             CONTENT

*                               *
*                               *
****                         ****

Answer

Niet the Dark Absol picture Niet the Dark Absol · Jan 17, 2013

Assuming <div id="content">CONTENT</div> and that CONTENT includes at least one HTML node.

#content {position:relative}
#content:before, #content:after, #content>:first-child:before, #content>:first-child:after {
    position:absolute; content:' ';
    width:80px; height: 80px;
    border-color:red; /* or whatever colour */
    border-style:solid; /* or whatever style */
}
#content:before {top:0;left:0;border-width: 1px 0 0 1px}
#content:after {top:0;right:0;border-width: 1px 1px 0 0}
#content>:first-child:before {bottom:0;right:0;border-width: 0 1px 1px 0}
#content>:first-child:after {bottom:0;left:0;border-width: 0 0 1px 1px}

Here's a Fiddle