css - 图像在缩放时未与 div 对齐

标签 css html

我试图将居中的图片附加到它后面的黑色 div,但是如果你把窗口变小(窗口宽度变小),黑色的 div 会变小并且会在图片左上角和右上角之间出现一些空间边缘和黑色div。它不会固定在 div 附近。

我应该如何解决这个问题?谢谢。请先看全页,再看小页。 请参阅此处的示例:

.f-content {
    margin-top: 5%;
    text-align: center;
    display: inline-block;
    width: 100%;
    background-color: #1C2431;
}
<div class="f-content">
<div style="float: left; color:white;">FOOTER LEFT</div>
<img src="http://curier.cumparamlaptopuri.ro/1.png" alt="" width="40%" height="auto" style="margin-top: -26px; position: inherit;" />
<div style="float: right;color:white;">FOOTER RIGHT</div>
<div style="clear: right;"></div>
</div>

最佳答案

我可以这样建议吗:

.f-content {
    margin-top: 5%;
    text-align: center;
    display: inline-block;
    width: 100%;
    background-color: #1C2431;
    position: relative;
}

img {
  position: absolute;
  margin: 0 auto;
  left: 0;
  right: 0;
  margin-top: -1.9%;
}
<div class="f-content">
<div style="float: left; color:white;">FOOTER LEFT</div>
<img src="http://curier.cumparamlaptopuri.ro/1.png" alt="" width="40%" height="auto">
<div style="float: right;color:white;">FOOTER RIGHT</div>
<div style="clear: right;"></div>
</div>

关于css - 图像在缩放时未与 div 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42194198/

相关文章:

html - 多个部分设置为行内 block ,当其中一个部分的文本少行时,它会错位

javascript - 卸载前无法正常工作?

javascript - 如何使用angularjs从下拉列表中获取值

html - 如何根据父 div 是否显示 :none 创建 CSS 规则

javascript - 为什么这个文本输入在 iOS 上不起作用?

html - 如何让父元素隐藏但子元素可见

html - 如何在可穿戴网络 TIZEN 应用程序中启用页面指示器和更多选项?

css - 如何在不移动其中其他内容的情况下移动对象的背景图像?

javascript - HTML5 样板和关键呈现路径/延迟脚本和样式

html - 100% 高度 div 垂直中间的相对标志