I need a complex border for an anchor element. Unfortunately I can only solve the whole thing with CSS classes of the anchor element because I don’t have any options for the layout.
I already tested it with background linear-gradient but I didn’t reach a satisfactory result.
Here is an image as it should look, regardless of the font size and length of the text.
:root {
--gb-nav-btn-color-hover: red;
}
a {
border-radius: 0px;
display: block;
line-height: 30px;
width: fit-content;
height: fit-content;
padding-right: 25px;
background: linear-gradient(to bottom, var(--gb-nav-btn-color-hover) 2px, transparent 2px) 2px 0px, linear-gradient(to left, var(--gb-nav-btn-color-hover) 2px, green 2px) 0px -7px;
background-repeat: no-repeat;
background-position: center, center, center;
}
<a href="">An anchor element</a>
3
Answers
I hope this helps you
Pseudo-elements to the rescue. I’ve used
em
units (per Roko C. Buljan‘s helpful reminder) to keep the various aspects of the design in proportion to the font size.Also, I’ve put some common values in custom properties for easy configuration.