使用 CSS 反向填充

发布于 2024-10-07 22:53:15 字数 1234 浏览 0 评论 0原文

我正在开发一个网站,并且正在尝试一些 CSS 的新东西。更多的是“天赋”,但我希望该网站看起来不错。 :)

alt text

在上图中,我希望该行实际上位于白色框中“欢迎来到” Moria”,所以看起来好像白线从盒子里出来并延伸出去。基本上,我希望白线下降几个像素。 (或者其他所有内容都增加了几个像素。)

这是该部分的 HTML:

<div class = "paragraphSection">
    <span class="textHeading">Welcome to Moria</span><span class="mainBodyText">
    Moria is a Minecraft server, which we have evolved into fun place to 
    build, talk, and fight. Everyone is welcome to join us play!  Of course, you should probably 
    read this page to understand what is happening, because it's a little more then 
    just Minecraft.</span>
    </div>

这是我尝试使用的 CSS:

.paragraphSection {
    border-top-style:solid;
    border-top-width:1px;
    border-color:white;
    padding-top:0px;

}

.textHeading {
    font-size:2em;
    padding-left:3px;
    padding-right:3px;
    background-color:white;
    padding:-10px;

    -moz-border-radius:5px 5px 5px 5px / 5px 5px 5px 5px;
    border-radius: 5px 5px 5px 5px / 5px 5px 5px 5px;
}

我尝试做的只是将填充元素设为负值,这样它就会“向上”而不是向下。然而,这根本不起作用。我以为你可以做到这一点,但显然不行。所以我不知道如何使paragraphSection的边框向下移动。

I'm working on a website, and I'm trying some new stuff with CSS. More for "flair" than anything, but I want the site to look good. :)

alt text

In the picture above, I want the line to actually be "in" the white box saying "Welcome to Moria" so it looks as though the white line comes /out/ of the box and stretches across. Basically, I want the white line down a few pixels. (or everything else up a few pixels.)

This is the HTML of the section:

<div class = "paragraphSection">
    <span class="textHeading">Welcome to Moria</span><span class="mainBodyText">
    Moria is a Minecraft server, which we have evolved into fun place to 
    build, talk, and fight. Everyone is welcome to join us play!  Of course, you should probably 
    read this page to understand what is happening, because it's a little more then 
    just Minecraft.</span>
    </div>

And this is the CSS I'm trying to use:

.paragraphSection {
    border-top-style:solid;
    border-top-width:1px;
    border-color:white;
    padding-top:0px;

}

.textHeading {
    font-size:2em;
    padding-left:3px;
    padding-right:3px;
    background-color:white;
    padding:-10px;

    -moz-border-radius:5px 5px 5px 5px / 5px 5px 5px 5px;
    border-radius: 5px 5px 5px 5px / 5px 5px 5px 5px;
}

What I tried to do was simply making the padding element negative, so it would go "up" instead of down. However, that didn't work at all. I thought you could do that, but apparently not. So I'm not sure how to make the border of the paragraphSection move down.

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

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

发布评论

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

评论(3

顾北清歌寒 2024-10-14 22:53:15

试试这个:

.textHeading{
  position:relative;
  top:-5px; //Adjust it according to what looks good to you.
  .
  .
}

Try this:

.textHeading{
  position:relative;
  top:-5px; //Adjust it according to what looks good to you.
  .
  .
}
迷乱花海 2024-10-14 22:53:15

我会选择负上边距:

.textHeading {
  margin-top: -5px;
  ...
}

根据规范不允许使用负填充,因此必须忽略:

与边距属性不同,填充值不能为负数。

来源:CSS 2.1 规范:8.4 盒子模型:填充属性

I would go for a negative top margin:

.textHeading {
  margin-top: -5px;
  ...
}

Negative padding is not allowed as per the spec and therefore must be ignored:

Unlike margin properties, values for padding values cannot be negative.

Source: CSS 2.1 Specification: 8.4 Box model: Padding properties

无语# 2024-10-14 22:53:15

其他样式会影响这些块。

请参阅我的示例: http://jsfiddle.net/DFEyj/ 看起来符合预期。

另请注意,您的语法非常冗长。

Other styles affect these blocks.

See my sample: http://jsfiddle.net/DFEyj/ Looks as intended.

Also do note, that you syntax is very verbose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文