简体   繁体   English

此div的margin-top在Firefox中不起作用

[英]margin-top for this div does not work in Firefox

I have divided my layout into divs, and within the div="content" area I have a table and a filter option which need to be positioned. 我已将布局划分为div,并且在div =“content”区域内,我有一个表和一个需要定位的过滤器选项。 I'm trying to insert some margin between the filter option area and the navigation bar. 我正在尝试在过滤器选项区域和导航栏之间插入一些边距。 This looks fine in Chrome but in Mozilla Firefox the filter options appear way below than they should. 这在Chrome中看起来不错,但在Mozilla Firefox中,过滤器选项看起来比它们应该的方式低得多。

This is my code and how it looks at the moment: 这是我的代码以及它当下的样子:

http://jsfiddle.net/elmiri/5mXJ7/ if you open this link in Chrome the filter option looks fine however in Mozilla it looks really bad. http://jsfiddle.net/elmiri/5mXJ7/如果您在Chrome中打开此链接,过滤器选项看起来不错,但在Mozilla中看起来非常糟糕。 Here is all of my code: 这是我的所有代码:

<div id="header">
<h1>LOGO</h1>
</div>

<div id="navigation">
<ul>
    <li><a href="">Home</a></li> 
    <li><a href="">Test</a>
    <li><a href="">Test</a>
    <li><a href="">Test</a> 
    <li><a href="">Activity Feed</a> 
    <li><a href="">Stats</a> 
    <li><a href="">Contact Us</a> 
    <li><a href="http://localhost/playtime/itms/Users/users.php">Users</a> 
    <li><a href="">My account</a> 
    </ul>

</div>
</body>
</html>
<div id="personalised">
<p>Hello, </p>
</div>
<div id="content">
<form id="form1" method="get" action="">
<div id= "filter">
  <label for="column">Select client type:</label>
  <select name="column" id="column">
    <option selected>Key</option>
    <option >Norm</option>
    <option >Onb</option>
  </select>
  <input type="submit" name="change" id="change" value="Filter">
  <input type="submit" name="Remove" id="Remove" value="Show all">
  </div>
<table>
  <tr>
    <th scope="col">Client name</th>
    <th scope="col">Client type</th>
    <th>&nbsp;</th>
    <th>&nbsp;</th>
  </tr>
    <tr>
    <td>Client2</td>
    <td>KEY</td>
    <td><a href="#" onclick="newWindow('update_clients.php?client_id=3', 800, 800)">EDIT</a></td>
    <td><a href="delete_clients.php?client_id=3">DELETE</a></td>
  </tr>
    <tr>
    <td>Client3</td>
    <td>KEY</td>
    <td><a href="#" onclick="newWindow('update_clients.php?client_id=5', 800, 800)">EDIT</a></td>
    <td><a href="delete_clients.php?client_id=5">DELETE</a></td>
  </tr>
    <tr>
    <td>client4</td>
    <td>NORM</td>
    <td><a href="#" onclick="newWindow('update_clients.php?client_id=7', 800, 800)">EDIT</a></td>
    <td><a href="delete_clients.php?client_id=7">DELETE</a></td>
  </tr>
    <tr>
    <td>client4</td>
    <td>ONB</td>
    <td><a href="#" onclick="newWindow('update_clients.php?client_id=8', 800, 800)">EDIT</a></td>
    <td><a href="delete_clients.php?client_id=8">DELETE</a></td>
  </tr>
    <tr>
    <td>client100</td>
    <td>Key</td>
    <td><a href="#" onclick="newWindow('update_clients.php?client_id=13', 800, 800)">EDIT</a></td>
    <td><a href="delete_clients.php?client_id=13">DELETE</a></td>
  </tr>
  </table>
</div>

This is the part of the code that positions the filter option: 这是定位过滤器选项的代码的一部分:

<div id= "filter">
  <label for="column">Select client type:</label>
  <select name="column" id="column">
    <option <?php if ($col == 'Key') echo 'selected'; ?>>Key</option>
    <option <?php if ($col == 'Norm') echo 'selected'; ?>>Norm</option>
    <option <?php if ($col == 'Onb') echo 'selected'; ?>>Onb</option>
  </select>
  <input type="submit" name="change" id="change" value="Filter">
  <input type="submit" name="Remove" id="Remove" value="Show all">
  </div>

the css code: css代码:

#filter {
float:right;
margin-top: 2%;
}

THIS filter div is within the Content div so I'm not sure if that's causing problem. 这个过滤器div在Content div中,所以我不确定这是否会导致问题。 I tried to set margin-top to 20 px and it still did not work in Firefox. 我试图将margin-top设置为20 px,但它仍然无法在Firefox中运行。 Would be grateful if someone helped me put a gap between the navigation bar and the filter option so that it looks fine both in Chrome and Mozilla. 如果有人帮助我在导航栏和过滤器选项之间设置了一个间隙,以便在Chrome和Mozilla中看起来都很好,那将不胜感激。 Thank you 谢谢

That's because the margin-top if set in a percentage it is proportional to the element's parent width and not height as one would normally expect. 这是因为margin-top如果设置为百分比,它与元素的父宽度成正比,而不是人们通常预期的高度。 Margin on MDN . MDN的保证金

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM