css - 多个背景 css3 : 2 repeated-x images, 每个占容器的一半

标签 css background-image background-repeat

我有这个: http://jsfiddle.net/MAJZz/

我想要的是红色鱼停在容器的一半,绿色鱼从那里开始直到结束。 换句话说,红色鱼应该覆盖(从 0% 到 50% 水平方向),绿色鱼应该覆盖(从 50% 到 100% - 同样,水平方向)。

这是我的 html:

<div></div>

这是我的 CSS:

div {
    background: url(http://a0.twimg.com/profile_images/88812997/Redfish_facebook_normal.jpg) repeat-x, url(http://icons.iconarchive.com/icons/fasticon/fish-toys/16/Green-Fish-icon.png) repeat-x;
    position: absolute;
    top: 10px;
    left: 10px;
    width: 500px;
    height: 100px;
}

这可能吗?

提前致谢。

最佳答案

我认为你可以使用 after 和 before 伪类,如果你真的只需要两个背景,

div:before {
    background: url(http://a0.twimg.com/profile_images/88812997/Redfish_facebook_normal.jpg) repeat-x;
    position:absolute;
    left:0;
    width:250px;
    height:100px;
    content:"";
}
div {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 500px;
    height: 100px;
}
div:after {
    position:absolute;
    width:250px;
    height:100px;
    right:0;
    top:0;
    background:url(http://icons.iconarchive.com/icons/fasticon/fish-toys/16/Green-Fish-icon.png) 50% top repeat-x;
    content:""
}

关于css - 多个背景 css3 : 2 repeated-x images, 每个占容器的一半,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13144697/

相关文章:

html - 为什么图像不垂直拉伸(stretch)

javascript - 观看模态时使用物化 css 类将填充添加到我的页面

javascript - 如何将菜单滚动到菜单中的当前元素?

html - 我如何使用 :hover with multiple classes

jquery - 如果元素不适合屏幕,添加滚动条

html - 背景图像尺寸

html - 使用 overflow-x :scroll content 将模糊效果固定到 div 的右边缘

iphone - iPad 和 iPhone : full page background image shows cut off/screen shot link included

css - 添加背景图像后背景消失 :no-repeat;

css - 如何使用 css 将我的第二张 bg 图像 "url(repeat_bg_right_side.png) "重新定位到页面右侧?