Firefox 中的 img 旁边出现额外的空格
Extra whitespace appears next to img in Firefox
我正在使用最大宽度:100%;和最大高度:100%;对于我的 img 标签。 img 周围有一个容器,由于某种原因,图像旁边右侧会出现额外的空白。
容器的宽度不固定,所以应该是一样的,比如图片+每边15px padding。
CSS
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
ul {
list-style:none;
margin:0;
padding:0;
}
li {
height:100px;
display: inline-block;
background: lightblue;
padding: 15px;
}
img {
max-width:100%;
max-height:100%;
}
HTML
<ul>
<li><img src="http://lorempixel.com/1450/600/"></li>
</ul>
请尝试以下 css :
li {
background: lightblue none repeat scroll 0 0;
display: inline-block;
height: 100px;
padding: 15px;
width: 204px;
}
img {
height: auto;
width: 100%;
}
您想要相同的内边距而不改变宽度。在 CSS 之后发表评论:
/*-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;*/
See DEMO 在 FF 和 Chrome.
中显示相同的输出
给 li 添加宽度。
li{ width:200px; }
一个可能的解决方案是做这样的事情:
li {
padding: 0px;
}
img {
padding: 0px;
}
既然你说图像不需要修改大小,那么简单地删除填充可能是删除白色的一种方法 space。
使用 CSS 重置,它将修复您可能遇到的所有此类问题。我建议 Eric Meyer 的。
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
我正在使用最大宽度:100%;和最大高度:100%;对于我的 img 标签。 img 周围有一个容器,由于某种原因,图像旁边右侧会出现额外的空白。
容器的宽度不固定,所以应该是一样的,比如图片+每边15px padding。
CSS
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
ul {
list-style:none;
margin:0;
padding:0;
}
li {
height:100px;
display: inline-block;
background: lightblue;
padding: 15px;
}
img {
max-width:100%;
max-height:100%;
}
HTML
<ul>
<li><img src="http://lorempixel.com/1450/600/"></li>
</ul>
请尝试以下 css :
li {
background: lightblue none repeat scroll 0 0;
display: inline-block;
height: 100px;
padding: 15px;
width: 204px;
}
img {
height: auto;
width: 100%;
}
您想要相同的内边距而不改变宽度。在 CSS 之后发表评论:
/*-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;*/
See DEMO 在 FF 和 Chrome.
中显示相同的输出给 li 添加宽度。
li{ width:200px; }
一个可能的解决方案是做这样的事情:
li {
padding: 0px;
}
img {
padding: 0px;
}
既然你说图像不需要修改大小,那么简单地删除填充可能是删除白色的一种方法 space。
使用 CSS 重置,它将修复您可能遇到的所有此类问题。我建议 Eric Meyer 的。
/* http://meyerweb.com/eric/tools/css/reset/
v2.0 | 20110126
License: none (public domain)
*/
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}