Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS transform, push/pull surrounding elements

Tags:

css

transform

I'n using translateY() to pull an element up to overlap an element above it.

.element {
  transform: translateY(-50%);
}

It leaves space to the bottom. Is there any way to pull up any elements below it?

https://codepen.io/anon/pen/OBYRMe

In the example you can see it overlaps the element on top which is what I want but leaves space on the bottom. I am trying to achieve this without modifying other elements (e.g. use transform on elements on the bottom as well)

Note: using margin -50% does not work because it doesn't bring up the element 50% relative to the element's height. Only transform calculates the height to my knowledge.

like image 584
CyberJ Avatar asked Mar 11 '26 00:03

CyberJ


2 Answers

Use margin-top: -50%; instead. Happy coding

like image 113
Domenik Reitzner Avatar answered Mar 12 '26 13:03

Domenik Reitzner


You can apply transform on elements on bottom using the following css.I hope this is what you are looking for

.element ~ div {
    transform: translateY(-50%);
}
like image 34
Ashwin Avatar answered Mar 12 '26 12:03

Ashwin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!