csdngxl 2022-06-07 23:47 采纳率: 92.9%
浏览 77
已结题

html出现的默认外边距消除不掉

如图,我写的代码运行出来两边会有默认的8.5px外边距

img

我试过了body{margin:0px;}没有用
代码如下

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>index</title>
    <link rel="stylesheet" type="text/css" href="css/base.css">
    <link rel="stylesheet" type="text/css" href="css/common.css">
</head>
<body>
    <div class="header w">头部</div>
    <div class="box w">内容</div>
    <div class="footer w">底部</div>
</body>
</html>

base.css

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    -webkit-font-smoothing: antialiased;
    background-color: #fff;
    font: 12px/1.5 Microsoft YaHei, Heiti SC, tahoma, arial, Hiragino Sans GB, "\5B8B\4F53", sans-serif;
    color: #666;
}

common.css

.w {
    width: 1519px;
    margin: 0 auto;
}
.header {
    position: relative;
    height: 105px;
    background-color:red;
}
.footer {
    position: relative;
    height: 105px;
    background-color:green;
}

我也尝试过在style标签里面写以上样式,但没有出现8.5px的外边距
这到底是什么原因呢?

  • 写回答

3条回答 默认 最新

  • 王鹏飞的解忧屋 2022-06-07 23:56
    关注

    看一下右侧控制台都给第一个div赋值了哪些属性

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月13日
  • 已采纳回答 6月8日
  • 赞助了问题酬金5元 6月7日
  • 创建了问题 6月7日

悬赏问题

  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