I want to give a popper-box (tooltip) a padding to the window. So it has an offset to the window frame and does not stick at the edges
I tried to achieve this by adding a padding/ margin/ transparent border
to the popper-box. But all of these approaches have the downside that the arrow is being offsetted by the margin/ padding: https://jsfiddle.net/hq3tLf9k/ arrow being pushed down by 20px
the following approach was to have an inner div that has this padding/ margin
applied and leave the parent box untouched: https://jsfiddle.net/dz2ayntf/
this works for the positioning of the arrow, but I also want to animate-in the popper box (slide in) using a css transition: transform, transform: translate(0, 10px)
. This transition should apply to both, the box and the arrow. transfom: translate
unfortunately creates a relative position context and the position of the arrow is offsetted by the margin. https://jsfiddle.net/dz2ayntf/1/
So back to the original question:
In Popper 2 we no longer consider CSS margin because of inherent issues with it. Instead, to apply some padding between the popper and its reference element, use the offset modifier. You also need to remove margin from your arrows too; instead use the padding option in the arrow modifier. 5.
Instead, to apply some padding between the popper and its reference element, use the offset modifier. You also need to remove margin from your arrows too; instead use the padding option in the arrow modifier. 5. Ensure your popper and arrow box size is constant for all placements
Also, x-out-of-boundaries is now data-popper-reference-hidden. 4. Remove all CSS margins In Popper 2 we no longer consider CSS margin because of inherent issues with it. Instead, to apply some padding between the popper and its reference element, use the offset modifier.
Normally, we’ll need to add some more javascript and css style to deal with the positioning. But with popper.js, it’s a whole lot easier. Just create a new popper object and then pass the element that you want to use as reference, in this case is the button, and next the popup element, and finally the options.
found the solution:
The popper.js modifier preventOverflow
takes an object where you can pass options width a padding, this will be the distance to the "overflow element" here, the viewport
api documentation: https://popper.js.org/docs/v2/modifiers/prevent-overflow/#padding
https://jsfiddle.net/ynbad02x/
var state = Popper.createPopper(reference, popper, {
placement: 'right',
modifiers: [{
name: 'preventOverflow',
options: {
altAxis: true,
padding: 40
},
}]
});
the popover box has 40px padding to the edge, while scrolling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With