I’m trying to create a simple HTML script that shows a piece of text aligned to the left, and when hovered it reveals another piece of text. When shown, the text should be centered and directly above the hovered element’s text or if the revealed text is longer than the original text, left aligned. It should also work for any length of text.
I cannot figure out how to make it work when the "answer" is above the "question". I tried not having them in the same "container" and just positioning the answer above using relative and absolute positions, but I couldn’t figure out how to make it align properly with that route. I could only get it to center on with the width of the whole page.
.hide {
display: block;
text-align: center;
opacity: 0;
font-size: 10px;
}
.myDIV:hover+.hide {
opacity: 1;
}
.myDIV {
font-size: 20px;
text-align: left;
}
.myContainer {
position: absolute;
display: inline-block;
}
<div class="myContainer">
<div class="myDIV">Question</div>
<div class="hide">Answer</div>
</div>
2
Answers
Something like this. This doesn’t cover all the cases, but it might give you an idea.
Here’s what I came up with, should work with your case. You can also use wrapping.