Show Bootstrap-5 dropdown out of overflowing container - drop-down-menu

As already asked here, i need to add dropdown into the table element which has scroll to x-direction (horizontal scroll) and in the last column there is one three dot icon where I need to add dropdown element. But dropdown menu always clips inside the table which is not good user experience.
As per the, Bootstrap doc, there is option named boundary but I am not getting how this boundary option works or even don;t know whether it entirely works or not and how.
If i remove relative position from dropdown parent which is with class dropdown and also remove from all the ancestors which is not static then I am getting correct behavior. I don;t feel it's the correct way to remove position relative only for getting this dropdown-menu out of container.
Is this the only solution or the boundary makes sense? I am not getting how popperconfig works and how should I use boundary aka data-bs-boundary?
In earlier version of bootstrap, with some code tweak, I used to get entire dropdown all the way at the end of the body element but not sure with this.

So here there are multiple things to consider when dropdown actually clips under the overflow parent/one of the ancestor parents(grand, great-grand and so on...)
We can apply position static to all parent/s to apply as a quick fix this without any javascript extra code when there are no css transformations/opacity (or any other property which creates stacking context) applied on any of them. But this is not helpful when any third party library adds many other elements in between.
We also need to consider the case when there is transform property applied to the parent/s because transform also creates a new stacking context even for the fixed position element. So in that case we have to move the dropdown menu out of the container. This question's answer discuss more on it.
Considering that there are multiple dropdowns with id's like myPopperDropdown-1, 2 etc.. which all are clipped under overflow hidden on one of the parent/s, we can do something like this.
$("[id*='myPopperDropdown-']").each(function(el,index) {
var parent, dropdownMenu, left, top;
$(this).on('show.bs.dropdown',function(){
parent = $(this).parent();
dropdownMenu = $(this).find('.dropdown-menu');
left = dropdownMenu.offset().left - $(window).scrollLeft();
top = dropdownMenu.offset().top - $(window).scrollLeft();
$('body').append(dropdownMenu.css({
position:'fixed',
left: left,
top: top
}).detach());
})
$(this).on('hidden.bs.dropdown',function(){
$(this).append(dropdownMenu.css({
position:'absolute', left:false, top:false
}).detach());
})
})
body {margin: 10px !important}
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="card">
<div class="card-body bg-light overflow-hidden">
<div class="bs-dropdown-1">
<div class="dropdown" id="myPopperDropdown-1">
<a class="btn btn-primary dropdown-toggle" role="button" href="javascript:void(0)" aria-expanded="false" data-bs-toggle="dropdown">Dropdown-1</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
</div>
</div>
<div class="card-body bg-light overflow-hidden mt-3">
<div class="bs-dropdown-2">
<div class="dropdown" id="myPopperDropdown-2">
<a class="btn btn-primary dropdown-toggle" role="button" href="javascript:void(0)" aria-expanded="false" data-bs-toggle="dropdown">Dropdown-2</a>
<ul class="dropdown-menu" style="position: absolute;">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul></div>
</div>
</div>
</div>
As of now not found any other better solution than this and even changing in popperConfig also not working due to restrictions applied even on fixed positioning.
Original answer was at Bootstrap dropdown clipped by overflow:hidden container, how to change the container?. which is somewhat modified here.

Related

Xpath grab div contents based on span class

<div class="accrd-row">
<h3 class="ui-helper-reset ui-accordion-header ui-corner-top ui-accordion-header-collapsed ui-corner-all ui-state-default ui-accordion-icons" role="tab" id="ui-id-1" aria-controls="ui-id-2" aria-selected="false" aria-expanded="false" tabindex="0"><span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><span class="icon icon-ki-act-panda"></span>Outdoor Activities</h3>
<div class="accrd-detail ui-accordion-content ui-corner-bottom ui-helper-reset ui-widget-content" id="ui-id-2" aria-labelledby="ui-id-1" role="tabpanel" aria-hidden="true" style="display: none;">Need to grab this text here</div>
</div>
I am trying to grab the text:
Need to grab this text here
Based on that the span above has the word "panda" in it. I know it is something like:
//span/#class[contains(.,'panda')]/following-sibling::a/div
But I cannot seem to get this to pick up the text.
You need to go back to the parent of span since the div you are looking for is a sibling of h3 not span.
There is probably a nicer way to do it but this is working for me to get the div element you need:
//h3//span[contains(#class, 'panda')]/parent::h3/following-sibling::div

