如何右对齐下拉水平子菜单?

时间:2016-10-05 23:00:05

标签: html css html5 css3 dropdown

这就是我目前所拥有的: https://jsfiddle.net/pjt69trm/2/

HTML:

<body>
  <div class="dropdown">
    <button class="dropbtn">Language</button>

    <div class="dropdown-content">
      <a href="#" id="fr">Français</a>
      <a href="#" id="es">Español</a>
      <a href="#" id="en">English</a>
    </div>
  </div>
</body>

CSS:

.dropbtn {
    background-color: transparent;
    background-image: url("https://www.acadaslate.com/App_Themes/Default/images/glyphicon-triangle-bottom.png");
    background-repeat: no-repeat;
    background-position: right center;
    color: black;
    border: none;
    cursor: pointer;
    white-space: pre;
    font-size: 1.5vh;
}

.dropdown {
    position: absolute;
    display: inline-block;
    top: 5%;
    right: 50%;
    margin: 0 0;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: white;
    width: 350px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}

.dropdown-content a {
    color: black;
    padding: 12px 16px;
    text-decoration: none;
    display: inline-block;
    float: left;
}

.dropdown-content a:hover {
    background-color: #f1f1f1
    /* branco mais escuro quando passa o mouse por cima */
}

.dropdown:hover .dropdown-content {
    display: inline-block;
}

.dropdown:hover .dropbtn {
    /* se quiser que fique de outra cor quando passa o mouse por cima... */
    background-color: transparent;
}

这就是我想要的:

This is what I'm trying to get. (Click)

我觉得我需要更改CSS中的一行才能拥有它,但我不知道是什么。 :(

我一直在到处搜索,但没有成功。也许有人知道。

1 个答案:

答案 0 :(得分:0)

简单...将margin-left:-284px;添加到.dropdown-content