我想阻止最右侧的图像泄漏到右侧填充之外。
这有意义吗?
<div style="margin: 0 15px;height: 40px; background-color: red">
</div>
<div style="padding: 0 15px;height: 400px;white-space: nowrap;overflow: hidden;">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
</div>
最佳答案
使用margin
而不是padding
。
<div style="margin: 0 15px;height: 40px; background-color: red">
</div>
<div style="margin: 0 15px;height: 400px;white-space: nowrap;overflow: hidden;">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
<img src="http://placekitten.com/g/200/200">
</div>
关于html - 阻止img元素html溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54695477/