多个背景彼此叠加(正常,拉伸,正常)

问题描述 投票:0回答:2

由于我faced an issue的背景图像对于不同分辨率的内容而言太短,我试图将背景分成3个部分并自动拉伸中间部分以相应地填充顶部和底部图像之间的空间。不幸的是,我没有在CSS中意识到这一点。怎么做到这一点?

content_background_top.png:1024 x 68px content_background_middle.png:1024 x 6px(拉伸) content_background_bottom.png:1024 x 71px

像这样的东西:

#content{
    width: 1024px;
    height: 950px;
    text-align: center;
    padding: 35px 0 35px 0;
    background: url(img/content_background_top.png), url(img/content_background_middle.png), url(img/content_background_bottom.png);
    background-repeat: no-repeat;
    background-size: 1024px 68px, 1024px auto, 1024px 71px;
}
html css css3 background-image
2个回答
1
投票

您需要指定背景位置和背景大小。另请注意,您需要最后列出较大的“中间”背景,以便它不会覆盖其他背景。

#content {
  width: 1024px;
  height: 950px;
  text-align: center;
  padding-top: 35px;
  background: url(http://i.stack.imgur.com/vNQ2g.png?s=128&g=1), url(http://i.stack.imgur.com/vNQ2g.png?s=128&g=1), url(http://i.stack.imgur.com/vNQ2g.png?s=128&g=1);
  background-repeat: no-repeat;
  background-position: 0% 0%, 0% 100%, 0% 50%;
  background-size: 100px, 100px, cover;
}
<div id="content"></div>

0
投票
#content{
    width: 1024px;
    height: 750px;
    text-align: center;
    padding: 40px 0 40px 0;
    background: url(img/content_background_top.png), url(img/content_background_bottom.png), url(img/content_background_middle.png);
    background-repeat: no-repeat;
    background-position: 0% 0%, 0% 100%, 0% 50%; /* Order: Top, Bottom, Middle */
    background-size: 1024px 68px, 1024px 71px, 1024px 100%;
}
© www.soinside.com 2019 - 2024. All rights reserved.