1

On click on the image, number displays as tooltip message for 4 seconds and disappears. This is working as expected. But while displaying the tooltip, the div height and width got changed. How can we display the tool tip on top of the image without affecting the height/width of the grid-container

I haved added a demo here:

https://codesandbox.io/s/amazing-ellis-2h3pd?file=/src/components/Home.js

3
  • If you could include your CSS and HTML into the link, that would be great, and would help SO users find the answer faster. Commented Jun 1, 2020 at 22:58
  • css is already avaiable under the styles.css in that link. Commented Jun 1, 2020 at 23:12
  • Sorry, I am not used to the CodeSandbox platform. Thanks! Commented Jun 1, 2020 at 23:13

1 Answer 1

1

First Solution

You can set position: absolute and apply necessary margins to make it appear on top of the image

{phoneTooltip === id && (
  <div style={{position: 'absolute', marginLeft: '100px', zIndex: 1, marginTop: '-50px'}} 
    className="tooltip_PhoneNumber_home" key={phonenumber}>
      {phonenumber}
</div>
)}

Second Solution

Refactor jsx so tooltip is always on top of image but with visibility: hidden, opacity: 0 and click action makes it visible.

<span className="phoneNumber_home">
  <div style={{opacity: phoneTooltip === id ? 1 : 0}} className="tooltip_PhoneNumber_home" key={phonenumber}>
    {phonenumber}
  </div>
  <img
    src="https://homepages.cae.wisc.edu/~ece533/images/tulips.png"
    alt={"phoneTooltip.show"}
    key={id}
    name="phoneNumberhomeicon"
    onClick={displayPhoneToolTip(id)}/>
</span>
Sign up to request clarification or add additional context in comments.

1 Comment

Happy to say that height and width extension is not happening anymore. In desktop view it look good, but in mobile view its going out of the container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.