Часто возникают вопросы, как позиционировать SVG внутри HTML.
Ниже моя попытка сделать это.
Решил так:
Помещаю блок svg в родительский контейнер <div class="container"> и уже его позиционирую относительно других блоков.
Стили, для наглядности, которые относятся только к внутреннему содержанию SVG, разместил внутри SVG. Их можно, также перенести к основным стилям, всё будет работать точно так же.
- Вариант с постоянным вращением SVG
body {
display: flex;
}
.container {
position:relative;
width:200px;
height:200px;
left:85%;
}
.rect {
position:relative;
width:200px;
height:700px;
background:#E6E6E6;
left:100%;
top:-50%;
}
img {
width: 700px;
}
.svg {
position: absolute;
top: -95.5%;
bottom: 0%;
left: 0%;
right: 0%;
}
<div class="image"><img src="https://i.stack.imgur.com/jSl5W.jpg"/>
<div class="container">
<svg id="svg1" class="svg" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-40 0 300 300" >
<defs>
<mask id="msk">
<path d="M-23 150 A100, 100 0 0 1 245 150" fill="grey" stroke="#111111" stroke-width="2" />
<path d="M245 150 A100,100 0 0 1 -23,150" fill="black" stroke="#111111" stroke-width="2" />
<text id="Text" fill="white" y="-15" x="10" >
<textPath xlink:href="#circ"> fill="white" LET`S GO! LET`S GO! LET`S GO! LET`S GO!
</textPath>
</text>
</mask>
<path id="circ" d="M10 150 A100, 100 0 0 1 210 150M210 150 A100,100 0 0 1 10,150" fill="none" stroke="#111111" stroke-width="2" />
</defs>
<style>
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
#text {
font-size:24px;
font-weight:bold;
mix-blend-mode: difference;
letter-spacing:12;
transform-origin: 50% 50%;
transform-box: fill-box;
animation: spin 6s infinite linear;
}
</style>
<path id="circ" d="M10 150 A100, 100 0 0 1 210 150M210 150 A100,100 0 0 1 10,150" fill="none" stroke="#111111" stroke-width="2" />
<g id="G1" >
<rect x="-40" y="0" width="300" height="150" fill="black" />
<rect x="-40" y="150" width="300" height="150" fill="white" />
</g>
<text id="text" fill="white" y="-15" x="10" >
<textPath xlink:href="#circ"> LET`S GO! LET`S GO! LET`S GO! LET`S GO! LET`S GO!
</textPath>
</text>
</svg>
</div>
<div class="rect"> </div>
</div>
- Вариант с вращением при наведении на SVG
Добавляются стили:
#G1:hover ~ #text {
animation-play-state: running;
body {
display: flex;
}
.container {
position:relative;
width:200px;
height:200px;
left:85%;
}
.rect {
position:relative;
width:200px;
height:700px;
background:#E6E6E6;
left:100%;
top:-50%;
}
img {
width: 700px;
}
.svg {
position: absolute;
top: -95.5%;
bottom: 0%;
left: 0%;
right: 0%;
}
<div class="image"><img src="https://i.stack.imgur.com/jSl5W.jpg"/>
<div class="container">
<svg id="svg1" class="svg" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-40 0 300 300" >
<defs>
<mask id="msk">
<path d="M-23 150 A100, 100 0 0 1 245 150" fill="grey" stroke="#111111" stroke-width="2" />
<path d="M245 150 A100,100 0 0 1 -23,150" fill="black" stroke="#111111" stroke-width="2" />
<text id="Text" fill="white" y="-15" x="10" >
<textPath xlink:href="#circ"> fill="white" LET`S GO! LET`S GO! LET`S GO! LET`S GO!
</textPath>
</text>
</mask>
<path id="circ" d="M10 150 A100, 100 0 0 1 210 150M210 150 A100,100 0 0 1 10,150" fill="none" stroke="#111111" stroke-width="2" />
</defs>
<style>
@keyframes spin {
from {transform:rotate(0deg);}
to {transform:rotate(360deg);}
}
#text {
font-size:24px;
font-weight:bold;
mix-blend-mode: difference;
letter-spacing:12;
transform-origin: 50% 50%;
transform-box: fill-box;
animation: spin 6s infinite linear;
animation-play-state: paused;
}
#G1:hover ~ #text {
animation-play-state: running;
</style>
<path id="circ" d="M10 150 A100, 100 0 0 1 210 150M210 150 A100,100 0 0 1 10,150" fill="none" stroke="#111111" stroke-width="2" />
<g id="G1" >
<rect x="-40" y="0" width="300" height="150" fill="black" />
<rect x="-40" y="150" width="300" height="150" fill="white" />
</g>
<text id="text" fill="white" y="-15" x="10" >
<textPath xlink:href="#circ"> LET`S GO! LET`S GO! LET`S GO! LET`S GO! LET`S GO!
</textPath>
</text>
</svg>
</div>
<div class="rect"> </div>
</div>