Home > database >  On hovering any elements transform all the elements
On hovering any elements transform all the elements

Time:05-19

I have 3 elements: svg, p and p

HTML code

<svg xmlns="http://www.w3.org/2000/svg"  width="335.312" height="119.152" viewBox="0 0 335.312 119.152">
    <path id="Path_2" data-name="Path 2" d="M334.1,0H58.861L0,58.861l58.861,58.861H334.1Z" transform="translate(0.707 0.723)" fill="#ed3430" stroke="rgba(0,0,0,0)" stroke-width="1"/>
</svg>

<p >Text A</p>
<p >Some text...</p>

Css code

svg, p {
    transition: transform 1s;
}

svg:hover, p:hover {
    transform: translate(-30px, 0px);
}

When I hover any of these 3 elements I would like to transform all these 3 elements. Currently, if I hover p element then only specific p element transforms leaving other 2 elements unaffected.

Updated - Video added

https://www.veed.io/view/b7a90341-0307-4ff1-a871-84639407086b

CodePudding user response:

If you want them all to do the same thing at the same time, you could wrap them in a container instead of trying to iterate through them and get them all to cooperate with each other.

.container {
  display: flex;
  flex-direction: column;
  transition: transform 1s;
  width:max-content;
}

.container:hover {
  transform: translate(-30px, 0px);
  transition: transform 1s;
}
<div >
  <svg xmlns="http://www.w3.org/2000/svg"  width="335.312" height="119.152" viewBox="0 0 335.312 119.152">
    <path id="Path_2" data-name="Path 2" d="M334.1,0H58.861L0,58.861l58.861,58.861H334.1Z" transform="translate(0.707 0.723)" fill="#ed3430" stroke="rgba(0,0,0,0)" stroke-width="1"/>
</svg>

  <p >Text A</p>
  <p >Some text...</p>
</div>

  • Related