margin-bottom属性不起作用

时间:2016-01-02 18:13:12

标签: html css drop-down-menu

我有css代码:

$scope

HTML code:

.dropdown-menu {
  position:absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  display: none;
  float: left;
  min-width: 160px;
  padding: 5px 0;
  margin: 2px 0 0;
  list-style: none;
  font-size: 14px;
  background-color: #ffffff;
  border: 1px solid #cccccc;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  background-clip: padding-box;
}
.arrow {
position:absolute;
margin-bottom: 50px;
margin-left: 50px;
width: 0;
height: 0;
border-style: solid;
border-width: 0 5px 8.7px 5px;
border-color: transparent transparent #007bff transparent;
line-height: 0px;
_border-color: #000000 #000000 #007bff #000000;
_filter: progid:DXImageTransform.Microsoft.Chroma(color='#000000');
}

`

来自 <ul class="dropdown-menu"> <li class="arrow"></li> <li><a href="#">Credit History</a></li> <li><a href="#">Purchased Content</a></li> <li><a href="#">Access logs</a></li> </ul> 课程的margin-bottom: 50px;会向下移动我的箭头。如果我放arrow,我的箭仍然会下降。我试图把那个箭头放在下拉菜单的上方。

有谁能告诉我为什么我的箭不上去了?非常感谢你!

稍后编辑:我更新了问题。

FIDDLE here

2 个答案:

答案 0 :(得分:1)

你可能想要这样的东西

#menu_options {
position: absolute;
/*top: 100%;*/

}
.dropdown-menu {
  left: 0;
  z-index: 1000;
  float: left;
  min-width: 160px;
  padding: 5px 0;
  margin: 2px 0 0;
  list-style: none;
  font-size: 14px;
  background-color: #ffffff;
  border: 1px solid #cccccc;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
  background-clip: padding-box;
}

.arrow {
  position:relative;
  top:3px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 5px 8.7px 5px;
  border-color: transparent transparent #007bff transparent;
  line-height: 0px;
  _border-color: #000000 #000000 #007bff #000000;
  _filter: progid: DXImageTransform.Microsoft.Chroma(color='#000000');
}
<div id='menu_options'>
<li class="arrow"></li>
<ul class="dropdown-menu">
  <li><a href="#">Credit History</a></li>
  <li class="divider"></li>
  <li><a href="#">Purchased Content</a></li>
  <li class="divider"></li>
  <li><a href="#">Access logs</a></li>
</ul>
</div>

答案 1 :(得分:1)

我最终解决的解决方案是:

CSS代码:

    .dropdown-menu {
      position: absolute;
      display:none;
    /*  top: 100%;*/
      left: 0;
      z-index: 1000;
      float: left;
      min-width: 160px;
      padding: 5px 0;
      margin: 2px 0 0;
      list-style: none;
      font-size: 14px;
      background-color: #ffffff;
      border: 1px solid #cccccc;
      border: 1px solid rgba(0, 0, 0, 0.15);
      border-radius: 6px;
      -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
      background-clip: padding-box;
    }

.arrow {
  position:relative;
  left: 80%;
  bottom:13px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 5px 8.7px 5px;
  border-color: transparent transparent #fff transparent;
  line-height: 0px;
  _border-color: #000000 #000000 #fff #000000;
  _filter: progid: DXImageTransform.Microsoft.Chroma(color='#000000');
}

HTML code:

<ul class="dropdown-menu">
<li class="arrow"></li>
  <li><a href="#">Credit History</a></li>
  <li class="divider"></li>
  <li><a href="#">Purchased Content</a></li>
  <li class="divider"></li>
  <li><a href="#">Access logs</a></li>
</ul>

感谢@repzero。