当浮动权利时,Firefox将内容从div中推出

时间:2017-03-18 15:35:02

标签: html css firefox margin

我目前正在为我的网站设计导航栏,我在firefox中遇到了一个问题。我的左侧有我的徽标,右侧有我的导航内容,但整个导航内容都被推出了nav div(仅限Firefox)。我该怎么做才能解决它?

火狐: http://i.cubeupload.com/OoAJIe.png

铬: http://i.cubeupload.com/QXo2KS.png

这是我的HTML:

  <div class="nav" id="nav">
    <div class="nav_content">

      <ul>
        <li class="logo"><a href="index.php"><img src="images/Spendr.png" /></a></li>

        <li class="tab btn"><a href="panel/index.php"><button>Kurv: 0</button></a></li>
        <li class="tab txt"><a href="#udbetaling">Nye varer</a></li>
        <li class="tab txt"><a href="#features">Udsalg</a></li>
        <li class="tab txt" id="kategorierMenu"><a>Kategorier</a></li>
      </ul>

    </div>
  </div>

这是我的CSS:

.nav {
    width: 100%;
    background: #262626;
    transition: background 0.5s, border 0.5s, color 0.5s, height 0.5s, padding-top 0.3s, opacity 0.5s;
    position: fixed /*fixed*/;
    z-index: 999;
    height: 71px;
    float: left;
}

.nav_content {
    max-width: 1150px;
    width: 90%;
    height: 100%;
    background: none;
    margin: 0 auto;
    white-space: nowrap;
}

.nav ul li, .nav ul li a {
    list-style: none;
    text-decoration: none;
    display: inline-block;
} .nav .tab{
    float: right;
    font-family: DroidSans, sans-serif;
    font-size: 16px;
    color: #FFFFFF;
    text-decoration: none;
    transition: color 0.3s;
}

.txt a {
    float: right;
    font-family: DroidSans, sans-serif;
    font-size: 16px;
    color: #FFFFFF;
    text-decoration: none;
    transition: color 0.3s;
    height: 100%;
    padding-top: 26px;
    box-sizing: border-box;
    transition: background 0.3s;
}

.txt a:hover {
    cursor: pointer;
    background: #1A1A1A;
}
.nav .tab { border-radius: 3px; }
.nav .txt a { 
    padding-left:18px;
    padding-right: 18px;
} 

.logo img {
    height: 36px;
    width: auto;
    margin-top: 18px;
    float: left;
}

1 个答案:

答案 0 :(得分:0)

由于您正确地将.tab元素浮动,添加.logo { float: left; },这将使列表项全部浮动在菜单的任一侧。

&#13;
&#13;
.nav {
  width: 100%;
  background: #262626;
  transition: background 0.5s, border 0.5s, color 0.5s, height 0.5s, padding-top 0.3s, opacity 0.5s;
  position: fixed/*fixed*/
  ;
  z-index: 999;
  height: 71px;
  float: left;
}

.nav_content {
  max-width: 1150px;
  width: 90%;
  height: 100%;
  background: none;
  margin: 0 auto;
  white-space: nowrap;
}

.nav ul li,
.nav ul li a {
  list-style: none;
  text-decoration: none;
  display: inline-block;
}

.nav .tab {
  float: right;
  font-family: DroidSans, sans-serif;
  font-size: 16px;
  color: #FFFFFF;
  text-decoration: none;
  transition: color 0.3s;
}

.txt a {
  float: right;
  font-family: DroidSans, sans-serif;
  font-size: 16px;
  color: #FFFFFF;
  text-decoration: none;
  transition: color 0.3s;
  height: 100%;
  padding-top: 26px;
  box-sizing: border-box;
  transition: background 0.3s;
}

.txt a:hover {
  cursor: pointer;
  background: #1A1A1A;
}

.nav .tab {
  border-radius: 3px;
}

.nav .txt a {
  padding-left: 18px;
  padding-right: 18px;
}

.logo img {
  height: 36px;
  width: auto;
  margin-top: 18px;
  float: left;
}

.logo {
  float: left;
}
&#13;
<div class="nav" id="nav">
  <div class="nav_content">

    <ul>
      <li class="logo">
        <a href="index.php"><img src="images/Spendr.png" /></a>
      </li>

      <li class="tab btn"><a href="panel/index.php"><button>Kurv: 0</button></a></li>
      <li class="tab txt"><a href="#udbetaling">Nye varer</a></li>
      <li class="tab txt"><a href="#features">Udsalg</a></li>
      <li class="tab txt" id="kategorierMenu"><a>Kategorier</a></li>
    </ul>

  </div>
</div>
&#13;
&#13;
&#13;

您还可以将菜单更改为flex布局,并在auto上使用.logo页边距来分隔元素。

&#13;
&#13;
.nav {
  width: 100%;
  background: #262626;
  transition: background 0.5s, border 0.5s, color 0.5s, height 0.5s, padding-top 0.3s, opacity 0.5s;
  position: fixed/*fixed*/
  ;
  z-index: 999;
  height: 71px;
  float: left;
}

.nav_content {
  max-width: 1150px;
  width: 90%;
  height: 100%;
  background: none;
  margin: 0 auto;
  white-space: nowrap;
}

.nav ul li,
.nav ul li a {
  list-style: none;
  text-decoration: none;
  display: inline-block;
}

.nav .tab {
  float: right;
  font-family: DroidSans, sans-serif;
  font-size: 16px;
  color: #FFFFFF;
  text-decoration: none;
  transition: color 0.3s;
}

.txt a {
  float: right;
  font-family: DroidSans, sans-serif;
  font-size: 16px;
  color: #FFFFFF;
  text-decoration: none;
  transition: color 0.3s;
  height: 100%;
  padding-top: 26px;
  box-sizing: border-box;
  transition: background 0.3s;
}

.txt a:hover {
  cursor: pointer;
  background: #1A1A1A;
}

.nav .tab {
  border-radius: 3px;
}

.nav .txt a {
  padding-left: 18px;
  padding-right: 18px;
}

.logo img {
  height: 36px;
  width: auto;
  margin-top: 18px;
  float: left;
}

.nav ul {
  display: flex;
}

.logo {
  margin-right: auto;
}
&#13;
<div class="nav" id="nav">
  <div class="nav_content">

    <ul>
      <li class="logo">
        <a href="index.php"><img src="images/Spendr.png" /></a>
      </li>

      <li class="tab btn"><a href="panel/index.php"><button>Kurv: 0</button></a></li>
      <li class="tab txt"><a href="#udbetaling">Nye varer</a></li>
      <li class="tab txt"><a href="#features">Udsalg</a></li>
      <li class="tab txt" id="kategorierMenu"><a>Kategorier</a></li>
    </ul>

  </div>
</div>
&#13;
&#13;
&#13;