我有两个flexbox列。左列包含文本;右栏包含图片。这两栏应分别占页面宽度的60%和40%。文字的尺子大于图片的高度。我希望图片上有半透明的覆盖层;当我悬停在覆盖层上时,我希望覆盖层消失。
但是,我无法显示覆盖,而且似乎无法将悬停区域限制为图片大小--右列中的任何地方,什至图片下方,都会触发悬停效果。
因为我希望页面能够响应,所以我不想手动设置图片大小(或aspect-ratio
):它应该填充右列的宽度,右列应该填充页面宽度的40%--这里不要用px
。
这里有一个我正在尝试做的事情的快速模型。在这个例子中,黄色的#img-container
在图像底部以下展开,绿色的.overlay
没有显示。两者都应该与图像的大小完全相同。
Fiddle here.
我的方法对吗?有没有什么明显的我遗漏了的东西?我对网页设计还是个新手...谢谢你的帮助!
1条答案
按热度按时间3qpi33ja1#
要能够在特定元素上放置“覆盖”:
#container-img
)是position: relative
。position: absolute
元素定位。top
、right
、bottom
和/或left
赋值,或者像我在代码片段中使用的那样,定义它们的简写inset
属性,将 overlay 定位在元素内部。当您想要 overlay 图像时,inset: 0
会将 overlay 拉伸到其父#container-img
的所有边。#container-img
时的CSS。我在代码片段中注解了我的更改和添加: