how to have scrollbars on an inner div, not on the dialog - html

In the context of SharePoint, I call a dialog. SharePoint basically created a lightbox div and puts my html inside. I have no control over where it decides to display the dialog, nor of its dimensions, and not even of the CSS used for the containing page. In other words, whatever I can do must be included inside my own html/javascript/CSS.
The problem arrives because my html contains this one div that is sometimes
too high for the dialog,
which I would then naturally like to have a vertical scrollbar. I therefore define it with the CSS style of "overflow:auto".
But what I get instead is a scrollbar over the entire dialog, while the div is contained entirely in the dialog with no scrollbar at all.
I have traced the DOM, and I believe that the source of the problem is that the lightbox div containing my dialog is also defined with "overflow:auto". Apparently this takes precedence over the inner div, so that the vertical scrollbar is put on the containing div rather than on my inner div.
I am looking for a way to move the scrollbar from the dialog to the inner div. Please remember that I cannot change the CSS to get rid of the "overflow:auto" in the lightbox div that contains my html.
I can fix the problem by setting the height of the inner div to an absolute pixel value, but as I cannot predict in advance how much screen space is allocated to the other elements of the dialog or to the dialog itself, the visual results could be rather ugly.
Any ideas ?
Below is a simplistic example of the layout of the problem :
<div style="overflow:auto"> <!-- lightbox div -->
<!-- start of my html -->
<div style="overflow:auto !important">
<!-- high div -->
</div>
<div>
<button></button>
<button></button>
</div>
<!-- end of my html -->
</div> <!-- end of lightbox div -->
I should also mention that I am using Internet Explorer 9.

SharePoint has a funny way of calculating the height of the html I supply it for using inside the dialog. It probably calculates it while it is detached from the page, so that CSS positioning cannot work. Any attempt to use a clever CSS schema, such as proposed by Alexey Ivanov, therefore fails totally, with SP miscalculating the html as being extremely short. The best solution is this way butchered by SP not supplying a framework with a size for the CSS to position the elements inside.
So we are left with a javascript solution. As my html is not inserted at the topmost level of the iframe, I have no access to any body events. The only solution is then to use the onload event of an img element, as the only hookable event available, as counseled by Ann L. Unfortunately, a real image must successfully be loaded for this event to fire, so if necessary one can add a minimal 1-by-1 pixel image, which even it can be gotten out of the way with a style of "display:none".
The onload event is to contain javascript commands that will calculate the size of the dialog, subtract the total size of all elements except our maybe-too-high div, and set the height of this div to the calculated difference.
As DOM-traversal is quite broken in Internet Explorer, jQuery can be used to "fix" it by working around the bugs. If jQuery is not available, strong-arm methods can be used, such as looping on document.getElementsByTagName('div') to locate the divs of interest.
The SP divs that contain the supplied html can be identified by their className :
ms-dlgContent : the dialog itself
ms-dlgFrameContainer : the inner div that contains our html as its innerHTML and has the style of "overflow:auto" that conflicts with our own.
For the later, I have not managed to find any way of overriding its style of "overflow:auto". I finally settled for deleting its className by setting it to null. Not too big a loss, as the only style it contains is this same troublesome "overflow:auto".
All in all, quite a lot of work, both mental and programming, just because the SP programmers lacked a big enough imagination to take CSS positioning into account.

How about this? If you have an image in your inner div, it would have a jQuery "load" event. Since images tend to lag behind the rest of the document in loading, it would probably not fire until after the full DOM was complete. You could attach a handler to that.
Or, if you could stand having the scrollbars on screen for a second or two, you could use a timer inside your div and fire a method to change the outer div's style after enough time has passed that everything is loaded and set up.

First, I made this assumptions:
SharePoint lightbox do one of the following:
It's set width and height on itself.
OR It's positioning itself with position: absolute/relative.
OR It's loads content inside iframe.
Content that is not inside the inner overflow block (i. e. buttons) have fixed height.
If this assumptions are valid, then you probably can achieve described effect by position inner div div with "position: absolute", and entering left, right, top and bottom coordinates.
Example: http://jsfiddle.net/GxDcW/

You cannot get rid of the overflow: auto from the lightbox div with css or HTML, but you can with javascript. You don't need jquery or Mootools, a snippet of inline javascript should be fine
<script type="text/javascript">
var lightbox = document.body.getElementsByTagName("div")[0];
ligthbox.style.overflow = "visible";
</script>
This assumes the lightbox div is the first div on your page. If it's not, you can perhaps target it with it's id using getElementById or by targeting some wrapper div first.
Any other solution with css or html would most probably involve making it (over)complicated and error prone.

Related

How to get a tooltip to show when users hover over a div with a certain class and not show on others

