【问题标题】:How to right-align a dropdown horizontal submenu?如何右对齐下拉水平子菜单?
【发布时间】:2016-10-05 23:00:04
【问题描述】:

这是我目前拥有的: 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;
}

这就是我想要得到的:

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

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

【问题讨论】:

标签: html css dropdown


【解决方案1】:

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

【讨论】:

  • 谢谢。我要正确:0;在 .dropdown-content 上
  • 给猫剥皮的许多不同方法。 :) 任何一种方式都差不多。
猜你喜欢
  • 2022-11-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-19
  • 1970-01-01
  • 2019-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多