css - 如何使用伪元素添加响应图像

标签 css image responsive-design pseudo-element

我尝试使用图像和 css 伪元素添加框阴影和渐变边框。

我试过那个代码:

.box:before {
    content: url('box-shadow.png');
    position: absolute;
    width: auto;
    height: auto;
    max-width: 100%;
    z-index: -1;
    bottom: -9px;
    line-height: 0;
}
.box:after {
    content: url('box-border.png');
    position: absolute;
    width: auto;
    height: auto;
    max-width: 100%;
    bottom: -5px;
    right: 0px;
}

但是添加的图像不会在父 div 调整大小时调整大小,而它通过手动添加图像来工作。

看到那个 fiddle http://jsfiddle.net/5TG3E/2/

最佳答案

我从我这边试试可能对你有帮助。像这样写:

.box:after {
    content:'';
    position: absolute;
    z-index: -1;
    bottom: -9px;
    margin: 0 auto;
    top:0;
    left:0;
    right:0;
    background:url('http://dl.dropbox.com/u/4812171/box-shadow.png') no-repeat bottom center;
    -moz-background-size:100% 9px;
    background-size:100% 9px;
}
.box:before {
    content:'';
    position: absolute;
    bottom: 0px;
    right: 0px;
    left:0;
    top:0;
    background:url('http://dl.dropbox.com/u/4812171/box-border.png') no-repeat bottom right;
}

检查这个http://jsfiddle.net/5TG3E/6/

关于css - 如何使用伪元素添加响应图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10425162/

相关文章:

css - 如何将 "Error: Expected ' 样式解析为字符串数组?

javascript - 我需要为一个简单的图片库创建一个链接数组

c - 需要 JPEG 或其他有损图像压缩库

html - 无法将响应式 css 传递给在其他响应式页面中调用 Iframe 标记的页面

html - 如何向 `<option>` 列表中的 `<select>` 元素添加小缩略图?

html - 内部 div 元素位置

html - Outlook 2010 不在签名中包含样式标签

html - 根据屏幕大小将一个元素移动到另一个元素的下方或左侧

html - @font-face 未在任何浏览器中加载

c# - 调整许多位图大小时出现内存不足异常