html - 调整浏览器大小时重叠并保持流畅的布局

标签 html css svg

我需要重叠图像和 svg(内联)。我还试图保持流畅的布局。

这是我的代码。图像正确重叠。但是当调整浏览器大小时,这两个文件并没有按比例缩小。

<div id="mainContainer">
<img src="img/png.png" style="position: relevent; z-index: 1; display:block; margin: 0 auto; max-width:400px; width:100%;" />
<svg class="containerA" preserveAspectRatio= "xMinYMid meet" viewBox="0 0 200 240" xmlns="http://www.w3.org/2000/svg">
////some stuff
</svg></div>

CSS

.containerA{
    margin-top:10px;
    display: block;
    position: relevent;
    top: 0;
    left: 0;
}
body {
    background: #fff;
    text-align: center;
}
#mainContainer{
    margin: 0 auto;
    max-width:400px;
    width: 100%;
    z-index:0;
}

最佳答案

使用以下代码:

.containerA {
    margin-top:10px;
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}
.pngIMG{
    max-width:400px;
} /*For the PNG image, define a class to it. Avoid inline CSS.*/
body {
    background: #fff;
    text-align: center;
}
#mainContainer{
    margin: 0 auto;
    max-width:400px;
    width: 100%;
    z-index:0;
    position:relative;
}

也可以使用 media queries :

@media only screen and (min-width: 400px) {
    .containerA, .pngIMG {
        max-width:100%;
        width: 100%;
    } /*For the PNG image, define a class to it. Avoid inline CSS.*/
}

关于html - 调整浏览器大小时重叠并保持流畅的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25025572/

相关文章:

javascript - jQuery 到 Wordpress - Uncaught Error 让我发疯

html - 使用 @keyframes-dash 的 SVG 动画线条绘图未在 Chrome 和 Safari 上显示

svg viewbox 分辨率限制

javascript - 使用特定比例和位置初始化后,SVG 返回其默认比例和位置

javascript - jQuery:计算有多少列表项将该值存储到变量中并将其作为文本传递到范围中

html - 显示选择选项的第二个值

javascript - 如何使用 jQuery 查找具有电子邮件地址作为类名的元素?

css - 如何将 URL 图像添加为 scss 变量

html - UL 类似乎在我的页脚上不起作用

python - Requests.content 与 Chrome 检查元素不匹配