How to give popper.js popper-box margin/ padding so it wont stick to the window borders - popper.js

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:
how to have the popper-box not stick to the browser window edges, (padding)
transform: translate on box including the arrow

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

Related

How to do a draggable expandlble div (React, Tailwind)

I'm trying to get something similar to what is on this pageThis is from the Tailwind CSS website, I'm interested in the sidegraber thingy that can shrink the parent div. So far i've been trying to use vanilla css 'resize' tag with:
resize: horizontal;
overflow: auto;
but it didn't work great 😅
Any tips? thanks!
You can actually inspect the tailwind site to see its css, as it actually uses Tailwind :D
You can see that the parent div is relative and it contains 2 divs, one empty, and one with the content. When you move the grabby thingy, you set a margin ot the empty div, and translate the grabby thingy the same amount to the left. In the example, i have dragged the thingy 55px to the left, so it translated it 55px to the left, and added a margin to the empty div (55px again).
You can calculate this pixel value by subtracting the current mouseX position from the Xposition when you first clicked and started dragging.

Drop Down CSS not working (Laravel Blades)

I have a view in which I am using some drop downs like
Access Link
I am unable to show border bottom, I have tried to give border-bottom or border definition manually in that elements CSS but couldn't fix. Any help
It is not that it has no bottom border, but it is just not being shown by your browser.
Your button has a height of 40px. But it is also contained in a div that has a height of 40px and a box-sizing of border-box.
Based on this, when using border-box with box-sizing, the height allocated to the content (in this case, your button) is reduced after considering the border and padding attributes of the element (in this case, your div). I just do not know why the content appears to be being rendered in a way that it overlays the bottom border of your container div.
Note that the box-sizing property in your CSS is applied to all elements, including :before and :after pseudo elements.
You can resolve your issue and show the bottom border if you do any of the following:
Reduce the height of the button element (e.g., set .ms-choice to have height of 38px).
Increase the height of the container div (e.g. set to 42px). This will just mis-align your dropdown menus with your search input.
Change the container div to have a box-sizing of content-box.
Change the background-color of your button to transparent and put the white background color on your div.ms-parent.form-control. (I added this option to show that the button' is actually being rendered such that it overlays the bottom border of the containing div.)

Why is the outline larger than its div?

UPDATE
To get the input back to the size I want it to be, I had to get rid of padding and borders. The following accomplished this:
*{padding:0; margin:0; border:0;}
Thanks to CBroe, I discovered this is unique to FF which adds to the input a default border of .75px and a padding of 1.5px. For a total of about 4.5px. Chrome does not.
UPDATE 2
The above fix only gets the child element back to the size I thought it should be. The accepted answer below shows that FF has a bug which explains why the outline didn't behave as it should, which is to outline the parent only and not expand for absolute positioned descendents.
I have two div elements stacked vertically with their outline property set to 1px. The div elements have a height of 117px.
I expect where the two div elements meet to have their outlines contiguous. It does so with no content.
When I place an absolute positioned input with top = 97px and height = 20px into the top div , the outline of that div is pushed down.
Here is a fiddle which shows this. If you remove the input, you will see how the top div outline sits next to the bottom div.
There are two things (at least) that I do not understand:
1) In examining the box using the browser's dev tools (Firefox), I see that the top div is in fact still 117px high. The outline should be drawn around the div, but appears not to be. Why?
2) The input has a top of 97px plus a height of 20px. Why would this affect the position of the outline? It looks like the outline is pushed down 4px.
That's because outlines are implementation dependent. It's not only the size:
Outlines may be non-rectangular.
From CSS3 UI,
This specification does not define the exact position or shape of the
outline, but it is typically drawn immediately outside the border box.
Firefox has historically had a tendency of making outlines bigger in various situations, e.g.
outlines are drawn outside (i.e., expanded by) box-shadow and other visual overflow
outlines are drawn outside (expanded by) outlines on descendant elements
The former was fixed, the latter seems the same as your problem.
I've 2 answers for you:
1) In examining the box using the browser's dev tools (Firefox), I see that the top div is in fact still 117px high. The outline should be drawn around the div, but appears not to be. Why?
The outline appears to be drawn around everything inside. So if an element stand out 100px at the bottom. The outline will also be moved 100px. In this case the input element stands out 8px. So the outline is 8px longer than you expected.
The input has a top of 97px plus a height of 20px. Why would this affect the position of the outline? It looks like the outline is pushed down 4px.
You were almost right there, 97px+20px is indeed 117px height. But you forgot to count 8px from the input element. This comes from a 3px thick border + 1px thick padding.

