BootStrap下拉错误的位置

时间:2016-03-25 00:09:47

标签: javascript html css twitter-bootstrap

我创建了一个模态,在模态体中我想添加一个下拉按钮。

但由于某种原因,下拉是在完全错误的地方,我已经尝试在css中写它但无济于事

我先尝试过这个

<div class="modal-content">
  <div class="modal-header">
    <span class="close">×</span>
    <h2 align="left"><img src="/pic"width="50px" height="50px" />Share</h2>
  </div>
  <div class="modal-body">
    <input type="textarea" align="left" id = "shareSearchBar"  placeholder ="" name = "search">

    <div class="dropdown">
      <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        <img src="pic2"width="20px" height="20px" />Edit
        <span class="caret"></span>
      </button>
      <ul class="dropdown-menu  " aria-labelledby="dropdownMenu1">
        <li><a href="#" data-value="action"><img src="/pic"width="20px" height="20px" />E</a></li>
        <li><a href="#" data-value="another action"><img src="/pic"width="20px" height="20px" />V</a></li>
      </ul>
    </div>

我的css试图将按钮移动到正确的位置。

#dropdownMenu1 {
    position: absolute;
    top: 35%;
    right: 3%
}

.dropdown {
    position: absolute;
    top: 35%;
    right: 0%
}

然后我尝试了下面的非常相似但有点不同的内容

  <div class="modal-body">
    <button type="button" id = "dropdownMenu1" class="btn btn-small btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
      <img src="/pic"width="20px" height="20px" />Edit
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
      <li><a href="#" data-value="action"><img src="/pic"width="20px" height="20px" />e</a></li>
      <li><a href="#" data-value="another action"><img src="/pic"width="20px" height="20px" />v</a></li>
    </ul>
  </div>
</div>

相同的CSS ...

我真的无法看到这个。

enter image description here

2 个答案:

答案 0 :(得分:1)

@hat_to_the_back:这里更新了@Drinking People制作的小提琴..适合你想做的事情:

https://jsfiddle.net/Jyde/hcgd9u43/2/

<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>


<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Modal Header</h4>
  </div>
  <div class="modal-body">
    <div class="row">
     <div class="col-lg-6">
        <div class="input-group">
          <div class="input-group-btn">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><img src="/pic"width="20px" height="20px" />Edit <span class="caret"></span></button>
            <ul class="dropdown-menu">
              <li><a href="#" data-value="action"><img src="/pic"width="20px" height="20px" />e</a></li>
              <li><a href="#" data-value="another action"><img src="/pic"width="20px" height="20px" />v</a></li>
              <li><a href="#">Something else here</a></li>
              <li role="separator" class="divider"></li>
              <li><a href="#">Separated link</a></li>
            </ul>
          </div><!-- /btn-group -->
          <input type="text" class="form-control" aria-label="...">
        </div><!-- /input-group -->
      </div><!-- /.col-lg-6 -->
    </div>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
  </div>
</div>

答案 1 :(得分:0)

你能否重新启动你在模特秀节目中的下拉菜单。像这样:

$('#mymodal').on('shown', function() {
        $("#mydropdown").dropdown();
    });

并删除您的自定义CSS。

事件和initiliaze语法可以根据bootstrap的版本而改变。