Use CSS positioning methods with display.
Here I set the first img, i.e. closing icon, on display: none;and on :hoverof divI set it to lock, make sure that you use position: relative;in the parent element, otherwise it will fly in the wild.
Demo
div {
position: relative;
display: inline-block;
}
div img:first-child {
position: absolute;
top: 10px;
right: 10px;
display: none;
}
div:hover img:first-child {
display: block;
}
span,
2
ul > li > ul > li {
position: relative;
}
ul > li > ul > li > span {
position: absolute;
top: 10px;
right: 10px;
display: none;
}
ul > li > ul > li:hover > span {
display: block;
color: #fff;
}
, , , position: absolute; position: relative;
>, , li,
height: 25px;, ... ...