Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

html - Hover one element of linked elements

I have a circle and a text string grouped together in a page. I am trying to implement 3 possible situations:

. situation 1: when no elements are hover, only the circle should appear,

. situation 2: when the circle is hover, both the circle and the linked text should appear,

. situation 3: when the text is hover, only the circle should appear.

I can only implement the first 2 situations.

My attempt below:

.shape_text:hover .text {
  opacity: 1;
}

.text {
  opacity: 0;
}

.text:hover {
  opacity: 0;
}
<svg width="250" height="250">
  <g class="shape_text">
      <circle cx="30" cy="45" r="25" />
      <text class="text" x=0 y=100>That's a circle</text>
  </g>
</svg>
question from:https://stackoverflow.com/questions/65831517/hover-one-element-of-linked-elements

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your description seems a bit strange: What you wrote means that the circle should always be visible (1,2,3) and the text should only appear when the circle is hovered (2), which is quite easy:

text {
  opacity: 0;
}

circle:hover + text {
  opacity: 1;
}
<svg width="250" height="250">
  <g class="shape_text">
      <circle cx="30" cy="45" r="25" />
      <text class="text" x=0 y=100>That's a circle</text>
  </g>
</svg>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...