I've actually got the tooltip showing where I want it to show, that part is working. The text it's displaying is contained in a <span> that's hidden until they hover over a div that has the tooltip class on it, similar to the example on w3schools.com.
I have a column of div's and only certain ones get the tooltip class. The problem I'm having is that the span is successfully hidden in the div's that don't have the tooltip class, but it's still reserving the space for it and I'm having trouble figuring out how to get it to not do that.
I'm hiding the <span> with CSS's visibilty:hidden which hides the text but the space for it is still reserved. If I change it to display:none instead of visibility:hidden it hides the text and does not reserve the space for it, which makes sense and that is almost what I want except I can't make it visible again without posting back.
So now I'm debating putting the whole thing inside of an ajax call so I don't have to refresh the whole page, but I'm not sure that would work either.
Is this even possible, or does anyone have any suggestions?
I appreciate any help anyone can offer.
Thanks
You can try span{position:absolute}
Use js instead of css.
If you use css then it'll also create problems on responsive.
You can use bootstrap tooltip or simple jQuery
https://jqueryui.com/tooltip/
what you can do is, give that div an id, and through css hover, set the tooltip's display to block,
or you can use, javascript for this, regidter those divs with a on hover, function , check the target of the hovered element, if it matches with that one, set tooltip's div display property to block,,simple

How to make AMP accordion expanded and collapsed smoothly

I do not find, there is any option or event to make the feel of accordion as my expectation in AMP's accordion library. However, I have done many changes using jquery but now I need to expand and collapse item smoothly. Is there any way to do this.
You can try using amp-selector and add CSS animations to achieve the same effect.
You can use this trick to animate from heigh 0 to auto. How can I transition height: 0; to height: auto; using CSS?
You may find this thread helpful to solve your issue. It stated that:
Currently there is no animation for the expand/collapse action. This means that it may be difficult for the user to track the behavior of the interface if multiple items are collapsing at the same time that their target element is expanding.
There is no scrolling adjustment when amp-accordion closes or opens, which means if a large enough (or large enough set of) amp-accordion(s) closes above the current viewport, the content inside the viewport could shift dramatically (even entirely out of view)
Needs some way for multiple amp-accordion elements to communicate with each other (could be a parent element with an attribute something like "auto-collapse-children")
Also, check this Content Collapse jQuery plugin to smoothly collapse and expand content by clicking the panel header, which acts as an accordion.

height control - multiple step form without absolute positioning

The following is the script I am using:
http://www.webdeveloper.com/forum/archive/index.php/t-152085.html
How can you have a container around a multiple step webform without the height/absolute positioning screwing stuff up?
Some of the steps I have have are different heights, and also with absolute positioning you can't have a wrapper with a background color.
My problem is the height is crazy because div's are being hidden but the height is still taken
Any alternative with the same script that allows a wrapper bg color and a height that alternates, instead of flooding the scrollbar?
EDIT: Here is a live example (notice the scrollbar issue?)
http://fastfolio.com/div-test/test.html
if the steps are different heights, the scrolling hurts. maybe some kind of #top fix or something? how do you get it to read the height and adjust accordingly?
Check jQuery as this will make handling the scroll easier.
In your example HTML page, replace the onclick with a function that checks current height of the div ( $(this).parent().parent().height() ) and the scroll position of the body ( $(body).scrollTop() ).
If the height is smaller than scrolTop then use the scrollTop to move the body up.
jQuery will take you 30 minutes to get your head around, but it's well worth it and wil solve a lot of queries like this.
You should not be using visibility to toggle the element shown but rather the CSS style of "display" (between "block" and "none" will do what you're after).
The pagination should also not rely on IDs - far better for you to use an array, and a "current state" holder. The "next" submit entity for should
http://consulting.euphemize.net/jack.shepherd/pagination-form/
Better options held in here :)

Fixed element that moves to top of page on scroll - CSS only

I'm looking to produce the effect that is on this page: http://jonrohan.me/guide/css/creating-triangles-in-css/ - but with just CSS, no JavaScript (this would be trivial with JavaScript).
The effect I'm talking about is as follows:
Initially you see both the page header and the article title.
when you scroll the page header disappears.
The article title becomes fixed to the top of the page, so you always see it as you scroll.
The best I've managed to achieve so far is this:
http://jsfiddle.net/nottrobin/2FSvx/
But I don't like the duplication of the <nav> inherent in my solution.
Does anyone have any clever CSS/3 techniques they can think of to make it so that when you scroll down and the <header> disappears, the <nav> would naturally ride up to the top of the page?
Your example has some issues, if I scroll the webpage down or up sometimes the two navs overlap and the content is displayed twice and overlapping.
As far as I know, there is no such technique to obtain the same effect using only CSS, JS is required.
You can position elements using CSS only in a static way (normal page flow), fixed way (relative to browser window), or absolute/relative (relative to the nearest parent with a position set to relative).
You cannot "listen" to a scroll event like you would do with JavaScript, hence you cannot position an element relative to the amount of scrolling, nor change its position value in real time, because you will need JavaScript even for this.
CSS is a presentational markup language, properties you assign to elements using CSS rules cannot be changed on an event-basis.
You could do something like you did, but that means more markup language, more CSS and more maintenance difficulties.
You should use JS to optimize the user's experience, if a user has JS disabled, he/she will see the normal page behavior, otherwise the nav element will remain still, like all other websites do.

