dropdown menu with arrow in center

让人想犯罪 __ 提交于 2021-02-08 06:03:43

问题


I'm trying to create a dropdown menu like the one here, but I haven't been successful in styling it correctly.

The menu I'm looking to create is similar to one found here

Example:

enter image description here

This is what I have so far!

http://jsfiddle.net/9ggfz0st/1/

@import url('http://getbootstrap.com/dist/css/bootstrap.css');
.dropdown-menu:before {
  position: absolute;
  top: -7px;
  left: 9px;
  display: inline-block;
  border-right: 7px solid transparent;
  border-bottom: 7px solid #ccc;
  border-left: 7px solid transparent;
  border-bottom-color: rgba(0, 0, 0, 0.2);
  content: '';
}
.dropdown-menu:after {
  position: absolute;
  top: -6px;
  left: 10px;
  display: inline-block;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #ffffff;
  border-left: 6px solid transparent;
  content: '';
}
<div class="dropdown">
  <a data-toggle="dropdown" href="#">Dropdown trigger</a>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
    Account Settings<hr>Billing
  </ul>
</div>

I'm not able to center the arrow to the middle, also apply "drop down menu animation effect"

How can I center the arrow to the center?


回答1:


In order to change positioning of the arrow, simply change the left value like so:

.dropdown-menu:before {
  position: absolute;
  top: -7px;
  left: 40%;
  display: inline-block;
  border-right: 7px solid transparent;
  border-bottom: 7px solid #ccc;
  border-left: 7px solid transparent;
  border-bottom-color: rgba(0, 0, 0, 0.2);
  content: '';
}

.dropdown-menu:after {
  position: absolute;
  top: -6px;
  left: 40%;
  display: inline-block;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #ffffff;
  border-left: 6px solid transparent;
  content: '';
}

JSFiddle



来源:https://stackoverflow.com/questions/29997953/dropdown-menu-with-arrow-in-center

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!