How do margin rules apply to elements not in the DOM flow?

So I asked this question: google chrome issue with fixed position and margin-top which finally got me to realize that top and margin-top are not the same thing. I don't know how I've missed that all these years.
Anyways that got me thinking what is the difference exactly between margin-top and top, which is how I found this question: CSS: Top vs Margin-top.
I already knew what margin-top did. But I had never extrapolated that out to think "hmm, this element is not in the DOM flow so what exactly is margin-top pushing it away from?"
From the question I asked I know that margin-top behaves in very unexpected ways when applied to an element with a fixed position. And that in Chrome at least this can lead to some crazy rules (like margin-top: -273%;).
So my Question is: How do browsers apply margin rules to elements not in the DOM flow (i.e. elements with a position value of fixed or absolute . And what about the way they are applied and rendered leads to rules, like the one described above, actually rendering the element inside the view-port?
The top property simply determines how far from the top of the containing element that the box-model should start being rendered. In the case of position: fixed, that is the window itself. In the case of position: absolute, it is the next parent element with a non-static position.
Margin, on the other hand, is part of the box-model itself. Adding margin to the top of the box increases the empty space present above the box.
Consider the following layers for a position: fixed box:
top:10px
margin-top:10px
------------border-top:1px------------
padding-top:10px
content
All of the margin, border, and padding are part of the box model. That entire element, or "piece", is just one big square when positioning. So, if you have a margin of 10px on the top of the box, and position the element 10px from the top, it will have the appearance of having 20px of margin between the top of the window and where the visible box starts.
I've also made a very simple example in jsFiddle.
If you like graphics, take this example, where the red box has a position: fixed:
As you can see in the first section, only setting position: fixed on the element doesn't actually move it anywhere. It just removes it from the flow of the document.
In the section section, adding a margin-top: 10px makes the element move down 10px because the box now has 10px of margin on the top of it. However, it hasn't actually moved anywhere. The box has just gotten taller because the box model has changed.
In the third section, using a top: 10px actually moves the box to be 10px from the top of the window container. It has the exact same box model as in the first section.
Section four is like the second section above it, except the negative margin causes it to move up ten pixels. The box model is still taller and the box still hasn't moved.
When you set an absolute position on an element, the element doesn't move at all if you don't set any other position properties. So, without a top, right, bottom, or left property set, the element stays in the position it would have been in if it had been rendered as part of the flow, it's just now removed from the flow. So adding a margin, either positive or negative, makes it appear to move up or down from that position. In reality, you're just changing the element's box model though.
You also have to realize that using a percentage on top and bottom margins (and even paddings) has nothing to do with the height. It actually uses the width to figure out how much margin is there. Saying margin-top: 10% will make that value 10% of the available width, not the available height, and making it negative will just negate that value. I mentioned this because it is relevant to that first question you linked where you were using percentages for margin-top.
I hope this covered what you were looking for. I couldn't tell what exactly you were confused about so I just explained as much as I could.

Rotated element without padding or margin is not glued to the side

I have a div which I rotate inside a container. I have not been able to get the rotated div to "stick" to the left-most side of the container. Please see this fiddle to see what I mean.
You need to set the transform-origin (-webkit-transform-origin and so on) to top left, and add translateX(-100px) after the rotiation (so like this: transform: rotate(-90deg) translateX(-100px)). Otherwise you are rotating around the center point (set a background on the rotated element and you'll see).
Side-note, make sure the filter isn't applied in IE9 (use a conditional comment), because otherwise both will be applied and the result is a black box.
Updated fiddle