简体   繁体   English

图像在缩放时与 div 不对齐

[英]Image not aligning with div in scaling

I am trying to attach the centered picture to the black div behind it, but if you make the window small (the windows width smaller), the black div will get small and will appear some space between the picture top left and right edges and the black div.我试图将居中的图片附加到它后面的黑色 div 上,但是如果你把窗口变小(窗口宽度变小),黑色 div 会变小,并且会在图片的左上角和右上角之间出现一些空间黑色分区It does not stay fixed right near the div.它不会固定在 div 附近。

How should I fix this?我应该如何解决这个问题? Thank you.谢谢你。 Please see it in full page and then in small page.请先在整页中查看,然后在小页中查看。 See example here:请参阅此处的示例:

 .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>

May I suggest something like this:我可以建议这样的事情:

 .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>

I would recommend setting a responsive width to the left and right divs.我建议为左右 div 设置响应宽度。 That way the black bar doesn't expand in height.这样黑条就不会在高度上扩大。 I added in 20% for each but you can change this if needed.我为每个添加了 20%,但如果需要,您可以更改它。

<div class="f-content">
<div style="float: left; color:white; width:20%;">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; width: 20%;">FOOTER RIGHT</div>
<div style="clear: right;"></div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM