如何从该图像制作一个垂直可扩展的 DIV 框?

发布于 2024-10-06 13:12:56 字数 443 浏览 1 评论 0原文

我想从此图像为我的网站创建一个样式化的 DIV 框: alt text

如何使用 CSS 和 HTML 来做到这一点。

我将图像剪切为三个不同的部分:

  • alt text

  • 替代文字

  • alt text

但是我不知道如何将它们与 Div 一起使用来创建我的垂直消耗品盒子。

感谢您的帮助!

I would like to create from this image a styled DIV box for my website :
alt text

How can I do that using CSS and HTML.

I cut the image in three different parts :

  • alt text

  • alt text

  • alt text

However I don't know how to use them with Divs to create my vertically expendable box.

Thanks for your help!

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

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

发布评论

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

评论(4

酒与心事 2024-10-13 13:12:56

我假设您希望内容从顶部开始,但也扩展到第二个。如果是这种情况,那么您将需要在背景图像上进行一些重叠。

HTML

<div class="expandable">
    <div class="content top">content goes here</div>
    <div class="bottom"></div>
</div>

CSS

.expandable{
    background:url('middle-image.jpg') 0 0 repeat-x;
}
.top{
    background:url('top-image.jpg') 0 0 no-repeat;
    height:auto!important;
    height:100px;/* whatever the height of the top (big) area is */
    min-height:100px; /* whatever the height of the top (big) area is */
}
.bottom{
    background:url('bottom-image.jpg') 0 0 no-repeat;
    height:10px; /* whatever the height of the bottom image is. */
}

示例位于 http://www. jsfiddle.net/gaby/s8XZQ/

I assume that you want your content to start inside the top one, but expand to the second one as well. If that is the case then you will need some overlap on the background-images.

HTML

<div class="expandable">
    <div class="content top">content goes here</div>
    <div class="bottom"></div>
</div>

CSS

.expandable{
    background:url('middle-image.jpg') 0 0 repeat-x;
}
.top{
    background:url('top-image.jpg') 0 0 no-repeat;
    height:auto!important;
    height:100px;/* whatever the height of the top (big) area is */
    min-height:100px; /* whatever the height of the top (big) area is */
}
.bottom{
    background:url('bottom-image.jpg') 0 0 no-repeat;
    height:10px; /* whatever the height of the bottom image is. */
}

Example at http://www.jsfiddle.net/gaby/s8XZQ/

我的痛♀有谁懂 2024-10-13 13:12:56

这可以通过 CSS3 功能(如边框半径、盒子阴影和渐变)来完成。这是一个示例。应该适用于 Opera、Firefox、Chrome 和 Safari。

另外,您可以使用 :before 和 :after CSS 伪元素来执行此操作,就像其他两个答案一样。

编辑:对于 Internet Explorer,所有这些功能都可以通过行为文件实现,例如 PIE

This could be done with CSS3 features like border-radius,box-shadow and gradient. Here's an example. Should work in Opera, Firefox, Chrome and Safari.

Also, you can do this with :before and :after CSS pseudo-elements, like in other two answers.

Edit: For Internet Explorer all those features are possible with behavior file, like PIE.

oО清风挽发oО 2024-10-13 13:12:56

试试这个:
HTML:

<div class="container">
 <div class="top"></div>
 <div class="middle">content here content here content here</div>
 <div class="bottom"></div>
</div>

CSS:

.container { width: 300px; }
.top { padding-top: 15px; background: url(topimage.png); }
.middle { background: url(middleimage.png); }
.bottom { padding-bottom: 15px; background: url(bottomimage.png); }

调整 CSS 中的填充,使其与顶部图像和底部图像的高度相匹配,并调整容器宽度,使其与图像的宽度相匹配。

Try this:
HTML:

<div class="container">
 <div class="top"></div>
 <div class="middle">content here content here content here</div>
 <div class="bottom"></div>
</div>

CSS:

.container { width: 300px; }
.top { padding-top: 15px; background: url(topimage.png); }
.middle { background: url(middleimage.png); }
.bottom { padding-bottom: 15px; background: url(bottomimage.png); }

Adjust the paddings in the CSS so that they match the height of your topimage and bottomimage, and the container width so that it matches the image's widths.

错爱 2024-10-13 13:12:56

使用三个单独的 div,并将中间一个的顶部内边距设置为顶部的负高度。所以:

#top-div {
  height: 25px;
  background-image: url(bg-top.jpg);
}
#middle-div {
  background-image: url(bg-middle.jpg);
  padding-top: -25px;
}
#bottom-div {
  background-image: url(bg-bottom.jpg);
}

Use three separate divs, and set the top padding of the middle one to the minus height of the top one. So:

#top-div {
  height: 25px;
  background-image: url(bg-top.jpg);
}
#middle-div {
  background-image: url(bg-middle.jpg);
  padding-top: -25px;
}
#bottom-div {
  background-image: url(bg-bottom.jpg);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文