You can use margin-top
and padding-top
.
padding-top
will expand the parent area, but a negative margin-top
keep it at the expected position.
It looks like you are avoiding overflow, but actually it is not.
div { width:500px; height:200px; background:red; margin: 50px; overflow: hidden; background-clip: content-box; padding-top: 200px; margin-top: -150px; } span { background: blue; color: white; position: relative; top:100px; display:block; width: 100px; margin: auto; } span:hover:after { content: attr(data-name); color: black; position: absolute; top: -150px;; left: 0; }
<div> <span data-name="here">hover</span> </div>
This can cause problems with pointers, but you can fix them using pointer-events
.
source share