Achieve interstitialSection of Srolllify

In this Scrollify Demo content height is greater than section height generated by default. Each Section has different height. Same scenario is with my code. I have a section with large amount of content. I have put this content class in interstitialSection. But that section is not behaving like demo.
<section class="features panel1 job-section">
<div class="container-fluid no-padding">
<div class="col-lg-12 col-md-12 col-sm-12 col-x-s-12">
<h1 class="career-color">Career Opportunities at TSR Darashaw</h1>
<p class="career-desc">Be a part of TSRDL Family and embark upon the path of Growth, Excellence and Success. We strive to create a cohesive Family of competent team-mates inspired to serve our prestigious clientele.</p>
<h3 class="career-color current-title">Current Openings</h3>
<div CLASS="job">
<h4 class="career-color">Associate - Payroll</h4>
<ul class="job-details">
<li><span>EXPERIENCE: </span><span>2-5 years</span></li>
<li><span>Location:</span><span>Mumbai - Mahalakshmi</span></li>
<li><span>JOB CODE:</span><span>AP001</span></li>
</ul>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
<i class="icon-plus"></i>
<p class="show-details">SHOW DETAILS</p> <button class="apply">APPLY NOW</button>
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<h4 class="career-color job-desc-title">JOB DESCRIPTION</h4>
<ul class="faq-points">
<li><span></span><p>Validity of the executed instrument of transfer</p>
<ul class="sub-points">
<li><span></span><p>for shares :- 60 days from the date of execution</p></li>
<li><span></span><p>for debentures :- for an indefinite period</p></li>
</ul>
</li>
<li><span></span><p>SEBI has notified vide its Circular No. MRD/DoP/Cir-05/2009 dated 20th May,2009 that it is mandatory for all transactions in the securities market including transfer of shares in physical form of listed Companies to be accompanied with copies of PAN Cards of ALL the transferees.</p></li>
<li><span></span><p>Further as per SEBI (Listing Obligations And Disclosure Requirements) Regulations 2015, both transferor and transferee are to furnish copy of PAN for transfer of securities.</p></li>
<li><span></span><p>Please therefore attach self attested copies of PAN Cards of both the transferee(s) and transferor(s) alongwith the instrument of transfer</p></li>
<li><span></span><p>Keep photocopies of certificates, instrument of transfer and other documents sent by post to TSRDL. In case of a loss in transit, they come in handy.</p></li>
</ul>
<h4 class="career-color job-desc-title">Profile requirements</h4>
<ul class="faq-points">
<li><span></span><p>Validity of the executed instrument of transfer</p>
<ul class="sub-points">
<li><span></span><p>for shares :- 60 days from the date of execution</p></li>
<li><span></span><p>for debentures :- for an indefinite period</p></li>
</ul>
</li>
<li><span></span><p>SEBI has notified vide its Circular No. MRD/DoP/Cir-05/2009 dated 20th May,2009 that it is mandatory for all transactions in the securities market including transfer of shares in physical form of listed Companies to be accompanied with copies of PAN Cards of ALL the transferees.</p></li>
<li><span></span><p>Further as per SEBI (Listing Obligations And Disclosure Requirements) Regulations 2015, both transferor and transferee are to furnish copy of PAN for transfer of securities.</p></li>
<li><span></span><p>Please therefore attach self attested copies of PAN Cards of both the transferee(s) and transferor(s) alongwith the instrument of transfer</p></li>
<li><span></span><p>Keep photocopies of certificates, instrument of transfer and other documents sent by post to TSRDL. In case of a loss in transit, they come in handy.</p></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
jQuery(function($) {
$(function() {
$.scrollify({
section:".panel1",
scrollSpeed:1100,
interstitialSection : ".job-section",
easing: "easeOutExpo",
overflowScroll: true,
scrollbars: true,
touchScroll:true,
updateHash: false,
offset : 0
});
});
});
Scroll in demo is smooth for option section till next section. But whenever i have scrolled in my code, control goes directly to the next section.
How can i achieve this same as demo.
Remove the job-section class from your section.

