【问题标题】:<a> tag still has margin even after setting global margin and padding to 0<a> 标签仍然有边距,即使将全局边距和填充设置为 0
【发布时间】:2022-11-13 11:52:25
【问题描述】:

就像标题一样,我想要一个大小为 320px*40px 的框,有 4 个较小的框,大小为 80px*40px,并且没有边距或填充。我使用了* { margin: 0; padding: 0; },但余量仍然存在。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    
    .box {
      height: 40px;
      width: 320px;
      border-top: 3px solid #ff8500;
      border-bottom: 1px solid #edeef0;
    }
    
    .box .minibox {
      padding: 0;
      margin: 0;
      text-decoration: none;
      display: inline-block;
      font-size: 12px;
      color: #4C4C4C;
      width: 80px;
      height: 40px;
      line-height: 40px;
      text-align: center;
    }
    
    .box .minibox:hover {
      background-color: #edeef0;
      color: #ff8400;
    }
  </style>
</head>

<body>
  <div class="box">
    <a href="#" class="minibox">guideline</a>
    <a href="#" class="minibox">guideline</a>
    <a href="#" class="minibox">guideline</a>
    <a href="#" class="minibox">guideline</a>
  </div>
</body>

</html>

我试图在标签的选择器中添加margin: 0; padding: 0;,但什么也没发生。

【问题讨论】:

  • 这与line-heightheightwidth 有关。现在超链接的边距为 0。
  • 我再次检查,我认为“行高”、“高度”和“宽度”没有问题。感谢您的评论,我会再次检查。

标签: css css-selectors


【解决方案1】:

删除宽度和高度,你有行高。我无法也无法使用 Chrome 看到该问题。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    
    .box {
      height: 40px;
      border-top: 3px solid #ff8500;
      border-bottom: 1px solid #edeef0;
    }
    
    .box .minibox {
      padding: 0;
      margin: 0;
      text-decoration: none;
      display: inline-block;
      font-size: 12px;
      color: #4C4C4C;
      width: 80px;
      line-height: 40px;
      text-align: center;
    }
    
    .box .minibox:hover {
      background-color: #edeef0;
      color: #ff8400;
    }
  </style>
</head>

<body>
  <div class="box">
    <a href="#" class="minibox">guideline</a>
    <a href="#" class="minibox">guideline</a>
    <a href="#" class="minibox">guideline</a>
    <a href="#" class="minibox">guideline</a>
  </div>
</body>

</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-11
    • 1970-01-01
    • 2013-01-09
    • 2014-03-05
    • 2012-06-19
    • 1970-01-01
    • 2012-06-02
    相关资源
    最近更新 更多