3个div作为背景

发布于 2024-08-26 21:40:37 字数 727 浏览 5 评论 0原文

我已经为此工作了几个小时,但似乎无法理解它。 我有下面三张图片,我希望文本内容位于这些图片之上,但我该怎么做?
中间的图像是随着容器 div 展开而需要重复的图像。

好吧,我确实为我缺乏信息而道歉,有点晚了而且我没有完全思考清楚。我想包含一个包含所有三个图像的容器。该容器的最小高度将是顶部和底部图像。当内容开始溢出这个最小高度时,中间图像将开始重复以适应更高的高度。

顶部: 替代文本 http://files.droplr.com/files/45544730/INDf3。 Page.png

中间重复: 替代文本 http://files.droplr.com/files/45544730/ INE5i.Page-Tile.png

底部: 替代文本 http://files.droplr.com/files/45544730/ INFbt.Page-Bottom.png

I've been working on this for a couple of hours and can't seem to wrap my head around it.
I have three images, below, and I would like the text content to sit on top of these, but how do I do it?
The middle image is the image that would need to repeat as the container div expands.

Okay, I do apologise for my lack of information, it's a little late and I'm not exactly thinking straight. I would like to comprise a container with all three images. The minimum height of this container would be the top and bottom image. As contents starts to overflow this minimum height, the middle image would start to repeat to accommodate for more height.

Top:
alt text http://files.droplr.com/files/45544730/INDf3.Page.png

Middle repeating:
alt text http://files.droplr.com/files/45544730/INE5i.Page-Tile.png

Bottom:
alt text http://files.droplr.com/files/45544730/INFbt.Page-Bottom.png

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

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

发布评论

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

