在Plunker和JSFiddle中我都有相同的代码:
如您所见,在JSFiddle中,两种情况下图像周围的链接边界都是错误的,但在Plunker中是正确的。
这是JSFiddle的问题吗?如果是这样,我可以使用一些CSS来修复它,而不会在其他地方破坏它吗?
这是代码。 HTML:
.clearfix::after {
content: "";
clear: both;
display: table;
}
.one {
border: solid 2px gray;
width: 100px;
height: 100px;
padding: 3px;
margin: 2px;
float: left;
}
.one:hover {
border-color: #FF9900;
}
.two {
border: solid 2px gray;
width: 100px;
height: 100px;
padding: 3px;
margin: 2px;
display: inline-block;
}
.two:hover {
border-color: #FF9900;
}
<h3>Problem One - with float</h3>
<p>This is a problem in jsfiddle, but not plnkr</p>
<a href="#" class="one"><img src="https://en.js.cx/gallery/img6-thumb.jpg"></a>
<a href="#" class="one"><img src="https://en.js.cx/gallery/img5-thumb.jpg"></a>
<div class="clearfix"></div>
<h3>Problem Two - without float</h3>
<p>This is a problem in jsfiddle, but not plnkr</p>
<a href="#" class="two"><img src="https://en.js.cx/gallery/img6-thumb.jpg"></a>
<a href="#" class="two"><img src="https://en.js.cx/gallery/img5-thumb.jpg"></a>
答案 0 :(得分:0)
stender's的答案是最好的,请始终使用单位:
.one img, .two img {
max-width: 100%;
}
因为JSFiddle添加了边框。如果您检查代码,将会看到:
*, ::after, ::before {
box-sizing: border-box;
}