I want to create fancy borders for an element but the vertical lines are giving me trouble
- the right side looks correct in this example but only works for this specific size (which i don't want) and AFAIK there is no way to calc() the width based on the height.
- I don't want to use another image for verical lines, but if there is no other solution, I would.
- I am not married to this approach but it's the only one I've been able to figure out.
Can anyone tell me how I can fix this?
.block
{
position: relative;
width: 400px;
height: 200px;
margin: auto;
background-color: silver;
}
.border
{
position: absolute;
width: 100%;
height: 100%;
}
.corner
{
width: 16px;
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCA1LjEuN4vW9zkAAAC2ZVhJZklJKgAIAAAABQAaAQUAAQAAAEoAAAAbAQUAAQAAAFIAAAAoAQMAAQAAAAIAAAAxAQIAEAAAAFoAAABphwQAAQAAAGoAAAAAAAAAYAAAAAEAAABgAAAAAQAAAFBhaW50Lk5FVCA1LjEuNwADAACQBwAEAAAAMDIzMAGgAwABAAAAAQAAAAWgBAABAAAAlAAAAAAAAAACAAEAAgAEAAAAUjk4AAIABwAEAAAAMDEwMAAAAAAlR56NozS1xQAAAFRJREFUOE+1kkEOABAMBNX//8xNlgwNrUkcumTTbllh2ioIpkXV4gXPwOQgnsEzzclhYPBQNbqfSBmB2iUNuekATXcGx9UpbkhA7k/8BgZGhEcIG3SUNQ8QLldnBgAAAABJRU5ErkJggg==');
}
.ne { transform: rotate(90deg); }
.se { transform: rotate(180deg); }
.sw { transform: rotate(270deg); }
.edge
{
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAFBhaW50Lk5FVCA1LjEuN4vW9zkAAAC2ZVhJZklJKgAIAAAABQAaAQUAAQAAAEoAAAAbAQUAAQAAAFIAAAAoAQMAAQAAAAIAAAAxAQIAEAAAAFoAAABphwQAAQAAAGoAAAAAAAAAYAAAAAEAAABgAAAAAQAAAFBhaW50Lk5FVCA1LjEuNwADAACQBwAEAAAAMDIzMAGgAwABAAAAAQAAAAWgBAABAAAAlAAAAAAAAAACAAEAAgAEAAAAUjk4AAIABwAEAAAAMDEwMAAAAAAlR56NozS1xQAAAB9JREFUOE9jYBgFFANGBgaG/+iCpAAmdIFRMAoGBAAA0EYBA3ATNTsAAAAASUVORK5CYII=');
background-repeat: repeat-x;
}
.n { flex-grow: 1; }
.e { transform: rotate(90deg); background-repeat: repeat-y; }
.s { flex-grow: 1; transform: rotate(180deg); }
.w { transform: rotate(270deg); background-repeat: repeat-x;};
<div class="block">
<div class="border" style="display:flex; flex-direction: column">
<div style="height: 16px; display:flex; flex-direction: row;">
<div class="corner nw"></div>
<div class="edge n"></div>
<div class="corner ne"></div>
</div>
<div style="flex-grow: 1; display:flex; flex-direction: row;">
<div class="edge w" style="background-color: #ffff0015; height: 16px; width: 168px; position:relative; top: 76px; right:76px"></div>
<div style="flex-grow: 1;"></div>
<div class="edge e" style="background-color: #ff000015; width: 16px;"></div>
</div>
<div style="height: 16px; display:flex; flex-direction: row;">
<div class="corner sw"></div>
<div class="edge s"></div>
<div class="corner se"></div>
</div>
</div>
<div style="padding: 12px">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
</div>