【发布时间】:2015-04-04 04:34:36
【问题描述】:
我已尽一切努力将图像在页面上居中,仅用于 @media 屏幕和 (max-width:480px),但是没有任何效果。
代码如下:
前端
<figure class="img1 embed">
<img src="Images/testimonial-2.jpg" alt=""/>
</figure>
CSS
/*** Base Caption Styles ***/
figure.embed,
figure.embed-top,
figure.overlay,
figure.embed-over {
display: inline-block;
vertical-align: top;
position: relative;
margin: 0.5em;
font-size: 0.8em;
background: white;
overflow: hidden;
float: right;
}
figure.embed img,
figure.embed-top img,
figure.overlay img,
figure.embed-over img {
width: 100%;
display: block;
}
figure.embed figcaption,
figure.embed-top figcaption,
figure.overlay figcaption,
figure.embed-over figcaption {
width: 100%;
padding: 0.5em;
/* neutral theme */
color: rgba(50,50,50,1.0);
background: rgba(200,200,200,0.825);
}
谁能告诉我需要对这个代码做什么才能使图像居中?我试过 display: block;边距:0 自动和边距左:自动; margin-right: auto,但无济于事。
任何帮助将不胜感激!
【问题讨论】:
-
你在第一组规则中得到了浮动 + 你的 img 是宽度为 100% 的显示块
-
我知道,但是,我的问题是如何编辑上面的代码以使用媒体查询 480px 居中图像?
-
您是否在媒体查询或图像居中遇到问题?关于居中图像有很多问题。 jsfiddle.net/64d71yjg
标签: css image center centering