INFO: The CSS code is basically showing a name with a small line below and one you hover on it, the line starts completing to a full rectangle. When you hover out, it transitions back to being a line below the name.
The issue I am having is that, when I try changing the size of the text (in the rectangle), I have a ton of issues such as: - the rectangle needs adjusting for the new text height and width - the rectangle needs re-centring (for some reason it does not stay centred) - when the text is something like a name: e.g. John Smith, when the size is too big, the bottom of John, would start touching the top of Smith
QUESTION: How can I make the code a bit better, such that when I change the size of the text, everything fits automatically without a ton of re-adjustments?
HTML CODE
<header id="header">
<div class="svg-wrapper">
<svg class="svg-name" xmlns="http://www.w3.org/2000/svg">
<rect class="shape" />
<div class="text">John Smith</div>
</svg>
</div>
</header>
CSS CODE
header {
height: 450px;
background-image: url(/assets/img/logo.svg), url(/assets/img/background.jpe);
background-position: 20px 20px, bottom;
}
header nav {
float: right;
margin: 30px 30px 0 0;
}
header nav a {
display: inline-block;
margin-left: 20px;
color: rgba(0, 0, 0, 0.7);
}
header nav a:hover {
color: black;
}
header .svg-wrapper {
position: relative;
top: 50%;
transform: translateY(-50%);
margin: 0 auto;
width: 360px;
}
header .svg-wrapper:hover .shape {
stroke-width: 2px;
stroke-dashoffset: 0;
stroke-dasharray: 960;
}
header .svg-name {
height: 120px;
width: 360px;
}
header .shape {
height: 120px;
width: 360px;
stroke-dasharray: 140 940;
stroke-dashoffset: -674;
stroke-width: 8px;
fill: transparent;
stroke: black;
border-bottom: 5px solid black;
transition: stroke-width 1s, stroke-dashoffset 1s, stroke-dasharray 1s;
}
header .text {
text-transform: uppercase;
font-size: 132px;
line-height: 32px;
letter-spacing: 8px;
color: black;
top: -100px;
position: relative;
text-align: center;
}
FIDDLE URL
https://jsfiddle.net/snenkov/kshawbg5/6/
CODEPEN URL