Is it possible to have a popup div that 'breaks out' of an overflow:scroll or overflow:auto container?

I have a scrollable area that contains popup menus. Conceptually, something like this:
<div style="overflow:auto; width:100px; height:100px">
... content here that's big enough to trigger scrollbars...
<div>
Click here
<div style="position:relative">
<div id="popup"
style="display:none; position:absolute; width:150px; height:150px">
... more content. This div gets shown and hidden by jquery on click events.
</div>
</div>
</div>
</div>
The problem is that when the popup menu pops up, it is also contained within the scrolling div, and doesn't show up outside the 100x100 pixel scrollable area no matter how high I make the z-index. I realize of course that in a sense that's exactly what I asked for when I told the outer div to be overflow:auto in the first place. But for my use case it isn't what I want - I want the popup menu to be "over the top" and able to extend outside the scrollable area, while still staying in the right place, which is to say, directly underneath the "Click here" link. Even though the "Click here" link can move around as the container is scrolled.
I also realize that there are some complicated workarounds I could employ, like putting the popup entirely outside the scrollable div and using javascript to position it. And then I'd need to react to scroll events to reposition it as the content is scrolled, etc. Quite apart from needing to write lots of code to re-implement what the "position:relative/position:absolute" gave me for free, that'd also require quite a bit of refactoring of my own code, so I'd rather avoid it.
I'm wondering if there's some simple trick I can apply to my inner div to tell it to disregard its container's "overflow" property, or, failing that, a handy jquery script that will implement the complicated stuff for me behind the scenes so I just need to call it to get the effect I'm after.
I'd say that it's not possible to do that without using JS to calculate the position of the link and then display the popup with a position:fixed..
The problem is that your popup is inside a div with overflow:auto and everything inside that div will affect the scroll, so to show the popup you'll need to take it outside that div, and the only way i know to do that is by using the position:fixed... (or maybe using position:absolute on the popup, and a wrapper div with position:relative that contains the text and the popups)
so i'll propose 3 solutions:
put the popup outside the div with scroll, and when the user clicks
on the link, display the popup
calculate the exact position of the link (x,y) and display the popup using position:fixed and the coordinates
use a nice and always-easy-to-use "message box" (e.g. http://csscody.com/demo/wp-content/demo/popup/demo.htm) I know that this is not exactly what you wanted, but.. i ran out of ideas =D
I hope this helps
Displaying a popup inside a of a div with "overflow: auto", "overflow: scroll" or "overflow: hidden" will always generate this kind of issues. By rule, an element child can't be displayed beyond the parent's borders in all these cases because the overflow property makes precisely that. Using "position: fixed" to the popup will solve your issue BUT if you scroll down you'll see how the popup is displayed in the old position, previous to the scroll event. To solve this you can use JQuery, as follows:
$(".your-popup-PARENT-class").live( {
mouseenter: function(event) {
event.stopPropagation();
var position = $(this).offset();
$(this).find(".your-popup-class").css("top", (position.top + 30) );
$(this).find(".your-popup-class").css("left", position.left);
$(this).find(".your-popup-class").css("display", "inherit");
},
mouseleave: function(event) {
event.stopPropagation();
$(this).find(".your-popup-class").css("display", "none");
}
});
This code segment finds your popup parent element on the DOM tree, saves the current position and display the popup in the same position of the parent. As you can see, you can add or remove needed pixels, (bold code in previous CSS top definition).
Hopefully, this will be hepful for someone else with this kind of issue.
Kind regards!
I'm not sure what the effect you're going for is, but if you remove the popup's container, then the popup will show up outside of the scrollable div.
<div style="overflow:auto; width:100px; height:100px">
... content here that's big enough to trigger scrollbars...
<div id="popup"
style="display:none; position:absolute; width:150px; height:150px">
... more content. This div gets shown and hidden by jquery on click events.
</div>
</div>
I don't have an answer to this but if you ever found a good answer I'd love to hear about it. I have a very similar issue (I've a list of options for the user to select to modify the item in the scrolling section. It doesn't look so good if I'm near the bottom of the list.