CSS 背景由 5 部分图像编译而成,大小为文本

发布于 2024-10-28 21:25:48 字数 2073 浏览 3 评论 0原文

我目前正在 joomla 中制作一个标题,其背景由 5 部分图像组成。应该看起来像这样(只是一个 ASCII 示例)

{==--------}

它被分成

  1. Left ({=< )
  2. 标题(文本背景)
  3. 标题-右 (>=-)
  4. 中 (-)
  5. 右 (-})

希望大家可以想象这一点。现在,标题和中间需要重复 x,但我希望标题根据文本调整大小,据说是文本 div 的背景。我似乎无法正确组合 div 和 css 来正确执行此操作。现在我将每个部分的 div 包裹在 div 中,直到文本。文本结束后,他们会转到下一行。 display: inline 也没什么帮助。我猜我对 CSS 不太擅长。

提前致谢。

注意:我无法附上打印屏幕,因为图像受版权保护。

编辑:中间部分必须扩展,以便右侧部分到达末端,基本上占据整个宽度。

<代码> |<------------------------------DIV 的全宽-------------- ----------------->| {=<短文本>=-------------------------------------------------------- ------------------------} {=<更长的文本>=-------------------------------------------------------- -------------------} {=<更长的文字>=---------------------------------------------------- -----------}

感谢 Bazzz,我找到了一种方法。

由于中间设置为 width: 100% 时将到达右端,因此向后拉一点的唯一方法是使用较短的包装器。然后将“右”部分放在包装纸后面。

HTMLCSS

<div id="Header">
    <div id="Wrapper">
        <span id="Left">&nbsp;</span>
        <h1 id="Title">Title text</h1>
        <span id="Title-Right">&nbsp;</span>
        <span id="Mid">&nbsp;</span>
    </div>
    <span id="Right">&nbsp;</span>
</div>

#Header span, #Header h1 {
    display: inline-block;
    white-space:nowrap;
    overflow: hidden;
    width: 570px;
}
#Wrapper span, #Header h1 {
    display: inline-block;
    white-space:nowrap;//Don't wrap into 2nd line
    overflow: hidden;//This help with the 100% width setting
    width: 550px;//Header width - "Right" width
}
#Left {
    width: 20px;
    background: blue;
}
#Title {
    background: yellow;
}
#Title-Right {
    width: 20px;
    background: grey;
#Mid {
    width: 100%; //Maximize this
    background: green;
}
#Right {
    width: 20px;
    background: red;
}

I'm currently working on a heading in joomla with background formed from 5 parts of images. Should look like this (just an ASCII example)

{=<Text>=--------}

which is split into

  1. Left ({=<)
  2. Title (Background for the text)
  3. Title-Right (>=-)
  4. Middle (-)
  5. Right (-})

Hope you guys can visualize this. Now, Title and Middle need to be repeated x, but I want Title to size according to the text, supposedly background for the text's div. I can't seems to get the right combination of div and css to do it correctly. Right now I wrap div in div for each part until the text. After the text, they just goes to the next line. display: inline can't help much also. Guess I'm not so good with CSS after all.

Thanks in advance.

NOTE: I can't attach print screen as the images are copyrighted.

EDIT: the Middle part has to expand so that the Right part hits the end, basically occupying the whole width.


|<-----------------------------Full Width of DIV------------------------------->|
{=<Short Text>=------------------------------------------------------------------}
{=<Much Longer Text>=------------------------------------------------------------}
{=<Much Much Much Longer Text>=--------------------------------------------------}

Thanks to Bazzz, I've found a way to do it.

Since Middle when set to width: 100% will reach the right end, so the only way to pull back a little is by using a shorter wrapper. Then place the "Right" part after the wrapper.

HTML

<div id="Header">
    <div id="Wrapper">
        <span id="Left"> </span>
        <h1 id="Title">Title text</h1>
        <span id="Title-Right"> </span>
        <span id="Mid"> </span>
    </div>
    <span id="Right"> </span>
</div>

CSS

#Header span, #Header h1 {
    display: inline-block;
    white-space:nowrap;
    overflow: hidden;
    width: 570px;
}
#Wrapper span, #Header h1 {
    display: inline-block;
    white-space:nowrap;//Don't wrap into 2nd line
    overflow: hidden;//This help with the 100% width setting
    width: 550px;//Header width - "Right" width
}
#Left {
    width: 20px;
    background: blue;
}
#Title {
    background: yellow;
}
#Title-Right {
    width: 20px;
    background: grey;
#Mid {
    width: 100%; //Maximize this
    background: green;
}
#Right {
    width: 20px;
    background: red;
}

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

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

发布评论

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

评论(1

兮子 2024-11-04 21:25:48

这是我尝试创建您所要求的内容,看看它是否符合您的要求:

http://jsfiddle.net/47Aej/

您显然可以用您的图像替换 background: blue;background:red; 等。也可以随意更改“标题文本”,看看黄色部分的大小会根据文本而变化(最终与 h1 相同)。

HTMLCSS

<div id="Header">
<span id="Left"> </span><h1 id="Title">Title text</h1><span id="Mid"> </span><span id="Right"> </span>
</div>

#Header span, #Header h1 {
    display: inline-block;
}
#Left {
    width: 20px;
    background: blue;
}
#Title {
    background: yellow;
}
#Mid {
    width: 60px;
    background: green;
}
#Right {
    width: 20px;
    background: red;
}

Here is my attempt to create what you asked for, see if it matches your requirement:

http://jsfiddle.net/47Aej/

You obviously can replace the background: blue;, background:red; etc. with your images. also feel free to change the "Title text" to see that the yellow part will size according to the text (it is the same h1 in the end).

HTML

<div id="Header">
<span id="Left"> </span><h1 id="Title">Title text</h1><span id="Mid"> </span><span id="Right"> </span>
</div>

CSS

#Header span, #Header h1 {
    display: inline-block;
}
#Left {
    width: 20px;
    background: blue;
}
#Title {
    background: yellow;
}
#Mid {
    width: 60px;
    background: green;
}
#Right {
    width: 20px;
    background: red;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文