cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  <div class="row">
    <div class="col-md-12">
      <h3 class="text-center">Bootstrap table with btn dropdown menu wrapping within table </h3>
      <div>
      <div class="tableresp table-responsive">
        <table class="table table-bordered">
          <thead>
            <tr>
              <th>h1</th>
              <th>h2</th>
              <th>h3</th>
              <th>h4</th>
              <th>h5</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>t1</td>
              <td>t2</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>
              <td>t3</td>
              <td>t5</td>
            </tr>
            <tr>
              <td>t1</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu" id="dropdown">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>
              <td>t5</td>
              <td>t2</td>
              <td>t3</td>
            </tr>
            <tr>
              <td>t1</td>
              <td>t2</td>
              <td>t3</td>
              <td>t5</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>
            </tr>
            <tr>
              <td>t1</td>
              <td>t2</td>
              <td>t3</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>
              <td>t5</td>
            </tr>
            <tr>
              <td>t1</td>
              <td>t2</td>
              <td>t3</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>
              <td>t5</td>
            </tr>
            <tr>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>
              <td>t2</td>
              <td>t3</td>
              <td>t4</td>
              <td>t5</td>
            </tr>
            <tr>
              <td>t2</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>

              <td>t3</td>
              <td>t4</td>
              <td>t5</td>
            </tr>
            <tr>
              <td>t2</td>
              <td>t3</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>

              <td>t4</td>
              <td>t5</td>
            </tr>
            <tr>
              <td>t2</td>
              <td>t3</td>
              <td>t4</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>

              <td>t5</td>
            </tr>
            <tr>
              <td>t2</td>
              <td>t3</td>
              <td>t4</td>
              <td>t5</td>
              <td>
                <div class="dropdown">
                  <button class="btn btn-primary btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Buy</button>
                  <ul class="dropdown-menu">
                    <li>
                      <span class="close">&times;</span>
                      <table class="table">
                        <tbody>
                          <tr>
                            <td colspan="2"><span>Part No:</span> 45</td>
                          </tr>
                          <tr>
                            <td><span>Pack:</span> 2 pcs</td>
                            <td><span>Weight:</span> 5 kg</td>
                          </tr>
                          <tr>
                            <td><span>Stk:</span> 100pcs</td>
                            <td><span>Bt:</span> 500pcs</td>
                          </tr>
                          <tr>
                            <td><input class="form-control input-sm" type="text" placeholder="PACKS"></input>
                            </td>
                            <td><button class="btn btn-default btn-sub">Add to cart</button></td>
                          </tr>
                        </tbody>
                      </table>
                    </li>
                  </ul>
                </div>
              </td>

            </tr>
          </tbody>
        </table>
      </div>
</div>
    </div>
  </div>
</div>
            
          
!
            
              body{
      background: brown;
    color: white;
}

.dropdown-menu {
  border-radius: 0;
  padding: 0;
}

.dropdown {
  display: inline-block;
}

.positioning{
    position: relative;
}

.positioning .tableresp .dropdown-menu:before{
    position: unset;
    content: unset;
}

.dropdown-menu {
  min-width: 310px;
  left: auto;
  right: 3px;
  border-color: #ececec;
  margin-top: 10px;
  box-shadow: 3px -3px 10px 1px rgba(0, 0, 0, 0.11);
  -webkit-box-shadow: 3px -3px 10px 1px rgba(0, 0, 0, 0.11);
}

@media (max-width:480px){
  .dropdown-menu {
    min-width: 200px;
  }
}

.dropup .dropdown-menu {
  margin-bottom: 10px;
}

.dropup .dropdown-menu:before {
  top: auto;
  bottom: -10px;
  transform: rotate(180deg);
  -webkit-transform: rotate(180deg);
}

.dropdown-toggle {
  padding: 5px;
  line-height: 1.1;
  border-radius: 4px;
  font-size: 11px;
  margin-right: 5px;
  background: #7a7a7a;
  border-color: #7a7a7a;
  position: relative;
}

.dropdown-menu:before {
  position: absolute;
  content: "";
  top: -10px;
  right: 5px;
  width: 0;
  height: 0;
  border: 10px solid white;
  border-top: 0;
  border-right-color: transparent;
  border-left-color: transparent;
}

