Jure Jager
Jure Jager

Reputation: 146

Ribbon with border in it

It is possible to create ribbon with border inside. I have created default ribbon like this:

Ribbon without borders

But I need ribbon like this. I cannot use images.

Ribbon with border

What is the best possible solution?

Upvotes: 1

Views: 483

Answers (1)

Bram Vanroy
Bram Vanroy

Reputation: 28437

This is the best I could do.

h1 span:before, h1 span:after {
    content: "";
    height: 90%;
    margin-top: 2px;
    width: 70px;
    border: 3px solid black;
    position: absolute;
    top: 0;
}
h1 span:before {
    right: 100%;
    border-left: 0 none;
}
h1 span:after {
    left: 100%;
    border-right: 0 none;
}

h1:before, h1:after {
    content: "";
    height: 31px;
    width: 31px;
    margin-top: 8px;
    position: absolute;
    top: 0;
    -ms-transform: rotate(45deg);
    -webkit-transform: rotate(45deg);
    transform: rotate(45deg);
}

h1:before {
    border-top: 3px solid black;
    border-right: 3px solid black;
    right: calc(100% + 70px - 16px);
}
h1:after {
    border-bottom: 3px solid black;
    border-left: 3px solid black;
    left: calc(100% + 70px - 16px);
}

Notes:

  • Won't work with older browsers that don't support: transform, calc, :before and :after
  • This works with any length of the title, however if you change the font-size, you'll have to change the width and height of h1:before, h1:after manually.

Upvotes: 1

Related Questions