随机 15px 边距?

发布于 2024-10-15 04:32:13 字数 1118 浏览 2 评论 0原文

我得到随机的 15px 顶部和底部边距,但我不知道它们来自哪里。

这种情况在 IE 中不会发生,只有 FF 和 Chrome 才会发生。

在以下示例中,每个“Here is content”段落上方和下方的间距是意外的。

#pageContent {
    background-color: #fff;
    padding: 10px;
}

#contentHead {
    height: 33px;
    width: 882px;
    color: black;
    font-size: 14px;
    font-weight: bold;
    line-height: 34px;
    padding-left: 48px;
    text-transform: uppercase;
}

#contentBody{
    background-color: #d4d3d1;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    -moz-border-radius: 0 0 10px 10px;
    border: 1px solid #8b8b8b;
}

#contentNoSidebar{
    background-color: #000;
    color: white;
}
<div id="pageContent">
  <div id="contentHead">Sample Page</div>
  <div id="contentBody">
    <div id="contentNoSidebar">
      <p>Here is content</p>
      ...
      <p>Here is content</p>
    </div>
  </div>
</div>

I am getting random 15px top and bottom margins and I have no idea where they are coming from.

This is not happening in IE, only FF and Chrome.

In the following sample, the spacing above and below each "Here is content" paragraph was unexpected.

#pageContent {
    background-color: #fff;
    padding: 10px;
}

#contentHead {
    height: 33px;
    width: 882px;
    color: black;
    font-size: 14px;
    font-weight: bold;
    line-height: 34px;
    padding-left: 48px;
    text-transform: uppercase;
}

#contentBody{
    background-color: #d4d3d1;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    -moz-border-radius: 0 0 10px 10px;
    border: 1px solid #8b8b8b;
}

#contentNoSidebar{
    background-color: #000;
    color: white;
}
<div id="pageContent">
  <div id="contentHead">Sample Page</div>
  <div id="contentBody">
    <div id="contentNoSidebar">
      <p>Here is content</p>
      ...
      <p>Here is content</p>
    </div>
  </div>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

为你拒绝所有暧昧 2024-10-22 04:32:13

如果您谈论的是每个

标记周围的边距,那么这是用户代理样式表固有的。
默认情况下,段落标签有一个周围的边距。如果您执行以下操作:

p { margin: 0; padding: 0; }

您应该能够摆脱边距/填充。

If you're talking about the margins surrounding each <p> tag, that is inherent from the user agent style sheet.
By default paragraph tags have a surrounding margin. If you do something like:

p { margin: 0; padding: 0; }

you should be able to get rid of the margin/padding.

起风了 2024-10-22 04:32:13

段落默认为 1em 垂直边距(顶部和底部,但它们可以重叠)。我猜你说的是 div 有下边距 - 但事实并非如此,那是它下面的 p 的上边距。

Paragraphs default to 1em vertical margin (top and bottom, but they can overlap). I guess you're talking about the div having a bottom margin - but it doesn't, that's the top margin of the p below it.

黑寡妇 2024-10-22 04:32:13

现在您添加了测试图像,我知道您的意思。

使用此 CSS 可以解决此问题:

p { margin: 0; padding: 16px 0 }

简而言之,使用 padding 而不是 margin 在段落之间提供相同的间距。

Now you added a test image, I know what you mean.

Use this CSS to fix the issue:

p { margin: 0; padding: 16px 0 }

In short, provide the same spacing between paragraphs using padding instead of margin.

总攻大人 2024-10-22 04:32:13

删除内容正文 css 上的 --moz-border-radius: 0 0 10px 10px; 命令并使用
边距:0 像素;根据您的内容进行填充。它会起作用,这就是声誉的原因。在mozila浏览器中使用firebug我们可以轻松找到错误。

Delete the --moz-border-radius: 0 0 10px 10px; command on your content body css and use
margin:0 px; padding based on your content.It will work, this is the reason for the reputation. Use firebug in your mozila browser we can easily find the bugs.

二智少女 2024-10-22 04:32:13

您的问题似乎已经解决,但您可能想开始使用 CSS 重置来覆盖所有内容的用户代理样式表内容。使您的网页样式变得更容易,使它们在大多数浏览器上看起来都相同。

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}

Your questions seems resolved already, but you might want to start using a CSS reset to override user agent stylesheet stuff for everything. Makes styling your web pages so they look the same on most browsers easier.

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section {
    display: block;
}
body {
    line-height: 1;
}
ol, ul {
    list-style: none;
}
blockquote, q {
    quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content: '';
    content: none;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文