How would I place and center a logo between 2 lists in the bootstrap 3 navbar?

<body>
<nav class="navbar navbar-fixed-top" role="navigation">
<div class="navbar-inner" style="position: center;">
<ul class="nav navbar-nav">
<li>Home</li>
<li>Cottages</li>
</ul><a class="navbar-brand" href="#"><img src="http://placehold.it/150x150"></a>
<ul class="nav navbar-nav">
<li>Attractions</li>
<li>Contact</li>
</ul>
</div>
</nav>
Here's my code. I'm trying to put the brand in between the "Cottages" and "Attractions" links and center everything horizontally while keeping the layout responsive. Plus, I want the brand to extend vertically outside the navbar (existing without changing the height of a navbar).
If there is a better way to do this (rather than the HTML I have now) please let me know! Thank you.
Edit: here's a JSFiddle with my current code. Although I must say that the code results differently in my browser...
Use a wrapper class:
#wrapper {
margin:0 auto;
width:500px;
}
Apply this like this.
<div id="wrapper">
<nav> </nav>
</div>
if you need to resize it on a specific size based on a view-port you may need to use css #media Queries to alter the css based on a specific width.

Select visible xpath in list

I am trying to get the error message off of a page from a site. The list contains several possible errors so i can't check by id; but I do know that the one with display:list-item is the one I want. This is my rule but doesn't seem to work, what is wrong with it? What I want returned is the error text in the element.
//*[#id='errors']/ul/li[contains(#style,'display:list-item')]
Example dom elements:
<div id="errors" class="some class" style="display: block;">
<div class="some other class"></div>
<div class="some other class 2">
<span class="displayError">Please correct the errors listed in red below:</span>
<ul>
<li style="display:none;" id="invalidId">Enter a valid id</li>
<li style="display:list-item;" id="genericError">Something bad happened</li>
<li style="display:none;" id="somethingBlah" ............ </li>
....
</ul>
</div>
The correct XPath should be:
//*[#id='errors']//ul/li[contains(#style,'display:list-item')]
After //*[#id='errors'] you need an extra /, because <ul> is not directly beneath it. Using // again scans all underlying elements for <ul>.
If you are capable to not use // it would be better and faster and less consuming.

Center image within div

I've looked around and tried the suggestions to center an image, and it usually works just fine, but I've got a situation where something isn't right.
If you go to the test page:
http://www.503rephotography.com/_temp/ - you will see the image is pushed to the right a little bit, and if you increase or decrease the size of your screen, you will see it may shift a little further away from the center position.
I'm new to CSS and may have something messed up that is making this not work; I used some tips on here to make the div with the content on the page be somewhat centered. Now I'm just trying to center an image within that div box. Any help is much appreciated!!
You have to create a div container with margin-left:auto: and margin-right:auto; to center the content.
<div id="container">
<div id="header">
<h1 id="logo">
<a href="http://www.503rephotography.com">
<img src="images/logo.png" alt="503 rephotography">
</a>
</h1>
<ul class="navbar">
<li class="button">SERVICES</li>
<li class="button">PORTFOLIO</li>
<li class="button">CONTACT 503</li>
</ul>
</div>
<div id="topbar"></div>
<div id="content">
<img src="http://www.503rephotography.com/_temp/slides/1.jpg">
<div class="sub">
<p>Content will go here....why can't I get this div box to be centered???</p>
</div>
</div>
</div>
Try this fiddle see if it's what you need: http://jsfiddle.net/ftPa3/

Resources