使用Flex时内容和边界之间的差距
我在带有Flex显示屏的DIV中有一排图像。他们打算将毛绒躺在底部边界上,而是存在差距。
<!DOCTYPE html>
<html>
<head>
<style>
div {
height: 100px;
display: flex;
align-items: flex-end;
padding: 0;
background-color: aquamarine;
border-bottom: 2px solid hsl(0, 0%, 87%);
}
img {
width: 80px;
}
</style>
</head>
<body>
<div>
<img src="https://urnabios.com/wp-content/uploads/2015/04/angel_oak_tree.jpg">
<img src="https://cdn.thecoolist.com/wp-content/uploads/2016/05/Japanese-Cherry-beautiful-tree.jpg">
</div>
</body>
</html>
如您所见,DIV的填充是0,并且边框以绝对像素定义。那么,这是如何发生的,如何获得预期的布局?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将DIV的“盒装”设置为“边框框”将解决问题。
Setting the 'box-sizing' of the div to 'border-box' would solve the problem.
HTML元素在主体的情况下具有默认样式。
此处的更多信息
将保证金更改为0应该有效
The html elements have a default style in case of body its
More info here https://www.w3schools.com/cssref/css_default_values.asp
changing the margin to 0 should work