评论(7

一个人的旅程 2024-09-02 21:40:37
TRY FOLLOWING

<div style="background:url(../top.png) no-repeat;">
  Top
</div>

<div style="background:url(../middle.png)">
  Middle:
</div>

<div style="background:url(../bottom.png) no-repeat;">
  Bottom
</div>

相反,提供类并在样式表中处理它

TRY FOLLOWING

<div style="background:url(../top.png) no-repeat;">
  Top
</div>

<div style="background:url(../middle.png)">
  Middle:
</div>

<div style="background:url(../bottom.png) no-repeat;">
  Bottom
</div>

Give class instead and handle it in your stylesheets

独自唱情﹋歌 2024-09-02 21:40:37
<div class='top'>
</div>
<div class='middle'>
</div>
<div class='bottom'>
</div>

为每个 div 提供单独的 background CSS 样式。


但我建议,
为文本 div 赋予 background 样式,以及 box-shadowborder
在这种情况下,您只需要中间图像。

<div class='top'>
</div>
<div class='middle'>
</div>
<div class='bottom'>
</div>

Give each div seperate background CSS styling.


But I would suggest,
Give background styling to the text div, along with box-shadow and border.
In this case, you will need only the middle image.

☆獨立☆ 2024-09-02 21:40:37

我的解决方案:

我通常这样做:

<div class="box">
  <span class="header"></span>
  content
  <span class="bottom"></span>
</div>

css:

.box { background: url(middle.png) repeat-y left top; }
  .box .header { background: url(top.png) no-repeat; display: block; margin-bottom: -480px; /* +set height and width */}
  .box .bottom { background: url(bottom.png) no-repeat; display: block; /*+ height and width*/}

通常,div 的底部很小,可以将其留空(为整个设计添加间距)。另外,负的 margin-bottom 大小应该是: -(height - what_you_want_to_remain_empty) - 即如果您的 .box .header 图像具有 540px 并且您希望将顶部 50px 留空,您将像我一样设置 -490px

祝你好运。

my solution:

I usually do it like this:

<div class="box">
  <span class="header"></span>
  content
  <span class="bottom"></span>
</div>

css:

.box { background: url(middle.png) repeat-y left top; }
  .box .header { background: url(top.png) no-repeat; display: block; margin-bottom: -480px; /* +set height and width */}
  .box .bottom { background: url(bottom.png) no-repeat; display: block; /*+ height and width*/}

usually, bottom of div is so small it's ok to leave it blank (to add spacing to whole design). Also, negative margin-bottom size should be : -(height - what_you_want_to_remain_empty) - i.e. if your .box .header image has 540px and you want to leave top 50px empty, you'll set -490px as I had.

Good luck.

九八野马 2024-09-02 21:40:37

到目前为止,拥有代码会很有帮助,但我会尝试一下。

每个图像都需要一个容器。

<div class="head"></div>
<div class="text">TEXT HERE</div>
<div class="foot"></div>

--css--

div.head { 
  background-image:url('top.png');
  background-repeat:no-repeat;
}
div.text {
  background-image:url('middle.png');
  background-repeat: repeat-y;
}
div.foot {
  background-image:url('bottom.png');
  background-repeat:no-repeat;
}

我可能想让第一张图像与最后一张图像的大小相同,并让第二张图像根据需要填充。

Having the code so far would be helpful, but I will give it a whirl.

You are going to need a container for each image.

<div class="head"></div>
<div class="text">TEXT HERE</div>
<div class="foot"></div>

--css--

div.head { 
  background-image:url('top.png');
  background-repeat:no-repeat;
}
div.text {
  background-image:url('middle.png');
  background-repeat: repeat-y;
}
div.foot {
  background-image:url('bottom.png');
  background-repeat:no-repeat;
}

I would probably want to make the first image about the same size as the last image and let the 2nd image fill in as needed.

萤火眠眠 2024-09-02 21:40:37

我认为在 Seth M 的回答中,您需要提供顶部(头部)和头部的高度。底部(脚)分区。

然后它就会正常工作。

i think in Seth M's answer, you need to provide height for top(head) & bottom(foot) div.

then it will work properly.

好菇凉咱不稀罕他 2024-09-02 21:40:37
div.box:before {content:url(top.png);}
div.box {
  background-image:url(middle.png) repeat-y;
  width:?;
  margin:0;
  padding:0;
}
div.box:after {content:url(bottom.png);}

这是一件很巧妙的事情,它将顶部和底部的图片作为图像放在框中,但始终是第一个和最后一个。当然,如果你有边距或填充,它就不起作用,但也尝试这样做:

div.box > div {padding:10px;}

<div class="box"><div>
  Content goes here
</div></div>

这应该以一种奇怪的方式为你提供你想要的东西。请注意,较旧的浏览器不支持这些 CSS 规则。

div.box:before {content:url(top.png);}
div.box {
  background-image:url(middle.png) repeat-y;
  width:?;
  margin:0;
  padding:0;
}
div.box:after {content:url(bottom.png);}

It's a neat thing, which puts the top and bottom pics as images inside the box, but always first and last. Of course it doesn't work if you have margins or paddings, but try doing this too:

div.box > div {padding:10px;}

<div class="box"><div>
  Content goes here
</div></div>

That should give you exactly what you want, in a sort of weird way. Beware that older browsers won't support these CSS rules.

﹏半生如梦愿梦如真 2024-09-02 21:40:37

这是使用您发布的图像的 HTML/CSS 完整代码。标题部分相当“高”。我认为这是你设计的一部分。

<html>
<head>
<style type="text/css">
div.top, div.body, div.footer {
margin: 0 auto;
width: 844px;
color: #ffffff;
background-color: #666666;
padding-left: 10px; /* edit accordingly */
}

div.top {
background: url(http://files.droplr.com/files/45544730/INDf3.Page.png) no-repeat;
height: 426px;
}
div.body {
background: url(http://files.droplr.com/files/45544730/INE5i.Page-Tile.png) repeat-y;
height: 200px;
}
div.footer {
background: url(http://files.droplr.com/files/45544730/INFbt.Page-Bottom.png) no-repeat left bottom;
height: 100px;
}
</style>
</head>
<body>
<div class="top">top
</div>
<div class="body">body
</div>
<div class="footer">footer
</div>
</body>
</html>

Here's a ful code with HTML/CSS using the images you posted. The header portion is rather 'tall'. I assume it's part of your design.

<html>
<head>
<style type="text/css">
div.top, div.body, div.footer {
margin: 0 auto;
width: 844px;
color: #ffffff;
background-color: #666666;
padding-left: 10px; /* edit accordingly */
}

div.top {
background: url(http://files.droplr.com/files/45544730/INDf3.Page.png) no-repeat;
height: 426px;
}
div.body {
background: url(http://files.droplr.com/files/45544730/INE5i.Page-Tile.png) repeat-y;
height: 200px;
}
div.footer {
background: url(http://files.droplr.com/files/45544730/INFbt.Page-Bottom.png) no-repeat left bottom;
height: 100px;
}
</style>
</head>
<body>
<div class="top">top
</div>
<div class="body">body
</div>
<div class="footer">footer
</div>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文