earlier it was good but now when I put width and height 100% it doesn't really displays 100% instead a 10 px margin come on all four sides here's what I tried
早些时候这是好的,但是现在当我把宽度和高度100%放在100%而不是真正显示100%而不是所有四边都有10 px边距这里是我试过的
<html>
<head>
<style>
.cont img {
display: inline-block;
width :100%;
height : 100%;
margin:0;
padding:0;
}
</style>
</head>
<body>
<div class="cont">
<img src="IMG_5913-2.jpg" class="imgmy" name="imgmy">
</div>
</body>
</html>
what can I do to make it 100% with in any browser?
我该怎么做才能在任何浏览器中100%使用它?
4 个解决方案
#1
1
have a look at this code, set margin:0px
on body tag
看看这段代码,在body标签上设置margin:0px
<html>
<body style="margin:0px; ">
<div style="background-color:red; width:100%;">
hello
</div>
</body>
</html>
#2
0
Question is not 100% clear, but are you looking for a solution like this?
问题不是100%明确,但您是否正在寻找这样的解决方案?
.container {
height:100%;
width: 100%;
border: 1px red solid;
margin:0;
padding:0;
line-height: 0;
}
.container .imgmy{
height:100%;
width: 100%;
margin:0;
padding:0;
}
#3
0
Are you sure it was good earlier?
你确定早点好吗?
The margins around the image have nothing to do with the image itself.
图像周围的边距与图像本身无关。
Browsers define default styles in a so called User Agent Stylesheet. In this case, the white border is the 8px margin (that is in Chrome) on the body.
浏览器在所谓的用户代理样式表中定义默认样式。在这种情况下,白色边框是正文上的8px边距(即Chrome中)。
Luckily you can easily override these user agent stylesheets, and you should in this case.
幸运的是,您可以轻松覆盖这些用户代理样式表,在这种情况下您应该。
You can add margin:0 to the body, as mentioned above by Shreya. But to avoid similar 'errors' it is a good idea to include a reset.css or normalize.css. These files "make browsers render all elements consistently and in line with modern standards" (http://cdnjs.com/libraries/normalize). You don't have to write one yourself, others have done this for you, like Nicolas Gallagher: http://necolas.github.io/normalize.css/
你可以在身体上添加margin:0,如Shreya所述。但是为了避免类似的“错误”,最好包含reset.css或normalize.css。这些文件“使浏览器始终如一地呈现所有元素并符合现代标准”(http://cdnjs.com/libraries/normalize)。你不必自己写一个,其他人也为你做过这个,比如Nicolas Gallagher:http://necolas.github.io/normalize.css/
Read more about User Agent Stylesheets here: What is user agent stylesheet
在此处阅读有关用户代理样式表的更多信息:什么是用户代理样式表
#4
0
Assuming HTML
假设HTML
<body>
<div class="cont">
<img src="IMG_5913-2.jpg" class="imgmy" name="imgmy">
</div>
</body>
CSS
CSS
.cont img {
max-width: 100%;
max-height: 100%;
}
#1
1
have a look at this code, set margin:0px
on body tag
看看这段代码,在body标签上设置margin:0px
<html>
<body style="margin:0px; ">
<div style="background-color:red; width:100%;">
hello
</div>
</body>
</html>
#2
0
Question is not 100% clear, but are you looking for a solution like this?
问题不是100%明确,但您是否正在寻找这样的解决方案?
.container {
height:100%;
width: 100%;
border: 1px red solid;
margin:0;
padding:0;
line-height: 0;
}
.container .imgmy{
height:100%;
width: 100%;
margin:0;
padding:0;
}
#3
0
Are you sure it was good earlier?
你确定早点好吗?
The margins around the image have nothing to do with the image itself.
图像周围的边距与图像本身无关。
Browsers define default styles in a so called User Agent Stylesheet. In this case, the white border is the 8px margin (that is in Chrome) on the body.
浏览器在所谓的用户代理样式表中定义默认样式。在这种情况下,白色边框是正文上的8px边距(即Chrome中)。
Luckily you can easily override these user agent stylesheets, and you should in this case.
幸运的是,您可以轻松覆盖这些用户代理样式表,在这种情况下您应该。
You can add margin:0 to the body, as mentioned above by Shreya. But to avoid similar 'errors' it is a good idea to include a reset.css or normalize.css. These files "make browsers render all elements consistently and in line with modern standards" (http://cdnjs.com/libraries/normalize). You don't have to write one yourself, others have done this for you, like Nicolas Gallagher: http://necolas.github.io/normalize.css/
你可以在身体上添加margin:0,如Shreya所述。但是为了避免类似的“错误”,最好包含reset.css或normalize.css。这些文件“使浏览器始终如一地呈现所有元素并符合现代标准”(http://cdnjs.com/libraries/normalize)。你不必自己写一个,其他人也为你做过这个,比如Nicolas Gallagher:http://necolas.github.io/normalize.css/
Read more about User Agent Stylesheets here: What is user agent stylesheet
在此处阅读有关用户代理样式表的更多信息:什么是用户代理样式表
#4
0
Assuming HTML
假设HTML
<body>
<div class="cont">
<img src="IMG_5913-2.jpg" class="imgmy" name="imgmy">
</div>
</body>
CSS
CSS
.cont img {
max-width: 100%;
max-height: 100%;
}