Transparent Inside Border

<div class="inner-border">
    Transparent Inside Border
</div>
.inner-border {
    background: #000;
    color: #fff;
    margin: 50px;
    padding: 15px;
    position: relative;
}
.inner-border:before {
    border: 5px solid #000;
    content: "";
    position: absolute;
    top: -10px;
    bottom: -10px;
    left: -10px;
    right: -10px;
}

Reference URL

Comments

  1. User Avatar
    oboshto
    Permalink to comment#

    Great snippet. Thank you, Chris.

  2. User Avatar
    Stijn
    Permalink to comment#

    You could do the same with:

    .inner-border {
          outline: solid black 5px;
          outline-offset: 5px;
    }

    or am i mistaking myself?

    • User Avatar
      Zach Saucier
      Permalink to comment#

      This has rendering errors in some browsers and also does not allow for border-radius effects

  3. User Avatar
    Mohsin @ startablog
    Permalink to comment#

    What is the use of this code. I mean to say where should i apply this technique.

  4. User Avatar
    Jon
    Permalink to comment#

    Actually, what Stijn said works. You just have to set the offset the negative of the outline width.

  5. User Avatar
    Mano
    Permalink to comment#

    Jon, using the outline property works great in Webkit-based browsers. Firefox however does not render it perfectly and IE 9 renders it like a normal border.

    Using Chris’ method works across all of these browsers.

  6. User Avatar
    payel

    hello,

    Thanks, worked great…
    .inner-border {
    background: #fff;
    color: #626262;
    padding: 15px;
    position: relative;

    }
    .inner-border:before {
    border: 4px solid #e7e7e7;
    content: “”;
    position: absolute;
    top: -10px;
    bottom: -10px;
    left: -10px;
    right: -10px;
    -webkit-box-shadow: 0px 0px 2px 2px rgba(0,0,0,0.29);
    -moz-box-shadow: 0px 0px 2px 2px rgba(0,0,0,0.29);
    box-shadow: 0px 0px 2px 2px rgba(0,0,0,0.29);
    }

  7. User Avatar
    Sajidur Rahman
    Permalink to comment#

    You should try this. Best solution i found :

    -webkit-box-shadow: 0px 0px 0px 1px #fff;
    box-shadow: 0px 0px 0px 1px #fff;

    It doesn’t adds any extra pixels.

  8. User Avatar
    Manichandra

    The solution given by “CHRIS COYIER” is very useful when we don’t want the border on all sides. The best solution.
    using outline and box-shadow we cannot chose sides.

    Look at the below link.

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

Submit a Comment

icon-closeicon-emailicon-linkicon-menuicon-searchicon-tag