html - 将下拉菜单的边从右更改为左

标签 html css

这是导航栏

1

现在我想换边到这个

2

* {
  margin: 0px;
  padding: 0px;
  font-family: "Oswald", sans-serif;
}
body {
  background-color: #E2DCDC;
}
nav {
  width: 994px;
  background-color: #77BCF1;
  border: 3px solid white;
  margin: 45px auto;
  color: black;
}
nav > .navigationbar_ul {
  list-style-type: none;
  width: 100%;
  font-size: 0px;
}
nav > .navigationbar_header {
  width: 100%;
  text-align: center;
}
.navigationbar_li {
  display: inline-block;
}
.navigationbar_li_left {
  border-right: 3px solid white;
}
.navigationbar_li_right {
  border-right: none;
  border-left: 3px solid white;
}
.navigationbar_li:last-child {
  margin-right: 0px;
}
.navigationbar_li > .navigationbar_a {
  color: black;
  font-size: 16px;
  display: block;
  padding: 10px 15px;
  text-decoration: none;
  transition: background-color 0.2s ease-in-out 0s;
}
.navigationbar_li > .navigationbar_a:hover {
  background-color: white;
}
.dropdown_ul {
  position: absolute;
  width: 100px;
  display: none;
}
.dropdown_ul > .dropdown_li {
  background-color: #77BCF1;
  border: 3px solid white;
}
.dropdown_ul > .dropdown_li > .dropdown_a {
  cursor: pointer;
  padding: 10px 15px;
  display: block;
  color: black;
  font-size: 16px;
  text-decoration: none;
  transition: background-color 0.2s ease-in-out 0s;
}
.dropdown_ul > .dropdown_li > .dropdown_a:hover {
  background-color: white;
}
.navigationbar_li:hover .dropdown_ul {
  display: block;
}
.float_left {
  float: left;
}
.float_right {
  float: right;
}
.clear_both {
  clear: both;
}
<nav>
  <ul class="navigationbar_ul">
    <div class="float_left">
      <li class="navigationbar_li navigationbar_li_left"><a class="navigationbar_a" href="#">Link 1</a>
      </li>
      <li class="navigationbar_li navigationbar_li_left"><a class="navigationbar_a" href="#">Link 2</a>
      </li>
    </div>
    <div class="float_right">
      <li class="navigationbar_li navigationbar_li_right"><a class="navigationbar_a" href="#">Link 3</a>
        <ul class="dropdown_ul">
          <li class="dropdown_li"><a class="dropdown_a">Link 1</a>
          </li>
        </ul>
      </li>
    </div>
    <div class="clear_both"></div>
  </ul>
</nav>

JsFiddle

我该怎么做?

最佳答案

可能想在您的帖子中添加一些代码!让我们更容易帮助您。

无论如何。我修改了您的 css,仅用于右侧导航栏的下拉菜单。我将 .navigationbar_li_right 的位置更改为 position: relative; 并将子项 .dropdown_ul 更改为 position: absolute; 将右边的值设置为0,right: 0;

更新:根据 jaunt 的评论修改。

.navigationbar_li_right {
  position: relative;
  border-right: none;
  border-left: 3px solid white;
}
.navigationbar_li_right .dropdown_ul {
  position: absolute;
  right: 0;
}

Fiddle

关于html - 将下拉菜单的边从右更改为左,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30487398/

相关文章:

html - CSS 命名约定 - 嵌套 CSS

javascript - 文档准备好后更新全局变量,并使用此变量通过 Jquery 更改 HTML

如果日期在范围内,则 JavaScript 删除类

javascript - 如何使用纯 javascript 而不是 jquery 构建加载更多 <li> 函数

html - 如何修复输入类型复选框右侧对齐并单击孔标签显示剩余文本?

html - 在 MVC 中链接样式表的正确路径

html - 移动 Chrome 浏览器显示与其他移动浏览器不同

html - 在div之间添加一个空白

css - 图片在手机和平​​板电脑上的调整大小不同?

javascript - 我如何让一个 div 出现在它的容器外面,并滚动,同时保持溢出在它的容器上