.dropdown-menu li .close {
  position: absolute;
  right: 5px;
}

.dropdown-menu li table {
  border: 1px solid white;
  margin-bottom: 0;
}

.dropdown-menu li table tbody tr td {
  border-top: 0;
}

.dropdown-menu li table tbody tr td span {
  color: #59C3E3;
}

.dropdown-toggle.left-edge + .dropdown-menu {
  left: 0;
  right: auto;
}

.dropdown-toggle.left-edge + .dropdown-menu:before {
  left: 5px;
  right: auto;
}
            
          
!
            
                    $(".tableresp").on('click', '.dropdown-toggle', function(event) {

        if ($('.dropdown-menu').length) {
          var elm = $('.dropdown-menu'),
            docHeight = $(document).height(),
            docWidth = $(document).width(),
            btn_offset = $(this).offset(),
            btn_width = $(this).outerWidth(),
            btn_height = $(this).outerHeight(),
            elm_width = elm.outerWidth(),
            elm_height = elm.outerHeight(),
            table_offset = $(".tableresp").offset(),
            table_width = $(".tableresp").width(),
            table_height = $(".tableresp").height(),

            tableoffright = table_width + table_offset.left,
            tableoffbottom = table_height + table_offset.top,
            rem_tablewidth = docWidth - tableoffright,
            rem_tableheight = docHeight - tableoffbottom,
            elm_offsetleft = btn_offset.left,
            elm_offsetright = btn_offset.left + btn_width,
            elm_offsettop = btn_offset.top + btn_height,
            btn_offsetbottom = elm_offsettop,

            left_edge = (elm_offsetleft - table_offset.left) < elm_width,
            top_edge = btn_offset.top < elm_height,
            right_edge = (table_width - elm_offsetleft) < elm_width,
            bottom_edge = (tableoffbottom - btn_offsetbottom) < elm_height;

          console.log(tableoffbottom);
          console.log(btn_offsetbottom);
          console.log(bottom_edge);
          console.log((tableoffbottom - btn_offsetbottom) + "|| " + elm_height);
          // console.log(elm_width + " element width");              
          // console.log(elm_height + " element height");

          // console.log(table_width + " table width");
          // console.log(table_offset.left + " table offset left");
          // console.log(tableoffright + " table offright");
          // console.log(docWidth + " document width");
          // console.log(rem_tablewidth + " rem table width");

          // console.log(docHeight + " doc height");
          // console.log(table_height + " table height");
          // console.log(table_offset.top + " table offset top");
          // console.log(tableoffbottom + " table offbottom");
          // console.log(rem_tableheight + " rem table height");

          // console.log(btn_offset.left + " btn offset left");
          // console.log(btn_offset.top + " btn offset top");

          var table_offset_bottom = docHeight - (table_offset.top + table_height);
          // console.log(table_offset_bottom + " table_offset_bottom");

          var touchTableBottom = (btn_offset.top + btn_height + (elm_height * 2)) - table_offset.top;
          // console.log(touchTableBottom + " touchTableBottom");
          // console.log(table_height + " table_height");
          // console.log(btn_height + " btn_height");
          // console.log(elm_height + " elm_height");

          var bottomedge = touchTableBottom > table_offset_bottom;

          if (left_edge) {
            $(this).addClass('left-edge');
          } else {
            $('.dropdown-menu').removeClass('left-edge');
          }
          if (bottom_edge) {
            $(this).parent().addClass('dropup');
            // $(this).parent().removeClass('dropdown');
          } else {
            $(this).parent().removeClass('dropup');
            // $(this).parent().addClass('dropdown');
          }

        }
      });
//use if table height is below 300
var table_smallheight = $('.tableresp'),
				positioning = table_smallheight.parent();

		if (table_smallheight.height() < 320) {
			positioning.addClass('positioning');
			$('.tableresp .dropdown,.tableresp .dropup').css('position','static');

		}else{
			positioning.removeClass('positioning');
			$('.tableresp .dropdown,.tableresp .dropup').css('position','relative');
		
		}
            
          
!
999px
Loading ..................

Console