如何制作带有标题覆盖的居中液体图像?
我尝试使用 CSS 显示以标题覆盖为中心的图像,并在浏览器窗口太小时(缩小以适应)时显示液体功能。
我当前的最佳尝试看起来像以下 HTML(使用 Google 的徽标作为示例图像)
<div align="center">
<div class="container">
<img src="http://www.google.fr/images/logos/ps_logo2.png" class="picture" />
<h3 class="caption">Image Caption</h3>
</div>
</div>
和以下 CSS
.container {
position : relative;
max-width : 364px;
}
.picture {
border-radius:0.5em;
box-shadow: 0px 0px 0.5em #000000;
max-width:364px;
}
.caption {
position:absolute;
padding:0.25em;
top:1em; left:0; right:0;
color:black;
background-color:rgba(0,0,0,0.2);
text-align:center;
}
但是,如果它的行为像我希望的那样针对大型浏览器窗口居中,那么对于小型浏览器窗口它不会缩小... 另外,我不需要 IE 支持,特定于 WebKit 的(iPhone/Android)就足够了,如果可能的话,我想避免使用 JavaScript。
JSFiddle 准备使用版本 http://jsfiddle.net/kWH3C/1/
I'm trying with CSS to display an image centered with a caption overlay, and a liquid capability when the browser window is too small (shrink to fit).
My current best attempt looks like the following HTML (using Google's logo as sample image)
<div align="center">
<div class="container">
<img src="http://www.google.fr/images/logos/ps_logo2.png" class="picture" />
<h3 class="caption">Image Caption</h3>
</div>
</div>
with the following CSS
.container {
position : relative;
max-width : 364px;
}
.picture {
border-radius:0.5em;
box-shadow: 0px 0px 0.5em #000000;
max-width:364px;
}
.caption {
position:absolute;
padding:0.25em;
top:1em; left:0; right:0;
color:black;
background-color:rgba(0,0,0,0.2);
text-align:center;
}
However, if it behaves centered as I want it to be for large browser windows, it doesn't shrink for small browser windows...
Also I don't need IE support, a WebKit-specific (iPhone/Android) would be enough, and I would like to avoid JavaScript if possible.
JSFiddle ready-to play with version http://jsfiddle.net/kWH3C/1/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需将最大宽度设置为容器而不是图像,并告诉图像为
width:100%
http://jsfiddle.net/Madmartigan/kWH3C/5/
您不需要外部 div,并且
align="center"
是HTML5 中已弃用,请使用 CSS 进行对齐和定位。Just set the max-width to the container instead of the image and tell the image to be
width:100%
http://jsfiddle.net/Madmartigan/kWH3C/5/
You don't need the outer div, and
align="center"
is deprecated in HTML5, use CSS for alignment and positioning.