将按钮带到下拉列表的前面

时间:2017-02-08 06:58:30

标签: html css css3

我需要在我的下拉按钮中将按钮带到下拉列表的前面。即使我设置了z-index:

<div id="dd" class="wrapper-dropdown-5" tabindex="1">BOOK NOW
  <ul class="dropdown">
    <li><a href="#">Booking.com</a></li>
    <li><a href="#">Airbnb</a></li>
    <li><a href="#">Trip Advisor</a></li>
 </ul>
</div>

https://jsfiddle.net/2pdgc537/6/

- - - - 编辑-------------------------

我不需要降低下拉量我需要一些像https://s27.postimg.org/pqna239sj/sampel.png

这样的东西

3 个答案:

答案 0 :(得分:1)

您需要更改.wrapper-dropdown-5 .dropdown的顶部位置,即

.wrapper-dropdown-5 .dropdown
{
  top : 66%;
}

以下是工作代码段

function DropDown(el) {
  this.dd = el;
  this.initEvents();
}
DropDown.prototype = {
  initEvents: function() {
    var obj = this;

    obj.dd.on('click', function(event) {
      $(this).toggleClass('active');
      event.stopPropagation();
    });
  }
}

$(function() {

  var dd = new DropDown($('#dd'));

  $(document).click(function() {
    // all dropdowns
    $('.wrapper-dropdown-5').removeClass('active');
  });

});
/* DEMO 5 */

.wrapper-dropdown-5 {
  /* Size & position */
  position: relative;
  width: 200px;
  margin: 0 auto;
  padding: 12px 15px;
  z-index: 10;
  /* Styles */
  background: #63731b;
  border-radius: 50px;
  border: 5px solid transparent;
  border-color: #ffffff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
  color: white;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  -webkit-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -ms-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
}

.wrapper-dropdown-5:after {
  /* Little arrow */
  content: "";
  width: 0;
  height: 0;
  position: absolute;
  top: 50%;
  right: 15px;
  margin-top: -3px;
  border-width: 6px 6px 0px 6px;
  border-style: solid;
  border-color: #000000 transparent;
}

.wrapper-dropdown-5 .dropdown {
  /* Size & position */
  position: absolute;
  top: 66%;
  left: 0;
  right: 0;
  z-index: 5;
  /* Styles */
  background: #63731b;
  border-radius: 0 0 5px 5px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-top: none;
  border-bottom: none;
  list-style: none;
  -webkit-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -ms-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
  /* Hiding */
  max-height: 0;
  overflow: hidden;
}

.wrapper-dropdown-5 .dropdown li {
  padding: 0 10px;
}

.wrapper-dropdown-5 .dropdown li a {
  display: block;
  text-decoration: none;
  color: #ffffff;
  padding: 10px 0;
  transition: all 0.3s ease-out;
  /*border-bottom: 1px solid #e6e8ea;*/
}

.wrapper-dropdown-5 .dropdown li:last-of-type a {
  border: none;
}

.wrapper-dropdown-5 .dropdown li i {
  margin-right: 5px;
  color: inherit;
  vertical-align: middle;
}


/* Hover state */

.wrapper-dropdown-5 .dropdown li:hover a {
  color: #57a9d9;
}


/* Active state */

.wrapper-dropdown-5.active {
  border-radius: 40px;
  background: #E7B300;
  box-shadow: none;
  /*border-bottom: none;*/
  color: white;
  z-index: 10;
}

.wrapper-dropdown-5.active:after {
  border-color: #82d1ff transparent;
}

.wrapper-dropdown-5.active .dropdown {
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  max-height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">

        <div class="col-sm-4 h-center">
          <br/>

          <div id="dd" class="wrapper-dropdown-5" tabindex="1">BOOK NOW
            <ul class="dropdown">
              <li><a href="#">Booking.com</a></li>
              <li><a href="#">Airbnb</a></li>
              <li><a href="#">Trip Advisor</a></li>
            </ul>
          </div>


        </div>
      </div>
    </div>
  </div>
</div>
</div>

答案 1 :(得分:0)

在css .dropdown{margin-top:15%;}中添加此行。小提琴链接是:https://jsfiddle.net/6zw6j97b/

答案 2 :(得分:0)

只需像bolow一样编辑你的CSS。

.wrapper-dropdown-5 .dropdown {
  /* Size & position */
  position: absolute;
  top: 80%;
  display: block;
  left: 0;
  right: 0;
  z-index: 5;
  /* Styles */
  background: #63731b;
  border-radius: 0 0 5px 5px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-top: none;
  border-bottom: none;
  list-style: none;
  -webkit-transition: all 0.3s ease-out;
  -moz-transition: all 0.3s ease-out;
  -ms-transition: all 0.3s ease-out;
  -o-transition: all 0.3s ease-out;
  transition: all 0.3s ease-out;
  /* Hiding */
  max-height: 0;
  overflow: hidden;
}``