I am a newbie to web development and I’m facing an issue to complete my project. When I hover a text I want a paragraph or div to pop-up.
The code which I would be sharing is not my real project but is a copy of my real project error which I am facing. I tried the following tricks.
I tried making the "li#description" visiblity to hidden and on hover
li#hover:hover + li#description{
visibility: visible;
}
li#description{
display:none;
}
This didn’t work and when on hover I tried changing it to inline even this didn’t work.
Everything is similar you would find the name of the elements and the CSS not so good but it is just a copy
li {
list-style: none;
/* list-style: none; */
}
.hover-list {
display: flex;
align-items: center;
justify-content: center;
}
li#hover {
text-align: center;
background-color: darkslategray;
display: inline;
padding: 10px;
border-radius: 50px;
color: white;
}
li#description {
border: 2px solid black;
text-align: center;
padding: 10px;
font-size: large;
background-color: darkslategrey;
color: white;
}
<ul class="hover-list">
<li id="hover">
Hover Me!!
</li>
</ul>
<div id="description-div">
<ul class="description-list">
<li id="description">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Rerum consequatur veritatis facilis est voluptas obcaecati similique illo reiciendis a, eaque minima ullam totam dolor molestias officiis quia suscipit enim temporibus fugiat nulla possimus. Ut
recusandae laudantium in rem, nulla corrupti placeat ipsa assumenda consequatur et eveniet inventore voluptates officiis facilis id? Qui suscipit non maiores corporis quas adipisci dicta in enim amet magnam, repellendus, iusto recusandae laudantium
sit illo nemo delectus at officia saepe nihil obcaecati! Asperiores deserunt enim excepturi id dolorum hic expedita explicabo? Nesciunt, est ipsam! Velit in nostrum sunt consectetur laudantium ad inventore labore libero ducimus voluptates.
</li>
</ul>
</div>
2
Answers
You can keep your HTML as is and use some CSS trickery:
First set
li#description
to have display none. That way it doesn’t take up any space when its not visible.Then use
.hover-list:has(#hover:hover) + #description-div li#description{ display:block }
:has checks to see if any child match the selector, in this case checking to see if it has an element with the ID of hover that is being hovered. Then + will grab the next adjacement element, and then simply access the child with li#description and set it to having display block.