我只是练习HTML和CSS而且遇到了一个烦人的问题。我想知道那个横向差距是什么以及如何将其删除?
提前致谢
<!DOCTYPE html>
<html lang="en">
<head>
<title>Practice</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta content="utf-8" http-equiv="encoding" />
<style>
html,body
{
margin:0; padding:0; height:100%;
}
</style>
</head>
<body>
<script src="./js/jQuery.js"></script>
<img id="sample-img" src="Green-Nature-wallpaper.jpg" style="margin:0; padding:0;"></img>
<img id="sample-img2" src="Green-Nature-wallpaper.jpg" style="margin:0; padding:0;"></img>
<script>
$( document ).ready(function () {
$("#sample-img").width($(window).width());
$("#sample-img").height(0.6*$(window).height());
$("#sample-img2").width($(window).width());
$("#sample-img2").height(0.6*$(window).height());
});
$(window).resize(function() {
$("#sample-img").width($(window).width());
$("#sample-img").height(0.6*$(window).height());
$("#sample-img2").width($(window).width());
$("#sample-img2").height(0.6*$(window).height());
});
</script>
</body>
</html>
答案 0 :(得分:3)
您是否尝试将图像边距和填充设置为0?
<style>
img {
position:relative;
display:block;
margin:0;
padding:0;
}
</style>
答案 1 :(得分:0)
图像是内联内容,就像文字或单个字符一样。图像与放置字符的基线对齐。将vertical-align:bottom
添加到图片CSS。图像是内联元素,与文本类似,您看到的是为文本字体的下降保留的间隙,如字母的下卷曲&#39;。